ThrowTheSwitch / Ceedling

Ruby-based unit testing and build system for C projects
http://throwtheswitch.org
Other
594 stars 247 forks source link

Ceedling cannot find header files #678

Open MichaelBMiner opened 2 years ago

MichaelBMiner commented 2 years ago

Related to my issue 676 my ceedling is having trouble finding some files. I am attaching a text file of my code tree.

Here is the command I am running and the response clear; ceedling clean; ceedling clobber; ceedling test:test_can.c

Cleaning build artifacts...
(For large projects, this task may take a long time to complete)

Clobbering all generated files...
(For large projects, this task may take a long time to complete)

Test 'test_can.c'
-----------------
Generating include list for socket.h...
Generating include list for libsocketcan.h...
/opt/fsl-imx-fb/5.10-hardknott/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi/usr/include/libsocketcan.h:29:10: fatal error: can_netlink.h: No such file or directory
   29 | #include <can_netlink.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.
ERROR: Shell command failed.
> Shell executed command:
'gcc -E -I"/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src" -I"/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/cmock/src" -I"build/test/mocks" -I"test" -I"test/comms" -I"test/test_utilities" -I"test/support" -I"src" -I"src/comms" -I"src/utilities" -I"include" -I"include/comms" -I"include/utilities" -DCEEDLING_TESTS -DCEEDLING_TESTS -DGNU_COMPILER "/opt/fsl-imx-fb/5.10-hardknott/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi/usr/include/libsocketcan.h" -o "build/test/preprocess/files/libsocketcan.h"'
> And exited with status: [1].

rake aborted!
ShellExecutionException: ShellExecutionException
/var/lib/gems/2.7.0/gems/ceedling-0.31.1/lib/ceedling/tool_executor.rb:88:in `exec'
/var/lib/gems/2.7.0/gems/ceedling-0.31.1/lib/ceedling/preprocessinator_file_handler.rb:12:in `preprocess_file'
/var/lib/gems/2.7.0/gems/ceedling-0.31.1/lib/ceedling/preprocessinator.rb:48:in `preprocess_file'
/var/lib/gems/2.7.0/gems/ceedling-0.31.1/lib/ceedling/preprocessinator.rb:10:in `block in setup'
/var/lib/gems/2.7.0/gems/ceedling-0.31.1/lib/ceedling/preprocessinator_helper.rb:46:in `block in preprocess_files_smartly'
/var/lib/gems/2.7.0/gems/ceedling-0.31.1/lib/ceedling/preprocessinator_helper.rb:46:in `preprocess_files_smartly'
/var/lib/gems/2.7.0/gems/ceedling-0.31.1/lib/ceedling/preprocessinator_helper.rb:28:in `preprocess_mockable_headers'
/var/lib/gems/2.7.0/gems/ceedling-0.31.1/lib/ceedling/preprocessinator.rb:26:in `preprocess_test_and_invoke_test_mocks'
/var/lib/gems/2.7.0/gems/ceedling-0.31.1/lib/ceedling/test_invoker.rb:84:in `block in setup_and_invoke'
/var/lib/gems/2.7.0/gems/ceedling-0.31.1/lib/ceedling/test_invoker.rb:51:in `each'
/var/lib/gems/2.7.0/gems/ceedling-0.31.1/lib/ceedling/test_invoker.rb:51:in `setup_and_invoke'
/var/lib/gems/2.7.0/gems/ceedling-0.31.1/lib/ceedling/rules_tests.rake:70:in `block (2 levels) in <top (required)>'
/var/lib/gems/2.7.0/gems/ceedling-0.31.1/bin/ceedling:345:in `block in <top (required)>'
/var/lib/gems/2.7.0/gems/ceedling-0.31.1/bin/ceedling:332:in `<top (required)>'
/usr/local/bin/ceedling:23:in `load'
/usr/local/bin/ceedling:23:in `<main>'
Tasks: TOP => test:test_can.c
(See full trace by running task with --trace)
ERROR: Ceedling Failed

What is odd is when I run ceedling files:include I get the output

include files:
 - /opt/fsl-imx-fb/5.10-hardknott/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi/usr/include/can_netlink.h
 - /opt/fsl-imx-fb/5.10-hardknott/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi/usr/include/libsocketcan.h
 - /opt/fsl-imx-fb/5.10-hardknott/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi/usr/include/sys/socket.h
 - /opt/fsl-imx-fb/5.10-hardknott/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi/usr/include/unistd.h
 - include/comms/evcc_can.h
 - include/main.h
 - include/scheduler.h
 - include/utilities/logger.h
 - include/utilities/ring_buffer.h
 - include/utilities/time_conversions.h

 - test/support/unity_helper.h
file count: 11

tree.txt

The code in the attached tree was generated by Yocto and I can share any of if needed. My code is very simple.

#ifdef CEEDLING_TESTS
#include "unity.h"
#include "evcc_can.h"

#include "logger.h"

#include <linux/can/raw.h>

#include "mock_socket.h"
#include "mock_libsocketcan.h"
//#include "mock_unistd.h"

#define CAN_DEVICE "can0"
#define BIT_RATE 250000

static int32_t test_can_rx_socket;
static struct can_filter test_can_filter_array[CAN_RAW_FILTER_MAX];

void setUp(void)
{
    setsockopt_ExpectAndReturn(test_can_rx_socket, SOL_CAN_RAW, CAN_RAW_FILTER,
            &test_can_filter_array, sizeof(struct can_filter) * CAN_RAW_FILTER_MAX, SUCCESS);
}

void tearDown(void)
{

}

#endif
mvandervoord commented 2 years ago

Are the missing file(s) added using the paths or files sections in the project.yml file?

I've been debating removing the includes sections option from files because it can't work quite like the others. When we're working with a source or test file, ceedling is in control and can choose to add it to the list of things that get compiled. When it's an include file, ceedling is no longer in control. Compilers don't accept a list of header files to use, they accept a list of paths only... so ceedling does well with paths:includes because it can just add it to the list, but less well when it's a random header file that we would just like the compiler to use... we have no way of informing the compiler about this desire.

If nothing else, we should add to the documentation on this.

If this isn't your situation, I apologize. I'm writing half of this just to remind myself that this is something we need to address. I'm also hoping it helps in your situation, of course. ;)