I have created the unit test using ZTest framework unable to run with zephyr/kernel.h file

i am unable to build the unit test code with kernel file  

FAILED: CMakeFiles/testbinary.dir/home/avinash/zephyrproject/unittesting/gce-source_code_latest/app/vipr/model/gas.c.o
/usr/bin/gcc -DUNIT_TEST -DZTEST_UNITTEST -I/home/avinash/zephyrproject/unittesting/gce-source_code_latest/tests/model_test -I/home/avinash/zephyrproject/unittesting/gce-source_code_latest/tests/model_test/../app/vipr/model -I/home/avinash/zephyrproject/zephyr/subsys/testsuite/ztest/include/zephyr -I/home/avinash/zephyrproject/zephyr/subsys/testsuite/ztest/unittest/include -I/home/avinash/zephyrproject/zephyr/subsys/testsuite/include/zephyr -I/home/avinash/zephyrproject/zephyr/subsys/testsuite/ztest/include -I/home/avinash/zephyrproject/zephyr/subsys/testsuite/include -I/home/avinash/zephyrproject/zephyr/include/zephyr -I/home/avinash/zephyrproject/zephyr/include -I/home/avinash/zephyrproject/zephyr/. -m32 -imacros /home/avinash/zephyrproject/unittesting/gce-source_code_latest/build/zephyr/include/generated/zephyr/autoconf.h -Wall -I /home/avinash/zephyrproject/unittesting/gce-source_code_latest/build/zephyr/include/generated -g -gdwarf-4 -MD -MT CMakeFiles/testbinary.dir/home/avinash/zephyrproject/unittesting/gce-source_code_latest/app/vipr/model/gas.c.o -MF CMakeFiles/testbinary.dir/home/avinash/zephyrproject/unittesting/gce-source_code_latest/app/vipr/model/gas.c.o.d -o CMakeFiles/testbinary.dir/home/avinash/zephyrproject/unittesting/gce-source_code_latest/app/vipr/model/gas.c.o -c /home/avinash/zephyrproject/unittesting/gce-source_code_latest/app/vipr/model/gas.c
In file included from /home/avinash/zephyrproject/zephyr/include/zephyr/sys/atomic.h:18,
from /home/avinash/zephyrproject/zephyr/include/zephyr/kernel_includes.h:25,
from /home/avinash/zephyrproject/zephyr/include/zephyr/kernel.h:17,
from /home/avinash/zephyrproject/unittesting/gce-source_code_latest/app/vipr/model/gas.c:15:
/home/avinash/zephyrproject/zephyr/include/zephyr/kernel/thread_stack.h: In function ‘z_stack_ptr_align’:
/home/avinash/zephyrproject/zephyr/include/zephyr/kernel/thread_stack.h:71:40: error: ‘ARCH_STACK_PTR_ALIGN’ undeclared (first use in this function)


71 | return (char *)ROUND_DOWN(ptr, ARCH_STACK_PTR_ALIGN);
| ^~~~~~~~~~~~~~~~~~~~
/home/avinash/zephyrproject/zephyr/include/zephyr/sys/util.h:330:48: note: in definition of macro ‘ROUND_DOWN’
330 | (((unsigned long)(x) / (unsigned long)(align)) * (unsigned long)(align))
| ^~~~~
/home/avinash/zephyrproject/zephyr/include/zephyr/kernel/thread_stack.h:71:40: note: each undeclared identifier is reported only once for each function it appears in
71 | return (char *)ROUND_DOWN(ptr, ARCH_STACK_PTR_ALIGN);
| ^~~~~~~~~~~~~~~~~~~~
/home/avinash/zephyrproject/zephyr/include/zephyr/sys/util.h:330:48: note: in definition of macro ‘ROUND_DOWN’
330 | (((unsigned long)(x) / (unsigned long)(align)) * (unsigned long)(align))
| ^~~~~
[7/8] Building C object CMakeFiles/testbinary.dir/test_model_gas.c.o

Can you please help me to resolve this issue

Parents Reply Children
  • int8_t writeToAppQ(AppMsg* msg)
    {
        return k_msgq_put(&app_msgq, msg, APPMSGQ_SEND_TIMEOUT);
    }
    This the unit test code:
    #include <zephyr/ztest.h>
    #include "../../app/vipr/msgQ/appMsgQ.h"

    //K_MSGQ_DEFINE(app_msgq, sizeof(AppMsg), MAX_APPMSGQ_MSGS, 1);

    ZTEST_SUITE(app_msgq_test, NULL, NULL, NULL, NULL, NULL);

    /** Test for writeToAppQ */
    ZTEST(app_msgq_test, test_writeToAppQ)
    {
        AppMsg msg = { .id = 1, .data = {0} };
        int8_t result;

        result = writeToAppQ(&msg);
        zassert_true(result == 0, "Failed to write to the message queue");

       /** Test error handling */
        result = writeToAppQ(NULL);
        zassert_equal(result, -EINVAL, "Failed to handle NULL argument in writeToAppQ");
    }
Related