Unable to Run ZTest Unit Tests on nRF Sample – native_sim Not Detected by Twister

Hello everyone,

I would like to learn how to create unit tests using the ZTest framework for a Nordic sample project, in order to better understand how it works.

I am currently working on a Linux (Ubuntu) machine, as I understand from the documentation that this is the recommended approach for running unit tests without hardware.

Since I couldn’t find any example that directly applies ZTest to a Nordic sample, I decided to try creating my own test setup.
Here's what I’ve done so far:

  1. I created a new workspace and added the nrf_cloud_multi_service sample.

  2. I then attempted to create a unit test, which you can find at tests/unit directory in the zip file:

     multi-main.zip

  3. To run the test, I used the following command: python3 /home/sirdarwin/ncs/v3.0.0/zephyr/scripts/twister -T /home/sirdarwin/nrf_multi/tests/unit -p native_sim -v

However, the test did not run as expected. I’m attaching the terminal output, along with the build.log and CMakeOutput.log files for your review.



INFO    - Using Ninja..
INFO    - Zephyr version: v4.0.99-ncs1
INFO    - Using 'zephyr' toolchain.
INFO    - Building initial testsuite list...
INFO    - Writing JSON report /home/sirdarwin/nrf_multi/tests/unit/twister-out/testplan.json
INFO    - JOBS: 8
INFO    - Adding tasks to the queue...
INFO    - Added initial list of jobs to queue
ERROR   - CMake build failure: /home/sirdarwin/nrf_multi/tests/unit for native_sim/native
INFO    - 1/1 native_sim/native         nrf.cloud.loc_test                                 ERROR CMake build failure (native <host>)
ERROR   - see: /home/sirdarwin/nrf_multi/tests/unit/twister-out/native_sim_native/host/nrf.cloud.loc_test/build.log

INFO    - 1 test scenarios (1 configurations) selected, 0 configurations filtered (0 by static filter, 0 at runtime).
INFO    - 0 of 1 executed test configurations passed (0.00%), 0 built (not run), 0 failed, 1 errored, with no warnings in 4.76 seconds.
INFO    - 0 of 3 executed test cases passed (0.00%), 3 errored on 1 out of total 929 platforms (0.11%).
INFO    - 0 test configurations executed on platforms, 1 test configurations were only built.
INFO    - Saving reports...
INFO    - Writing JSON report /home/sirdarwin/nrf_multi/tests/unit/twister-out/twister.json
INFO    - Writing xunit report /home/sirdarwin/nrf_multi/tests/unit/twister-out/twister.xml...
INFO    - Writing xunit report /home/sirdarwin/nrf_multi/tests/unit/twister-out/twister_report.xml...
INFO    - -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
INFO    - The following issues were found (showing the top 10 items):
INFO    - 1) nrf.cloud.loc_test on native_sim/native error (CMake build failure)
INFO    -
INFO    - To rerun the tests, call twister using the following commandline:
INFO    - west twister -p <PLATFORM> -s <TEST ID>, for example:
INFO    -
INFO    - west twister -p native_sim/native -s nrf.cloud.loc_test
INFO    - or with west:
INFO    - west build -p -b native_sim/native . -T nrf.cloud.loc_test
INFO    - -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
INFO    - Run completed

Please note that the repository I shared is identical to the nrf_multi project for which I attached the logs. Just in case the issue was related to using a cloned repository, I also created the same project (nrf_cloud_multi_service_sample) from the nRF Connect SDK using VS Code and named it nrf_multi. I then manually added the same unit test files to this local project as well.

I’ve verified that my ZEPHYR_BASE is correctly set by running: echo $ZEPHYR_BASE
which outputs: /home/sirdarwin/ncs/v3.0.0/zephyr

The main issue I’m facing is that Twister doesn’t seem to detect the native_sim or native_posix platform for executing the test. Error as follows:

No board named 'native_sim' found.

Please choose one of the following boards:

unit_testing
nrf54lv10apdk
nrf7120pdk
nrf52dmouse
nrf52kbd
thingy91x
nrf52840gmouse
nrf54lm20apdk
nrf52833dongle
nrf52820dongle
thingy91
CMake Error at /home/sirdarwin/ncs/v3.0.0/zephyr/cmake/modules/boards.cmake:228 (message):
  Invalid BOARD; see above.

Please note that I’m relatively new to both Linux and the Zephyr RTOS environment. I’m trying to learn by doing, and I believe that writing tests is a great way to deepen my understanding.

There’s a high chance I may have made some mistakes in the process, and I’d really appreciate it if someone could review my steps and guide me on the correct approach to set up and run unit tests using ZTest.

Thank you for your time and support!

Best regards,
Semih

Parents Reply Children
No Data
Related