Skip to content

Commit c406a40

Browse files
simensrostadjorgenmk
authored andcommitted
ci: Test git patches in CI
Build and test patches documentated in the customization guide in CI to verify that they always work. Signed-off-by: Simen S. Røstad <simen.rostad@nordicsemi.no>
1 parent 0b9ab69 commit c406a40

3 files changed

Lines changed: 93 additions & 0 deletions

File tree

.github/workflows/build.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,23 @@ jobs:
157157
version: ${{ env.VERSION }}
158158
path: asset-tracker-template/app
159159

160+
# Asset Tracker Template firmware build with patches for Thingy91x
161+
- name: Apply patches for Thingy91x firmware
162+
if: ${{ github.event_name != 'pull_request' }}
163+
run: |
164+
git apply docs/patches/magnetometer.patch
165+
git apply docs/patches/dummy-module.patch
166+
working-directory: asset-tracker-template/app
167+
168+
- name: Build patched thingy91x firmware
169+
if: ${{ github.event_name != 'pull_request' }}
170+
uses: ./asset-tracker-template/.github/actions/build-step
171+
with:
172+
board: thingy91x/nrf9151/ns
173+
short_board: thingy91x
174+
version: ${{ env.VERSION }}-patched
175+
path: asset-tracker-template/app
176+
160177
# Asset Tracker Template debug firmware build
161178
- name: Build thingy91x debug firmware
162179
if: ${{ github.event_name != 'pull_request' }}

.github/workflows/target-test.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,27 @@ jobs:
185185
MEMFAULT_PROJECT_SLUG: ${{ vars.MEMFAULT_PROJECT_SLUG }}
186186
APP_BUNDLEID: ${{ env.APP_BUNDLEID }}
187187

188+
- name: Test Patched Firmware
189+
if: ${{ matrix.device == 'thingy91x' && endsWith(inputs.artifact_fw_version, '-patched') }}
190+
working-directory: asset-tracker-template/tests/on_target
191+
run: |
192+
pytest -v \
193+
--junit-xml=results/test-results-patched.xml \
194+
--html=results/test-results-patched.html --self-contained-html \
195+
tests/test_functional/test_patched.py
196+
shell: bash
197+
env:
198+
SEGGER: ${{ env.RUNNER_SERIAL_NUMBER }}
199+
DUT_DEVICE_TYPE: ${{ vars.DUT_DEVICE_TYPE }}
200+
UUID: ${{ env.UUID }}
201+
NRFCLOUD_API_KEY: ${{ secrets.NRF_CLOUD_API_KEY }}
202+
LOG_FILENAME: att_test_log_patched
203+
TEST_REPORT_NAME: ATT Patched Firwmare Test Report
204+
MEMFAULT_ORGANIZATION_TOKEN: ${{ secrets.MEMFAULT_ORGANIZATION_TOKEN }}
205+
MEMFAULT_ORGANIZATION_SLUG: ${{ vars.MEMFAULT_ORGANIZATION_SLUG }}
206+
MEMFAULT_PROJECT_SLUG: ${{ vars.MEMFAULT_PROJECT_SLUG }}
207+
APP_BUNDLEID: ${{ env.APP_BUNDLEID }}
208+
188209
- name: Generate and Push Power Badge
189210
if: ${{ matrix.device }} == ppk_thingy91x
190211
continue-on-error: true
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
##########################################################################################
2+
# Copyright (c) 2024 Nordic Semiconductor
3+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
4+
##########################################################################################
5+
6+
import os
7+
from utils.flash_tools import flash_device, reset_device
8+
import sys
9+
import pytest
10+
from utils.flash_tools import flash_device, reset_device
11+
12+
sys.path.append(os.getcwd())
13+
from utils.logger import get_logger
14+
15+
logger = get_logger()
16+
17+
def test_patched_firmware(dut_board, hex_file):
18+
"""Test the patched firmware with magnetometer functionality."""
19+
# Only run this test for thingy91x devices
20+
devicetype = os.getenv("DUT_DEVICE_TYPE")
21+
if devicetype != "thingy91x":
22+
pytest.skip("This test is only for thingy91x devices")
23+
24+
# Flash the patched firmware
25+
flash_device(os.path.abspath(hex_file))
26+
dut_board.uart.xfactoryreset()
27+
28+
# Log patterns to check
29+
pattern_magnetometer = "Magnetic field data:"
30+
pattern_cloud = "Connected to Cloud"
31+
pattern_shadow = "Requesting device shadow from the device"
32+
33+
# Cloud connection
34+
dut_board.uart.flush()
35+
reset_device()
36+
dut_board.uart.wait_for_str(pattern_cloud, timeout=120)
37+
38+
# Wait for shadow request
39+
dut_board.uart.wait_for_str(pattern_shadow, timeout=30)
40+
41+
# Wait for magnetometer readings
42+
dut_board.uart.wait_for_str(pattern_magnetometer, timeout=30)
43+
44+
# Extract magnetometer values from UART output
45+
values = dut_board.uart.extract_value(
46+
r"Magnetic field data: X: ([\d.-]+) G, Y: ([\d.-]+) G, Z: ([\d.-]+) G"
47+
)
48+
assert values, "Failed to extract magnetometer values"
49+
50+
x, y, z = map(float, values)
51+
# Basic validation of magnetometer values
52+
# These ranges are typical for magnetometer readings in microtesla
53+
assert -1000 <= x <= 1000, f"Magnetometer X value {x} out of expected range"
54+
assert -1000 <= y <= 1000, f"Magnetometer Y value {y} out of expected range"
55+
assert -1000 <= z <= 1000, f"Magnetometer Z value {z} out of expected range"

0 commit comments

Comments
 (0)