Skip to content

Commit 59fd5bb

Browse files
simensrostadjorgenmk
authored andcommitted
docs: patches: Include dummy shell in module patch
Include dummy shell in module patch to show users how a module can be updated to have a shell interface. This also improves testability. Signed-off-by: Simen S. Røstad <simen.rostad@nordicsemi.no>
1 parent c406a40 commit 59fd5bb

4 files changed

Lines changed: 118 additions & 23 deletions

File tree

.github/workflows/build.yml

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

160-
# Asset Tracker Template firmware build with patches for Thingy91x
160+
# Asset Tracker Template debug firmware build
161+
- name: Build thingy91x debug firmware
162+
if: ${{ github.event_name != 'pull_request' }}
163+
uses: ./asset-tracker-template/.github/actions/build-step
164+
with:
165+
memfault_project_key: ${{ secrets.MEMFAULT_PROJECT_KEY }}
166+
memfault_fw_type: ${{ env.MEMFAULT_FW_TYPE }}
167+
memfault_fw_version_prefix: ${{ env.MEMFAULT_FW_VERSION_PREFIX }}
168+
board: thingy91x/nrf9151/ns
169+
short_board: thingy91x
170+
version: ${{ env.VERSION }}-debug
171+
path: asset-tracker-template/app
172+
debug: true
173+
174+
# Asset Tracker Template firmware build with patches for Thingy91x
161175
- name: Apply patches for Thingy91x firmware
162176
if: ${{ github.event_name != 'pull_request' }}
163177
run: |
164178
git apply docs/patches/magnetometer.patch
165179
git apply docs/patches/dummy-module.patch
166-
working-directory: asset-tracker-template/app
180+
working-directory: asset-tracker-template
167181

168182
- name: Build patched thingy91x firmware
169183
if: ${{ github.event_name != 'pull_request' }}
@@ -174,20 +188,6 @@ jobs:
174188
version: ${{ env.VERSION }}-patched
175189
path: asset-tracker-template/app
176190

177-
# Asset Tracker Template debug firmware build
178-
- name: Build thingy91x debug firmware
179-
if: ${{ github.event_name != 'pull_request' }}
180-
uses: ./asset-tracker-template/.github/actions/build-step
181-
with:
182-
memfault_project_key: ${{ secrets.MEMFAULT_PROJECT_KEY }}
183-
memfault_fw_type: ${{ env.MEMFAULT_FW_TYPE }}
184-
memfault_fw_version_prefix: ${{ env.MEMFAULT_FW_VERSION_PREFIX }}
185-
board: thingy91x/nrf9151/ns
186-
short_board: thingy91x
187-
version: ${{ env.VERSION }}-debug
188-
path: asset-tracker-template/app
189-
debug: true
190-
191191
- name: Upload artifacts
192192
uses: actions/upload-artifact@v4
193193
with:

docs/patches/dummy-module.patch

Lines changed: 83 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,32 @@ index e1948cc..8d20bcd 100644
77
add_subdirectory_ifdef(CONFIG_APP_CLOUD src/modules/cloud)
88
add_subdirectory_ifdef(CONFIG_APP_FOTA src/modules/fota)
99
+add_subdirectory_ifdef(CONFIG_APP_DUMMY src/modules/dummy)
10+
diff --git a/app/Kconfig b/app/Kconfig
11+
index dad4070..684fe73 100644
12+
--- a/app/Kconfig
13+
+++ b/app/Kconfig
14+
@@ -15,6 +15,7 @@ rsource "src/modules/led/Kconfig.led"
15+
rsource "src/modules/fota/Kconfig.fota"
16+
rsource "src/modules/environmental/Kconfig.environmental"
17+
rsource "src/modules/button/Kconfig.button"
18+
+rsource "src/modules/dummy/Kconfig.dummy"
19+
20+
endmenu
21+
1022
diff --git a/app/src/modules/dummy/CMakeLists.txt b/app/src/modules/dummy/CMakeLists.txt
1123
new file mode 100644
12-
index 0000000..a299b3b
24+
index 0000000..8b69448
1325
--- /dev/null
1426
+++ b/app/src/modules/dummy/CMakeLists.txt
15-
@@ -0,0 +1,8 @@
27+
@@ -0,0 +1,9 @@
1628
+#
1729
+# Copyright (c) 2025 Nordic Semiconductor ASA
1830
+#
1931
+# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
2032
+#
2133
+
2234
+target_sources_ifdef(CONFIG_APP_DUMMY app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/dummy.c)
35+
+target_sources_ifdef(CONFIG_APP_DUMMY app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/dummy_shell.c)
2336
+target_include_directories(app PRIVATE .)
2437
diff --git a/app/src/modules/dummy/Kconfig.dummy b/app/src/modules/dummy/Kconfig.dummy
2538
new file mode 100644
@@ -66,7 +79,7 @@ index 0000000..2319814
6679
+endif # APP_DUMMY
6780
diff --git a/app/src/modules/dummy/dummy.c b/app/src/modules/dummy/dummy.c
6881
new file mode 100644
69-
index 0000000..8c2450a
82+
index 0000000..c2733b5
7083
--- /dev/null
7184
+++ b/app/src/modules/dummy/dummy.c
7285
@@ -0,0 +1,162 @@
@@ -149,7 +162,7 @@ index 0000000..8c2450a
149162
+/* State machine handlers */
150163
+static void state_running_run(void *o)
151164
+{
152-
+ const struct dummy_state *state_object = (const struct dummy_state *)o;
165+
+ struct dummy_state *state_object = (struct dummy_state *)o;
153166
+
154167
+ if (&DUMMY_CHAN == state_object->chan) {
155168
+ struct dummy_msg msg = MSG_TO_DUMMY_MSG(state_object->msg_buf);
@@ -279,3 +292,69 @@ index 0000000..4d3816e
279292
+#endif
280293
+
281294
+#endif /* _DUMMY_H_ */
295+
diff --git a/app/src/modules/dummy/dummy_shell.c b/app/src/modules/dummy/dummy_shell.c
296+
new file mode 100644
297+
index 0000000..9a82441
298+
--- /dev/null
299+
+++ b/app/src/modules/dummy/dummy_shell.c
300+
@@ -0,0 +1,60 @@
301+
+/*
302+
+ * Copyright (c) 2025 Nordic Semiconductor ASA
303+
+ *
304+
+ * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
305+
+ */
306+
+
307+
+#include <zephyr/kernel.h>
308+
+#include <zephyr/shell/shell.h>
309+
+#include <zephyr/zbus/zbus.h>
310+
+#include <zephyr/logging/log.h>
311+
+
312+
+#include "dummy.h"
313+
+
314+
+/* Register log module */
315+
+LOG_MODULE_REGISTER(dummy_shell_module, CONFIG_APP_DUMMY_LOG_LEVEL);
316+
+
317+
+/* Forward declarations */
318+
+static void dummy_shell_callback(const struct zbus_channel *chan);
319+
+
320+
+/* Register zbus callback */
321+
+ZBUS_LISTENER_DEFINE(dummy_shell, dummy_shell_callback);
322+
+
323+
+/* Add subscriber to channel */
324+
+ZBUS_CHAN_ADD_OBS(DUMMY_CHAN, dummy_shell, 0);
325+
+
326+
+/* Static variable to store shell reference */
327+
+static const struct shell *dummy_shell_ref;
328+
+
329+
+/* Shell command handler for sending dummy request */
330+
+static int cmd_dummy_request(const struct shell *shell, size_t argc, char **argv)
331+
+{
332+
+ struct dummy_msg request = {
333+
+ .type = DUMMY_SAMPLE_REQUEST,
334+
+ };
335+
+
336+
+ /* Store the shell reference */
337+
+ dummy_shell_ref = shell;
338+
+
339+
+ int err = zbus_chan_pub(&DUMMY_CHAN, &request, K_SECONDS(1));
340+
+ if (err) {
341+
+ shell_error(shell, "Failed to send request: %d", err);
342+
+ return err;
343+
+ }
344+
+
345+
+ shell_print(shell, "Dummy request sent");
346+
+ return 0;
347+
+}
348+
+
349+
+/* Shell command handler for receiving dummy response */
350+
+static void dummy_shell_callback(const struct zbus_channel *chan)
351+
+{
352+
+ const struct dummy_msg *response = zbus_chan_const_msg(chan);
353+
+
354+
+ if (response->type == DUMMY_SAMPLE_RESPONSE) {
355+
+ shell_print(dummy_shell_ref, "Response received: %d", response->value);
356+
+ }
357+
+}
358+
+
359+
+/* Register shell command */
360+
+SHELL_CMD_REGISTER(att_dummy_request, NULL, "Asset Tracker Template Dummy CMDs", cmd_dummy_request);

tests/on_target/tests/conftest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,15 @@ def bin_file():
167167
return os.path.join(artifacts_dir, file)
168168

169169
pytest.fail("No matching firmware .bin file found in the artifacts directory")
170+
171+
@pytest.fixture(scope="session")
172+
def hex_file_patched():
173+
# Search for the firmware hex file in the artifacts folder
174+
artifacts_dir = "artifacts/"
175+
hex_pattern = f"asset-tracker-template-{r"[0-9a-z\.]+"}-patched-{DUT_DEVICE_TYPE}-nrf91.hex"
176+
177+
for file in os.listdir(artifacts_dir):
178+
if re.match(hex_pattern, file):
179+
return os.path.join(artifacts_dir, file)
180+
181+
pytest.fail("No matching firmware .hex file found in the artifacts directory")

tests/on_target/tests/test_functional/test_patched.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414

1515
logger = get_logger()
1616

17-
def test_patched_firmware(dut_board, hex_file):
17+
def test_patched_firmware(dut_board, hex_file_patched):
1818
"""Test the patched firmware with magnetometer functionality."""
1919
# Only run this test for thingy91x devices
2020
devicetype = os.getenv("DUT_DEVICE_TYPE")
2121
if devicetype != "thingy91x":
2222
pytest.skip("This test is only for thingy91x devices")
2323

2424
# Flash the patched firmware
25-
flash_device(os.path.abspath(hex_file))
25+
flash_device(os.path.abspath(hex_file_patched))
2626
dut_board.uart.xfactoryreset()
2727

2828
# Log patterns to check
@@ -52,4 +52,8 @@ def test_patched_firmware(dut_board, hex_file):
5252
# These ranges are typical for magnetometer readings in microtesla
5353
assert -1000 <= x <= 1000, f"Magnetometer X value {x} out of expected range"
5454
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"
55+
assert -1000 <= z <= 1000, f"Magnetometer Z value {z} out of expected range"
56+
57+
dut_board.uart.write("att_dummy_request\r\n")
58+
dut_board.uart.wait_for_str("Dummy request sent", timeout=10)
59+
dut_board.uart.wait_for_str("Response received", timeout=10)

0 commit comments

Comments
 (0)