ThrowTheSwitch / CMock

CMock - Mock/stub generator for C
http://throwtheswitch.org
MIT License
652 stars 269 forks source link

CMock not breaking include chain at mocked header #460

Closed abergerSRS closed 7 months ago

abergerSRS commented 9 months ago

It seems that I have a situation where CMock is following the #includes of a mocked header, and ends up with a compiler error.

I have a test file (test_ADC.c) that begins with:

#include "unity.h"
#include "ADC.h"

#include "mock_instrument_noinline.h"

My instrument_noinline.h begins

#ifndef _INSTRUMENT_H
#define _INSTRUMENT_H

#include "DDS.h"
#include "PLL.h"
#include "frontpanel.h"
#include "statistics.h"

And when I try to run ceedling test:ADC, I get the following error

Test 'test_ADC.c'
-----------------
Compiling test_ADC_runner.c...
build/test/runners/test_ADC_runner.c:30: warning: "UNITY_INCLUDE_DOUBLE" redefined
   30 | #define UNITY_INCLUDE_DOUBLE
      |
<command-line>: note: this is the location of the previous definition
In file included from test/noInline/instrument_noinline.h:4,
                 from build/test/mocks/mock_instrument_noinline.h:5,
                 from build/test/runners/test_ADC_runner.c:31:
utilities/DDS.h: In function 'ConvertDegreesToDDSphase':
utilities/DDS.h:84:1: internal compiler error: Segmentation fault
   84 | inline uint32_t ConvertDegreesToDDSphase(float angle_deg) {return (uint32_t)((angle_deg/360)*REVS_TO_PHASE32);}

My understanding is that by using #include "mock_instrument_noinline.h", CMock should break the dependency chain at instrument_noinline.h and ignore all of the #includes within that file. Why is it trying to #include "DDS.h"?

abergerSRS commented 9 months ago

It's possible that the above test and error message are a red-herring. If I instead try to run a test that doesn't include any mocks I still get the internal compiler error: Segmentation fault, but this when trying to build unity.c:

$ ceedling test:queues

Test 'test_queues.c'
--------------------
Compiling unity.c...
C:/Users/aberger/Documents/Projects/P123/P123-firmware/vendor/ceedling/vendor/unity/src/unity.c: In function 'UnityPrintFloat':
C:/Users/aberger/Documents/Projects/P123/P123-firmware/vendor/ceedling/vendor/unity/src/unity.c:250:5: internal compiler error: Segmentation fault
  250 |     if (number < 0.0f || (number == 0.0f && 1.0f / number < 0.0f))
      |     ^~
libbacktrace could not find executable to open
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://github.com/msys2/MINGW-packages/issues> for instructions.
ERROR: Shell command failed.
> Shell executed command:
'gcc.exe -I"test" -I"test/noInline" -I"test/support" -I"source" -I"utilities" -I"drivers" -I"board" -I"test/win32" -I"test/noInline" -I"CM4F_RTCESL_4.5_MCUX/GMCLIB/Include" -I"CM4F_RTCESL_4.5_MCUX/MLIB/Include" -I"C:/Users/aberger/Documents/Projects/P123/P123-firmware/vendor/ceedling/vendor/unity/src" -I"C:/Users/aberger/Documents/Projects/P123/P123-firmware/vendor/ceedling/vendor/cmock/src" -I"build/test/mocks" -DTEST -DCONFIGURATION=2 -DENABLE_SUMDIFF -DUNITY_INCLUDE_DOUBLE -DGNU_COMPILER -g -c "C:/Users/aberger/Documents/Projects/P123/P123-firmware/vendor/ceedling/vendor/unity/src/unity.c" -o "build/test/out/unity.o"'
> And exited with status: [1].
Letme commented 9 months ago

Is this your first test or project has testing already working? Also not sure about your above statement where cmock would break dependency chain, as it could usually be the missing include guard or something...

abergerSRS commented 9 months ago

This project was (and still is) working on a previous machine. I've copied the repo to a new machine, and can't get things working again.

Old machine: Windows 10 Ruby 2.7.2p137 GCC (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0

$ gem list ceedling
 ceedling (0.30.0) 

(in project directory):

$ ceedling version
Ceedling:: 0.28.2
CException:: 1.3.1.18
CMock:: 2.4.4.215
Unity:: 2.4.1.120

New machine: Windows 11 Ruby 2.7.2p137 GCC (Rev3, Built by MSYS2 project) 10.2.0

$ gem list ceedling
 ceedling (0.30.0) 

(in project directory):

$ ceedling version
Ceedling:: 0.28.2
CException:: 1.3.1.18
CMock:: 2.4.4.215
Unity:: 2.4.1.120
Letme commented 9 months ago

From your report the compiler version changed, so I would look into that, especially since : internal compiler error: Segmentation fault means that compiler crashed. And based on lines it is with floating points, so maybe you need to enable some flags to add that support?

abergerSRS commented 9 months ago

Yeah, you're right. If I install gcc.exe (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0 on the new machine everything works.

It's pretty painful to make sure the entire toolchain (ruby, ceedling, gcc) is identical to get things working on a separate development machine. Any suggestions?

Letme commented 9 months ago

Use Docker containers and you get Continues integration for free.