How to do unit test for specific driver like sensor and i2c? #80856
Unanswered
freedom-168
asked this question in
Q&A
Replies: 1 comment 1 reply
-
Hi Gavin! Please take a look at the test folder for a different sensor, like BMI160, https://github.com/zephyrproject-rtos/zephyr/tree/8a824f307d0b69ccb3161eddc6be2a08ef60f112/tests/drivers/sensor/bmi160, especially the boards folder. My initial hunch is that the driver is not compiling because it's not in the DTS. JP |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
As we know, ZTest provides one simple testing framework for both generic test framework and unit testing. I want to do some unit test for some specific sensor driver with ZTest and some mocks. first I will create one folder in ${zephyrbase}/test/unit/bma422. add prj.conf and testcase.yaml to the folder like net_timeout example.
When I run following commands to start compile it, it reports some errors.
west build -p -b unit_testing . -T drivers.sensor.bosch.bma4xx
Here is the error report.
${zephyrbase}/include/zephyr/device.h:1204:10: fatal error: zephyr/syscalls/device.h: No such file or directory
1204 | #include <zephyr/syscalls/device.h>
but the zephyr/syscalls/device.h is auto generated during the compilation stage.
All examples in test/unit are not for drivers, I tried to build test/drivers/i2c/i2c_bme688 with following command
west build -p -b native_sim tests/drivers/i2c/i2c_bme688
it will reports following errors.
ephyr/include/zephyr/device.h:96:41: error: ‘__device_dts_ord___PARENT_ORD’ undeclared here (not in a function)
96 | #define DEVICE_NAME_GET(dev_id) _CONCAT(_device, dev_id)
Is there anyone who successfully did the driver unit test in Zephyr ?
I really appreciate your kindly help.
Thanks
Gavin
Beta Was this translation helpful? Give feedback.
All reactions