PlatformIO Community

Running gtest for application developed zephyr

Please find as in my build error logs below, I am writing test cases for an application which uses zephyr driver files, The build system is able to locate the zephyr driver file,
but unable to locate the zephyr.h file & other dependent files

.
Kindly someone suggest on how zephyr can be included on pio to run gtest.

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

PS D:\spi_test> platformio.exe test --environment native
Verbose mode can be enabled via `-v, --verbose` option
Collected 1 items

Processing native in native environment
---------------------------------------------------------------------------------------------------------------------Building...
In file included from lib\calculator\uC_SPI.h:17,
                 from lib\calculator\uC_SPI.cpp:15:
lib\calculator/uC_IO_Define.h:20:10: fatal error: zephyr.h: No such file or directory

****************************************************************
* Looking for zephyr.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:zephyr.h"
* Web  > https://platformio.org/lib/search?query=header:zephyr.h
*
****************************************************************

 #include "zephyr.h"
          ^~~~~~~~~~
compilation terminated.
*** [.pio\build\native\libfcb\calculator\uC_SPI.o] Error 1
In file included from lib\calculator/uC_SPI.h:17,
                 from test\native\test.cpp:3:
lib\calculator/uC_IO_Define.h:20:10: fatal error: zephyr.h: No such file or directory

****************************************************************
* Looking for zephyr.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:zephyr.h"
* Web  > https://platformio.org/lib/search?query=header:zephyr.h
*
****************************************************************

 #include "zephyr.h"
          ^~~~~~~~~~
compilation terminated.
*** [.pio\build\native\test\native\test.o] Error 1
============================================ [FAILED] Took 10.01 seconds ============================================
Test    Environment    Status    Duration
------  -------------  --------  ------------
native  native         FAILED    00:00:10.005
=====================

The native platform of PlatformIO does not have the capability to include Zephyr, even though there’s a native_posix feature for in Zephyr. This is an open issue (https://github.com/platformio/platform-native/issues/14).

The best one can do is either refactor your library to not use Zephyr when compilling for the native platform (you can e.g. check for #if defined(__x86_64__) etc), or let the unit tests run on the embedded device itself (see official examples and docs).