Skip to content

Commit 1b9c83a

Browse files
workflows: re-add native sim twister tests
Add native sim tests. Signed-off-by: Giacomo Dematteis <giacomo.dematteis@nordicsemi.no>
1 parent 62c142a commit 1b9c83a

File tree

15 files changed

+129
-162
lines changed

15 files changed

+129
-162
lines changed

.github/workflows/sonarcloud.yml

+13-4
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,19 @@ jobs:
5454
# - name: Install sonar-scanner and build-wrapper
5555
# uses: SonarSource/sonarcloud-github-c-cpp@v3
5656

57-
# - name: Build and test native sim
58-
# working-directory: asset-tracker-template
59-
# run: |
60-
# west twister -T . -C --coverage-platform=native_sim -v --inline-logs --integration
57+
- name: Build and test native sim
58+
working-directory: asset-tracker-template
59+
run: |
60+
west twister -T . -C --coverage-platform=native_sim -v --inline-logs --integration
61+
62+
- name: Results
63+
if: always()
64+
uses: pmeier/pytest-results-action@v0.7.1
65+
with:
66+
path: asset-tracker-template//twister-out/*.xml
67+
summary: true
68+
fail-on-empty: true
69+
title: ATT FW Unittest natvie sim Results
6170

6271
# - name: Build and test
6372
# working-directory: asset-tracker-template

app/sample.yaml

+22-22
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,25 @@ tests:
1515
platform_allow:
1616
- thingy91x/nrf9151/ns
1717
tags: ci_build
18-
app.build.memfault:
19-
build_only: true
20-
sysbuild: true
21-
integration_platforms:
22-
- thingy91x/nrf9151/ns
23-
platform_allow:
24-
- thingy91x/nrf9151/ns
25-
extra_configs:
26-
- CONFIG_MEMFAULT_NCS_PROJECT_KEY="PROJECTKEY"
27-
extra_args: EXTRA_CONF_FILE="overlay-memfault.conf;overlay-modemtrace-to-memfault.conf;overlay-etb.conf"
28-
tags: ci_build
29-
app.build.bootloader_update:
30-
build_only: true
31-
sysbuild: true
32-
integration_platforms:
33-
- thingy91x/nrf9151/ns
34-
platform_allow:
35-
- thingy91x/nrf9151/ns
36-
tags: ci_build
37-
extra_args:
38-
- mcuboot_CONFIG_FW_INFO_FIRMWARE_VERSION=3
39-
- CONFIG_BUILD_S1_VARIANT=y
18+
# app.build.memfault:
19+
# build_only: true
20+
# sysbuild: true
21+
# integration_platforms:
22+
# - thingy91x/nrf9151/ns
23+
# platform_allow:
24+
# - thingy91x/nrf9151/ns
25+
# extra_configs:
26+
# - CONFIG_MEMFAULT_NCS_PROJECT_KEY="PROJECTKEY"
27+
# extra_args: EXTRA_CONF_FILE="overlay-memfault.conf;overlay-modemtrace-to-memfault.conf;overlay-etb.conf"
28+
# tags: ci_build
29+
# app.build.bootloader_update:
30+
# build_only: true
31+
# sysbuild: true
32+
# integration_platforms:
33+
# - thingy91x/nrf9151/ns
34+
# platform_allow:
35+
# - thingy91x/nrf9151/ns
36+
# tags: ci_build
37+
# extra_args:
38+
# - mcuboot_CONFIG_FW_INFO_FIRMWARE_VERSION=3
39+
# - CONFIG_BUILD_S1_VARIANT=y

tests/module/README.md

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Assert Tracker Template Unit Tests on native sim
2+
3+
## Run tests locally
4+
5+
### Setup docker
6+
```shell
7+
cd <path_to_att_dir>
8+
docker run --rm -it \
9+
--privileged \
10+
-e BUILD_WRAPPER_OUT_DIR=build_wrapper_output_directory \
11+
-e CMAKE_PREFIX_PATH=/opt/toolchains \
12+
-v .:/work/asset-tracker-template \
13+
ghcr.io/zephyrproject-rtos/ci:v0.27.4 \
14+
/bin/bash
15+
```
16+
17+
### Commmands
18+
```shell
19+
cd work/asset-tracker-template/
20+
west init -l .
21+
west config manifest.group-filter +bsec
22+
west config build.sysbuild True
23+
west update -o=--depth=1 -n
24+
west blobs fetch hal_nordic
25+
26+
cd ..
27+
pip install -r nrf/scripts/requirements-build.txt
28+
apt-get update
29+
apt install -y curl ruby-full
30+
31+
cd asset-tracker-template/
32+
west twister -T . -C --coverage-platform=native_sim -v --inline-logs --integration
33+
```

tests/module/app/CMakeLists.txt

+22
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,39 @@ target_sources(app
1717
src/checks.c
1818
../../../app/src/modules/app/app.c
1919
../../../app/src/common/message_channel.c
20+
../../../app/src/modules/cloud/cloud_module.c
2021
)
2122

2223
target_include_directories(app PRIVATE src)
2324

2425
zephyr_include_directories(${ZEPHYR_BASE}/include/zephyr/)
2526
zephyr_include_directories(${ZEPHYR_BASE}/subsys/testsuite/include)
2627
zephyr_include_directories(../../../app/src/common)
28+
zephyr_include_directories(../../../app/src/modules/cloud)
29+
zephyr_include_directories(${NRF_DIR}/subsys/net/lib/nrf_cloud/include)
30+
zephyr_include_directories(${NRF_DIR}/../modules/lib/cjson)
31+
32+
target_link_options(app PRIVATE --whole-archive)
33+
2734

2835
# Options that cannot be passed through Kconfig fragments
2936
target_compile_definitions(app PRIVATE
3037
-DCONFIG_APP_LOG_LEVEL=4
3138
-DCONFIG_APP_PAYLOAD_CHANNEL_BUFFER_MAX_SIZE=100
3239
-DCONFIG_APP_MODULE_TRIGGER_TIMEOUT_SECONDS=600
40+
-DCONFIG_APP_CLOUD_LOG_LEVEL=0
41+
-DCONFIG_APP_CLOUD_THREAD_STACK_SIZE=2048
42+
-DCONFIG_APP_CLOUD_MESSAGE_QUEUE_SIZE=5
43+
-DCONFIG_APP_CLOUD_EXEC_TIME_SECONDS_MAX=1
44+
-DCONFIG_APP_CLOUD_WATCHDOG_TIMEOUT_SECONDS=2
45+
-DCONFIG_APP_CLOUD_BACKOFF_TYPE_LINEAR=1
46+
-DCONFIG_APP_CLOUD_BACKOFF_INITIAL_SECONDS=6
47+
-DCONFIG_APP_CLOUD_BACKOFF_LINEAR_INCREMENT_SECONDS=6
48+
-DCONFIG_APP_CLOUD_BACKOFF_MAX_SECONDS=36
49+
-DCONFIG_APP_NETWORK_SAMPLE_NETWORK_QUALITY=1
50+
-DCONFIG_LTE_LC_CONN_EVAL_MODULE=1
51+
-DCONFIG_LTE_LC_EDRX_MODULE=1
52+
-DCONFIG_LTE_LC_PSM_MODULE=1
53+
-DCONFIG_APP_MODULE_RECV_BUFFER_SIZE=1024
54+
-DCOAP_CONTENT_FORMAT_APP_JSON=50
3355
)

tests/module/app/VERSION

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Do not modify, will be overwritten by release workflow.
2+
VERSION_MAJOR = 0
3+
VERSION_MINOR = 0
4+
PATCHLEVEL = 0
5+
VERSION_TWEAK = 0
6+
EXTRAVERSION = dev

tests/module/app/src/main.c

+9
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ FAKE_VALUE_FUNC(int, dk_buttons_init, button_handler_t);
2525
FAKE_VALUE_FUNC(int, task_wdt_feed, int);
2626
FAKE_VALUE_FUNC(int, task_wdt_add, uint32_t, task_wdt_callback_t, void *);
2727
FAKE_VOID_FUNC(date_time_register_handler, date_time_evt_handler_t);
28+
FAKE_VALUE_FUNC(int, nrf_cloud_client_id_get, char *, size_t);
29+
FAKE_VALUE_FUNC(int, nrf_cloud_coap_init);
30+
FAKE_VALUE_FUNC(int, nrf_cloud_coap_connect, const char * const);
31+
FAKE_VALUE_FUNC(int, nrf_cloud_coap_disconnect);
32+
FAKE_VALUE_FUNC(int, nrf_cloud_coap_shadow_device_status_update);
33+
FAKE_VALUE_FUNC(int, nrf_cloud_coap_bytes_send, uint8_t *, size_t, bool);
34+
FAKE_VALUE_FUNC(int, nrf_cloud_coap_sensor_send, const char *, double, int64_t, bool);
35+
FAKE_VALUE_FUNC(int, nrf_cloud_coap_json_message_send, const char *, bool, bool);
36+
FAKE_VALUE_FUNC(int, nrf_cloud_coap_shadow_get, char *, size_t *, bool, int);
2837

2938
LOG_MODULE_REGISTER(trigger_module_test, 4);
3039

tests/module/app/testcase.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ tests:
55
- native_sim/native/64
66
integration_platforms:
77
- native_sim
8+
timeout: 120

tests/module/battery/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ zephyr_include_directories(${ZEPHYR_BASE}/include/zephyr/)
2727
zephyr_include_directories(${ZEPHYR_NRFXLIB_MODULE_DIR}/nrf_fuel_gauge/include/)
2828
zephyr_include_directories(${ZEPHYR_BASE}/subsys/testsuite/include)
2929
zephyr_include_directories(${ASSET_TRACKER_TEMPLATE_DIR}/app/src/common)
30+
zephyr_include_directories(${ASSET_TRACKER_TEMPLATE_DIR}/app/src/modules/cloud)
3031

3132
# Options that cannot be passed through Kconfig fragments
3233
target_compile_definitions(app PRIVATE

tests/module/battery/src/redef.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ static int sample_fetch(const struct device *dev, enum sensor_channel chan)
1212
return 0;
1313
}
1414

15-
static int channel_get(const struct device *dev, enum sensor_channel chan)
15+
static int channel_get(const struct device *dev, enum sensor_channel chan,
16+
struct sensor_value *val)
1617
{
1718
return 0;
1819
}

tests/module/battery/testcase.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
tests:
2-
asset_tracker_template.fw.trigger:
2+
asset_tracker_template.fw.battery:
33
platform_allow:
44
- native_sim
55
- native_sim/native/64

tests/module/button/CMakeLists.txt

+1-23
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,11 @@ target_sources(app
2121
zephyr_include_directories(${ZEPHYR_BASE}/include/zephyr/)
2222
zephyr_include_directories(${ZEPHYR_BASE}/subsys/testsuite/include)
2323
zephyr_include_directories(../../../app/src/common)
24-
24+
zephyr_include_directories(../../../app/src/modules/cloud)
2525

2626
target_link_options(app PRIVATE --whole-archive)
2727
# Options that cannot be passed through Kconfig fragments
2828
target_compile_definitions(app PRIVATE
2929
-DCONFIG_APP_PAYLOAD_CHANNEL_BUFFER_MAX_SIZE=100
3030
-DCONFIG_APP_BUTTON_LOG_LEVEL=4
3131
)
32-
33-
# generate encoder code using zcbor
34-
set(zcbor_command
35-
zcbor code # Invoke code generation
36-
--cddl ${ZEPHYR_BASE}/subsys/net/lib/lwm2m/lwm2m_senml_cbor.cddl
37-
--cddl ${APPLICATION_SOURCE_DIR}/../../../app/src/modules/button/button_object.cddl
38-
--encode # Generate encoding functions
39-
--decode # Generate encoding functions
40-
--short-names # Attempt to make generated symbol names shorter (at the risk of collision)
41-
-t button-object # Create a public API for decoding/encoding the "button-object" type from the cddl file
42-
--output-cmake button_object.cmake # The generated cmake file will be placed here
43-
)
44-
execute_process(COMMAND ${zcbor_command}
45-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
46-
COMMAND_ERROR_IS_FATAL ANY)
47-
48-
# Include the cmake file generated by zcbor. It adds the
49-
# generated code and the necessary zcbor C code files.
50-
include(${CMAKE_CURRENT_BINARY_DIR}/button_object.cmake)
51-
52-
zephyr_link_libraries(button_object)
53-
target_link_libraries(button_object PRIVATE zephyr_interface)

tests/module/button/src/main.c

+9-22
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,15 @@
1111

1212
#include "message_channel.h"
1313

14-
#include "zcbor_decode.h"
15-
#include "button_object_decode.h"
1614
#include <dk_buttons_and_leds.h>
1715
#include <date_time.h>
1816

1917
DEFINE_FFF_GLOBALS;
2018

2119
LOG_MODULE_REGISTER(button_module_test, 4);
2220

23-
ZBUS_MSG_SUBSCRIBER_DEFINE(transport);
24-
ZBUS_CHAN_ADD_OBS(PAYLOAD_CHAN, transport, 0);
21+
ZBUS_MSG_SUBSCRIBER_DEFINE(button_subscriber);
22+
ZBUS_CHAN_ADD_OBS(BUTTON_CHAN, button_subscriber, 0);
2523

2624
#define FAKE_TIME_MS 1716552398505
2725

@@ -42,10 +40,10 @@ int dk_buttons_init(button_handler_t _button_handler)
4240
void tearDown(void)
4341
{
4442
const struct zbus_channel *chan;
45-
static struct payload received_payload;
43+
uint8_t button_number;
4644
int err;
4745

48-
err = zbus_sub_wait_msg(&transport, &chan, &received_payload, K_MSEC(1000));
46+
err = zbus_sub_wait_msg(&button_subscriber, &chan, &button_number, K_MSEC(1000));
4947
if (err == 0) {
5048
LOG_ERR("Unhandled message in payload channel");
5149
TEST_FAIL();
@@ -55,16 +53,15 @@ void tearDown(void)
5553
void test_button_trigger(void)
5654
{
5755
const struct zbus_channel *chan;
58-
static struct payload received_payload;
59-
struct button_object button_obj = { 0 };
56+
uint8_t button_number;
6057
int err;
6158

6259
TEST_ASSERT_NOT_NULL(button_handler);
6360
button_handler(DK_BTN1_MSK, DK_BTN1_MSK);
6461

65-
err = zbus_sub_wait_msg(&transport, &chan, &received_payload, K_MSEC(1000));
62+
err = zbus_sub_wait_msg(&button_subscriber, &chan, &button_number, K_MSEC(1000));
6663
if (err == -ENOMSG) {
67-
LOG_ERR("No payload message received");
64+
LOG_ERR("No BUTTON_CHAN message received");
6865
TEST_FAIL();
6966
} else if (err) {
7067
LOG_ERR("zbus_sub_wait, error: %d", err);
@@ -73,21 +70,11 @@ void test_button_trigger(void)
7370
return;
7471
}
7572

76-
/* check if chan is payload channel */
77-
if (chan != &PAYLOAD_CHAN) {
73+
/* check if chan is button channel */
74+
if (chan != &BUTTON_CHAN) {
7875
LOG_ERR("Received message from wrong channel");
7976
TEST_FAIL();
8077
}
81-
82-
/* decode payload */
83-
err = cbor_decode_button_object(received_payload.buffer,
84-
received_payload.buffer_len,
85-
&button_obj,
86-
NULL);
87-
if (err != ZCBOR_SUCCESS) {
88-
LOG_ERR("Failed to decode payload");
89-
TEST_FAIL();
90-
}
9178
}
9279

9380
/* This is required to be added to each test. That is because unity's

tests/module/environmental/CMakeLists.txt

+1-23
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ target_sources(app
2121
zephyr_include_directories(${ZEPHYR_BASE}/include/zephyr/)
2222
zephyr_include_directories(${ZEPHYR_BASE}/subsys/testsuite/include)
2323
zephyr_include_directories(../../../app/src/common)
24-
24+
zephyr_include_directories(../../../app/src/modules/cloud)
2525

2626
target_link_options(app PRIVATE --whole-archive)
2727
# Options that cannot be passed through Kconfig fragments
@@ -33,25 +33,3 @@ target_compile_definitions(app PRIVATE
3333
-DCONFIG_APP_ENVIRONMENTAL_EXEC_TIME_SECONDS_MAX=1
3434
-DCONFIG_APP_ENVIRONMENTAL_WATCHDOG_TIMEOUT_SECONDS=2
3535
)
36-
37-
# generate encoder code using zcbor
38-
set(zcbor_command
39-
zcbor code # Invoke code generation
40-
--cddl ${ZEPHYR_BASE}/subsys/net/lib/lwm2m/lwm2m_senml_cbor.cddl
41-
--cddl ${APPLICATION_SOURCE_DIR}/../../../app/src/modules/environmental/env_object.cddl
42-
--encode # Generate encoding functions
43-
--decode # Generate decoding functions
44-
--short-names # Attempt to make generated symbol names shorter (at the risk of collision)
45-
-t env-object # Create a public API for decoding/encoding the "env-object" type from the cddl file
46-
--output-cmake env_object.cmake # The generated cmake file will be placed here
47-
)
48-
execute_process(COMMAND ${zcbor_command}
49-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
50-
COMMAND_ERROR_IS_FATAL ANY)
51-
52-
# Include the cmake file generated by zcbor. It adds the
53-
# generated code and the necessary zcbor C code files.
54-
include(${CMAKE_CURRENT_BINARY_DIR}/env_object.cmake)
55-
56-
zephyr_link_libraries(env_object)
57-
target_link_libraries(env_object PRIVATE zephyr_interface)

0 commit comments

Comments
 (0)