ccmock

Ceedling how to pass defines to CMock


I am somewhat new to TDD, although I have been using C for some time. As a result, I am using ceedling to test my embedded project.

I can rake test:all in gcc, but I am now trying to move that to an embedded target simulator. I am specifying my cross-compiler, linker, etc. through the 'project.yml' file.

When I rake test:all, I get an error when "compiling cmock.c" (several other files compile without problems):

< path_to_cmock >/cmock.c:17:31: error: size of array 'CMock_Guts_Buffer' is too large

There are other errors after this, but this is the one that kicks them off.

When I go to cmock.c, I see this at the top of the file:

#ifdef CMOCK_MEM_DYNAMIC
static unsigned char*         CMock_Guts_Buffer = NULL;
static CMOCK_MEM_INDEX_TYPE   CMock_Guts_BufferSize = CMOCK_MEM_ALIGN_SIZE;
static CMOCK_MEM_INDEX_TYPE   CMock_Guts_FreePtr;
#else
static unsigned char          CMock_Guts_Buffer[CMOCK_MEM_SIZE + CMOCK_MEM_ALIGN_SIZE];
static CMOCK_MEM_INDEX_TYPE   CMock_Guts_BufferSize = CMOCK_MEM_SIZE + CMOCK_MEM_ALIGN_SIZE;
static CMOCK_MEM_INDEX_TYPE   CMock_Guts_FreePtr;
#endif

Perfect, so I just need to find where these are declared. I do a text search only to find that they aren't declared anywhere... so I suspect that they are coming from the defaults within ceedling.

I found the documentation for CMOCK and, under "Compiled Options",

A number of #defines also exist for customizing the cmock experience...

It goes on to list the #defines that I have found in the source code, but it does not state where to find them. I have tried to make an include file with the appropriate defines and pass the include file through the 'project.yml' with no luck.

I suspect that the answer is unbelievably simple, it just isn't outlined anywhere that I have searched. Thank you for your time,


Solution

  • Of course, the answer was staring me in the face.

    In the 'project.yml' file, there is a section called 'defines'. The default defines are:

    :defines:
      # in order to add common defines:
      #  1) remove the trailing [] from the :common: section
      #  2) add entries to the :common: section (e.g. :test: has TEST defined)
      :commmon: &common_defines []
      :test:
        - *common_defines
        - TEST
      :test_preprocess:
        - *common_defines
        - TEST
    

    I simply added the defines for my target:

    :defines:
      # in order to add common defines:
      #  1) remove the trailing [] from the :common: section
      #  2) add entries to the :common: section (e.g. :test: has TEST defined)
      :commmon: &common_defines
        - __dsPIC33EP32MC204__
        - UNITY_INT_WIDTH=16
        - CMOCK_MEM_INDEX_TYPE=uint16_t
        - CMOCK_MEM_PTR_AS_INT=uint16_t
        - CMOCK_MEM_ALIGN=1
        - CMOCK_MEM_SIZE=1024
        - CMOCK_MEM_STATIC
      :test:
        - *common_defines
        - TEST
      :test_preprocess:
        - *common_defines
        - TEST