Open bigbrett opened 3 years ago
Seeing the error logs, looks like proto_flash.h
has been included twice. Can you share your source files, test_logic_flash_logging.c
, logic_flash_logging.h
and proto_flash.h
?
maybe putting #pragma once
at the top of your header file would work too.
@bigbrett did you solved it??, because I'm facing the same problem
I also have a feeling this is about missing include guards in one of the header files of proto_flash.h
Well, actually after some testing i was able to replicate the problem:
This happens only when you have inline functions and includes in the header files to mock, like this
$ tree -L 3
.
|-- app
| |-- drvs
| | |-- myadc.c --> #include "myadc.h"
| | |-- myadc.h --> #include "mypwm.h" here is where the inline functions are declared
| | |-- mypwm.c
| | `-- mypwm.h --> #include "myadc.h"
| |-- dummy.c --> #include "myadc.h"
| |-- dummy.h
| `-- main.c
|-- makefile
|-- project.yml
`-- test
`-- test_dummy.c -- > #include "mock_myadc.h"
the problem relays on myadc.h includes mypwm.h and mypwm.h is also inluding for some reason myadc.h again (I'm just replicating the issue), if we do:
$ ceedling test:all
Test 'test_dummy.c'
-------------------
Generating include list for myadc.h...
Creating mock for myadc...
Generating runner for test_dummy.c...
Compiling test_dummy_runner.c...
Compiling test_dummy.c...
Compiling mock_myadc.c...
Build/ceedling/test/mocks/mock_myadc.c:120:9: error: redefinition of 'adc_c_to_f'
120 | uint8_t adc_c_to_f(uint8_t c)
| ^~~~~~~~~~
In file included from ./app/drvs/mypwm.h:4,
from Build/ceedling/test/mocks/myadc.h:1,
from Build/ceedling/test/mocks/mock_myadc.h:6,
from Build/ceedling/test/mocks/mock_myadc.c:6:
./app/drvs/myadc.h:9:55: note: previous definition of 'adc_c_to_f' with type 'uint8_t(uint8_t)' {aka 'unsigned char(unsigned char)'}
9 | static inline __attribute__ ((always_inline)) uint8_t adc_c_to_f( uint8_t c )
|
ceedling build too complains about a redefinition, The ceedling/test/mocks folder contains the proper files as expected
myadc.h
if we add the same include guards to myadc.h generate by ceedling and the type
$ ceedling test:dummy
Test 'test_dummy.c'
-------------------
Compiling mock_myadc.c...
Compiling unity.c...
Compiling dummy.c...
Compiling CException.c...
Compiling cmock.c...
Linking test_dummy.exe...
Running test_dummy.exe...
--------------------
OVERALL TEST SUMMARY
--------------------
TESTED: 2
PASSED: 2
FAILED: 0
IGNORED: 0
problem is solved
You can check a static inline module in CMock which you can use to mock also static inline
functions. I spinout the implementation of static inline functions in separate header (lets say postfix with _inline_impl.h) which I only include when ifndef TEST
. It helps in such cases - but I do not use Ceedling to build in those projects, so I can't give you example configuration.
Since you found a solution we can probably close this ticket?
Is not a solution because you have to manually modify what ceedling is generating, @mvandervoord nad i don't know if this break any other stuffs in ceedling
Was your solution to add protection to the generated header, like so:
// all other generated code
exactly. I can provide with the example in case some body else want to tested, make some suggestion about how to run some more exhaustive tests
Honestly, I thought we had this feature already... but it appears we do not. Perhaps this was because we were afraid of getting name conflicts... but that seems solveable... we could always generate the protection as something ridiculous like GUARD_HEADER_FOR_filename_H
As stated in the title. If I
rm -rf
the test build directory, the first time I runceedling test:all
, it sucessfully executes my tests, as expected.However when I run the same command again right after, some of my tests run to completion, but some fail with the compiler complaining about re-definitions:
and
Looks like a caching issue?
Additionally, when I
clobber
, the error persists. The only way to prevent the error from occurring again is torm -rf
the build directory.Project File
Ceedling Info:
Running on Ubuntu 20.04 LTS