[release/v4.1] Unit tests not being added to compilation

Xavi92
Posts: 45
Joined: Thu Mar 28, 2019 2:26 pm

[release/v4.1] Unit tests not being added to compilation

Postby Xavi92 » 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:

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
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():

Code: Select all

set(BUILD_TESTS 1) # <- Apparently required by project.cmake
project(my_project)
Now, test components (both the ones from esp-idf and ours) are added into the list. However, CMake returns the following error message:

Code: Select all

Failed to resolve component 'test_utils'.
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

Xavi92
Posts: 45
Joined: Thu Mar 28, 2019 2:26 pm

Re: [release/v4.1] Unit tests not being added to compilation

Postby Xavi92 » Mon Sep 14, 2020 9:05 am

I made some progress on this topic: the test_utils component can be found at $IDF_PATH/tools/unit-test-app/components and can be added to the build process by using:

Code: Select all

set(EXTRA_COMPONENT_DIRS ${EXTRA_COMPONENT_DIRS} $ENV{IDF_PATH}/tools/unit-test-app/components)
However, the following step fails, apparently because of the test application from unit-test-app being too large:

Code: Select all

FAILED: ulp_test_app
: && esp32ulp-elf-ld  -A elf32-esp32ulp -nostdlib CMakeFiles/ulp_test_app.dir/test_jumps_esp32.ulp.S.obj -o ulp_test_app  -T~/project/tests/build/esp-idf/ulp_test/ulp_test_app/esp32.ulp.ld  -Map=~/project/tests/build/esp-idf/ulp_test/ulp_test_app/ulp_test_app.map && :
esp32ulp-elf-ld: ulp_test_app section `.text' will not fit in region `ram'
esp32ulp-elf-ld: region `ram' overflowed by 268 bytes
ninja: build stopped: subcommand failed.
In any case, esp-idf is building all of its internal tests, but I am only interested in building mine. How can I discard esp-idf test from the build process?

Xavi92
Posts: 45
Joined: Thu Mar 28, 2019 2:26 pm

Re: [release/v4.1] Unit tests not being added to compilation

Postby Xavi92 » Tue Sep 15, 2020 5:31 am

I did not remember esp-idf expects test components to be listed manually into a CMake list called TEST_COMPONENTS. That solved the problem and made everything on my previous posts not needed. I hope this is useful to other users.

Who is online

Users browsing this forum: Baidu [Spider] and 468 guests