Unit Testing includepath

Bushfries
Posts: 5
Joined: Wed Mar 06, 2019 8:46 pm

Unit Testing includepath

Postby Bushfries » Wed Mar 20, 2019 5:12 pm

If I have a project structure that looks like:

Code: Select all

-project
	+main
	-components
		-testable
			-test
				test.c
Where in this project would the unit test app look for header files for the project? Currently I have all .c and .h files in project/main and would like to avoid making duplicates, if possible.

From the documentation and things I've read it seems like you have to make duplicate files for unity to be able to access them. Is there any way to avoid this and just use the project files I already have in project/main/?

ESP_igrr
Posts: 2071
Joined: Tue Dec 01, 2015 8:37 am

Re: Unit Testing includepath

Postby ESP_igrr » Thu Mar 21, 2019 1:41 am

You can specify include directories exported by the main component by setting COMPONENT_ADD_INCLUDEDIRS variable to the list of directories to include. By default, COMPONENT_ADD_INCLUDEDIRS is set to "include", so if you put the header files into "include" subdirectory of the component, they will be visible to other components.
If you want to keep the header files in the root of the "main" component, you can set
COMPONENT_ADD_INCLUDEDIRS := .

(See https://docs.espressif.com/projects/esp ... -variables for more details)

Bushfries
Posts: 5
Joined: Wed Mar 06, 2019 8:46 pm

Re: Unit Testing includepath

Postby Bushfries » Fri Mar 22, 2019 5:36 pm

Using a modified version of the unit test example with the file structure looking like this:
Image

I get the following error:

Code: Select all

/Users/user/esp/esp-idf/tools/unit-test-app/build/hub_test/libhub_test.a(test_mean.o):(.literal.test_func_16+0x0): undefined reference to `testable_mean'
/Users/user/esp/esp-idf/tools/unit-test-app/build/hub_test/libhub_test.a(test_mean.o): In function `test_func_16':
/Users/user/projects/unit_test/components/hub/test/test_mean.c:19: undefined reference to `testable_mean'
/Users/user/esp/esp-idf/tools/unit-test-app/build/hub_test/libhub_test.a(test_mean.o): In function `test_func_22':
/Users/user/projects/unit_test/components/hub/test/test_mean.c:25: undefined reference to `testable_mean'
/Users/user/esp/esp-idf/tools/unit-test-app/build/hub_test/libhub_test.a(test_mean.o): In function `test_func_32':
/Users/user/projects/unit_test/components/hub/test/test_mean.c:35: undefined reference to `testable_mean'
collect2: error: ld returned 1 exit status
test_mean.c is including the file like this:

Code: Select all

#include "../../../main/testable.h"
and CMakeLists.txt has the following information:

Code: Select all

set(COMPONENT_SRCDIRS "../../main")
set(COMPONENT_ADD_INCLUDEDIRS "../../main")

register_component()
Is there anything else I should be doing differently?

ESP_igrr
Posts: 2071
Joined: Tue Dec 01, 2015 8:37 am

Re: Unit Testing includepath

Postby ESP_igrr » Sun Mar 24, 2019 4:35 am

Just a thought, have you added mean.c to the CMakeLists of main component? Do you see main.c being compiled?

Bushfries
Posts: 5
Joined: Wed Mar 06, 2019 8:46 pm

Re: Unit Testing includepath

Postby Bushfries » Mon Mar 25, 2019 5:05 pm

I've realized what the problem is. When I do

Code: Select all

EXTRA_COMPONENT_DIRS="component"
it overwrites the default IDF_PATH components directory.

How would I go about adding multiple components via EXTRA_COMPONENT_DIRS? would it just be by using += rather than =?

Who is online

Users browsing this forum: Google [Bot] and 66 guests