Add unit test

nogema
Posts: 8
Joined: Tue Jun 27, 2023 2:57 pm

Add unit test

Postby nogema » Mon Oct 23, 2023 1:00 pm

Hello,

I am trying to add unit tests to my project. I followed the file tree of the unit test example (https://github.com/espressif/esp-idf/tr ... /unit_test) and change the CMakeLists.txt files as a result. However when I compile my code I get a fatal error about a file of the ESP-IDF framework :

Code: Select all

fatal error: driver/gpio.h: No such file or directory
   14 | #include "driver/gpio.h"
Here my file tree :

Code: Select all

+ components 
     + folder_1
        + include
           - file_1.h
           - file_2.h
           - file_3.h
        + test
           - CMakeLists.txt
           - test_file.c
        - file_1.c
        - file_2.c
        - file_3.c
        - CMakeLists.txt
     - folder_2
     - folder_3
+ main
     + include
        - main.h
     - CMakeLists.txt
     - main.c
Moreover, the ESP-IDF example only shows how to do unit test for user made functions and not user made functions + ESP-IDF items (like the gpio.h).

Does anyone have an idea what I did wrong or I missed ?

Thank you for your help

ESP_Sprite
Posts: 9716
Joined: Thu Nov 26, 2015 4:08 am

Re: Add unit test

Postby ESP_Sprite » Tue Oct 24, 2023 2:48 am

Probaby you need a REQUIRES drivers in the cmakelists.txt somewhere, to indicate the test component needs the driver component (which contains the GPIO driver)

nogema
Posts: 8
Joined: Tue Jun 27, 2023 2:57 pm

Re: Add unit test

Postby nogema » Mon Oct 30, 2023 11:24 am

Thank you for your tip. Now I can compile my project but I still get errors when I try to compile the test project such as :

Code: Select all

fatal error: esp_bt.h: No such file or directory
   25 | #include "esp_bt.h"
Here my CMakeList.txt file in the same folder as the file that triggers the above error :

Code: Select all

idf_component_register(SRCS "bluetooth_task.c" "gatts_table_creat_demo.c"
                    INCLUDE_DIRS "include"
                    REQUIRES "nvs_flash" "bt" "app_update" "log")

nogema
Posts: 8
Joined: Tue Jun 27, 2023 2:57 pm

Re: Add unit test

Postby nogema » Tue Oct 31, 2023 4:53 pm

I also tried to use the Eclipse IDE because until now I was using the VS Code IDE.
In Eclipse, I succeeded to compile the project but I cannot compile the test sub project. Eclipse only defines a "Local" target and even when I try to add a "New Launch Target...", it is not saved.

nogema
Posts: 8
Joined: Tue Jun 27, 2023 2:57 pm

Re: Add unit test

Postby nogema » Fri Nov 03, 2023 1:23 pm

I have finally solved my problem. The problem was the sdkconfig file of the sub folder test was different from the sdkconfig file of the project.

To summerise, explicitly declare the library components used in CMakelist.txt with the word REQUIRES and use the same sdkconfig file in the main project and the test project.

Who is online

Users browsing this forum: ESP_Sprite and 283 guests