Running and creating unit test for nordic application

Hello. 

I am trying to learn how to implement unit tests for embedded c-application. I created simple example about my problem and I am having hard time actually running the tests using native sim or nrf9160dk as target. I am following these instructions from nordic: https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/test_and_optimize/testing_unity_cmock.html 

I have installed these tools: Cmock,Unity & Ruby.

Everytime I try to run this command 'west build -b native_posix -t run', I get this output: 

```

PS C:\Users\OMISTAJA\Projekt\Testeri\Unit\src\test> west build -b native_posix -t run
usage: west [-h] [-z ZEPHYR_BASE] [-v] [-V] <command> ...
west: error: argument <command>: invalid choice: 'build' (choose from 'init', 'update', 'list', 'manifest', 'diff', 'status', 'forall', 'help', 'config', 'topdir', 'selfupdate')

```

I am using nrf connect from vscode.

0160.Unit.zip

  • I think it should be as simple as:

    1. install wsl,

    2. install ubuntu, I recommend 22.04 LTS.

    3 open VScode and select remote windows 

    4. Install the NCS extensions (they need to be reinstalled for the remote window) 

    5. Start developing 

    Regards

    Runar

  • Thank you 
    for other beginners:
    I needed to install cmake and ruby in wsl also.
    aftter running  unity/example_test in wsl I encountered this build error:

    /home/anicare/ncs/v2.6.0/zephyr/arch/posix/core/offsets/offsets.c
    In file included from /usr/lib/gcc/x86_64-linux-gnu/11/include/stdint.h:9,
    from /home/anicare/ncs/v2.6.0/zephyr/include/zephyr/types.h:11,
    from /home/anicare/ncs/v2.6.0/zephyr/include/zephyr/kernel_includes.h:21,
    from /home/anicare/ncs/v2.6.0/zephyr/include/zephyr/kernel.h:17,
    from /home/anicare/ncs/v2.6.0/zephyr/arch/posix/core/offsets/offsets.c:26:
    /usr/include/stdint.h:26:10: fatal error: bits/libc-header-start.h: No such file or directory
    26 | #include <bits/libc-header-start.h>
    | ^~~~~~~~~~~~~~~~~~~~~~~~~~
    compilation terminated.
    [9/95] Generating include/generated/version.h
    -- Zephyr version: 3.5.99 (/home/anicare/ncs/v2.6.0/zephyr), build: d96769faceca
    ninja: build stopped: subcommand failed.
    FATAL ERROR: command exited with status 1: /home/anicare/ncs/toolchains/2be090971e/usr/local/bin/cmake --build /home/anicare/ncs/v2.6.0/nrf/tests/unity/example_test/build --target run

    I tried to add #include <bits/libc-header-start.h> in offsets.c file but that  didnt fix the issue.

    You already helped me alot and pointed me in right direction. I alrdy got answer to my original ticket and this thread is getting quite long. I can try to solve this on my own.


    Thank you  Runar.

  • Hi all,
    I posted a question earlier about this not being completed, then solved it myself, and deleted the question. I realize this may be frustrating to those who were in the same boat as me. I solved this by building for native_posix_64, rather than native_posix. 

    My next issue is just running the test which I cannot seem to figure out. Will keep this updated as I move along.

  • Alternatively if you run this command

    sudo apt-get install gcc-multilib

    you should be able to compile for a 32-bit system

  • Can you specify a bit whats the issue when you try to run tests? This command should build and run tests automatically:

     west build -b native_sim -t run

Related