ThrowTheSwitch / CMock

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

CMock Working in Ubuntu 18.04 but not 20.04 #390

Closed MichaelBMiner closed 2 years ago

MichaelBMiner commented 2 years ago

Hello,

This is related to my question in ceedling, but it appears the issue is in CMock and not ceedling.

My issue is that I can run ceedling clobber test:all in Ubuntu 18.04 and not in Ubuntu 20.04. I have confirmed this by doing the following.

  1. Download an ISO of Ubuntu 20.04 (ubuntu-20.04.3-desktop-amd64.iso)
  2. Create a VM and install the following packages
  1. Clone my repo
  2. Run ceedling clobber test:all
  3. See the error socketcanfails

I did the same steps above but with an ISO of Ubuntu 18.04 (ubuntu-18.04.6-desktop-amd64.iso) When I run ceedling clobber test:all I see that all my tests run and build.

I am attaching my project.yml and libsocketcan.h

project.txt libsocketcan.txt

Note that both VMs are running the same versions of ceedling, unity, cmock and cexception.

Ceedling:: 0.31.1
Unity:: 2.5.4
CMock:: 2.5.4
CException:: 1.3.3

Edit: For completeness I am adding a test file that displays the error as well as a part of the c file used. test_can.c.txt can.c.txt

mvandervoord commented 2 years ago

I think you've misdiagnosed the problem. I strongly suspect that it's a difference between versions of your standard linux header files on these platforms.

Your header suggests the struct in question is defined in linux/if_link.h, but that's not included in the path of the mock. You might be able to work around this with the following:

:cmock:
    :includes_h_pre_orig_header: 
        - linux/if_link.h

This will include the header file that contains the struct in each of your mocks. The problem, of course, is that if THAT has further dependencies, it may run into problems and you could get stuck including a bunch of stuff. In that case, it's usually best to define this struct yourself (either a real version of it, or a simplified test version of it if the contents aren't important). This can be done in a test_helper and then included.

MichaelBMiner commented 2 years ago

You are 100% correct, the implementation of libsocketcan.h is very slightly different between the versions of Ubuntu.

The :cmock: include you have suggested unfortunately does not fix my issue. Redefining the struct in unity_helper.h did however solve the issue.

Thank you for your patience. This was an odd one for me!