Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ceedling how to pass defines to CMock

Tags:

c

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,

like image 725
slightlynybbled Avatar asked May 06 '16 17:05

slightlynybbled


2 Answers

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
like image 60
slightlynybbled Avatar answered Oct 20 '22 22:10

slightlynybbled


The proper way to setup the cmock for your prohect is as slightlynybbled pointed in previous answer, bu you could also provide a hidden setup for your cmocks into your project.yml file as follow:

:cmock:
  :mock_prefix: mock_   
  :when_no_prototypes:
  :warn
  :enforce_strict_ordering: TRUE
  :includes_h_pre_orig_header:
    - ../<cmock_headers_includes>.h
  :plugins:
    - :ignore
    - :ignore_arg
    - :callback
    - :expect
    - :expect_any_args
  :treat_as:
    uint8:    HEX8
    uint16:   HEX16
    uint32:   UINT32
    int8:     INT8
    bool:     UINT8

This setup have been tested with Ceedling 0.27, 0.28 and 0.28.1

like image 2
Rafael Campos Las Heras Avatar answered Oct 20 '22 21:10

Rafael Campos Las Heras