[release/v4.1] Unit tests not being added to compilation
Posted: Fri Aug 21, 2020 1:57 pm
We want to run some unit tests and we realized they are not being added into the ${test_components} CMake variable and thus not compiled. This is roughly the tree structure of our project:
We have already checked $PROJECT_PATH/components is being added to EXTRA_COMPONENT_DIRS.
Running idf.py build only shows the components that are compiled for the factory firmware, but none of the test components are being listed. By inspecting $IDF_PATH/tools/cmake/project.cmake, I see one of the following conditions must be met in order to add the test components into the list. So I have added the following line on the top-level CMakeLists.txt right before calling project():
Now, test components (both the ones from esp-idf and ours) are added into the list. However, CMake returns the following error message:
test_utils does not seem to be available on esp-idf yet its unit tests depend on it. How can we build our unit tests only and not those from esp-idf? Or is there anything we are doing wrong?
Thanks for reading,
Xavi
Code: Select all
- project (also $PROJECT_PATH)
- components
- a
- test
CMakeLists.txt
/* other source files */
CMakeLists.txt
/* other source files */
- b
- test
CMakeLists.txt
/* other source files */
CMakeLists.txt
/* other source files */
- c
- test
CMakeLists.txt
/* other source files */
CMakeLists.txt
/* other source files */
- tests
- main
main.c
CMakeLists.txt
CMakeLists.txt <- top-level CMakeLists.txt
Running idf.py build only shows the components that are compiled for the factory firmware, but none of the test components are being listed. By inspecting $IDF_PATH/tools/cmake/project.cmake, I see one of the following conditions must be met in order to add the test components into the list. So I have added the following line on the top-level CMakeLists.txt right before calling project():
Code: Select all
set(BUILD_TESTS 1) # <- Apparently required by project.cmake
project(my_project)
Code: Select all
Failed to resolve component 'test_utils'.
Thanks for reading,
Xavi