Ceedling如何将定义传递给CMock

虽然我已经使用C一段时间了,但我对TDD有点新鲜。 结果,我正在使用ceedling来测试我的嵌入式项目。

我可以进行rake test:all使用gcc,但我现在正尝试将其移至嵌入式目标模拟器。 我通过’project.yml’文件指定我的交叉编译器,链接器等。

当我进行rake test:all ,我在“编译cmock.c”时遇到错误(其他几个文件编译没有问题):

/cmock.c:17:31:错误:数组’CMock_Guts_Buffer’的大小太大

在此之后还有其他错误,但这是将它们踢掉的错误。

当我去cmock.c ,我在文件的顶部看到了这个:

 #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 

完美,所以我只需要找到这些声明的地方。 我做文本搜索只发现它们没有在任何地方声明……所以我怀疑它们来自于ceedling中的默认值。

我找到了CMOCK的文档,在“编译选项”下,

还有许多#defines可用于自定义cmock体验…

它继续列出我在源代码中找到的#defines,但它没有说明在哪里找到它们。 我试图用适当的定义创建一个包含文件,并通过’project.yml’传递包含文件,但没有运气。

我怀疑答案简单得令人难以置信,只是在我搜索的任何地方都没有概述。 感谢您的时间,

当然,答案是盯着我的脸。

在’project.yml’文件中,有一个名为’definitions’的部分。 默认定义是:

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

我只是为我的目标添加了定义:

 :defines: # in order to add common defines: # 1) remove the trailing [] from the :common: section # 2) add entries to the :common: section (eg :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 

为您的prohect设置cmock的正确方法是在上一个答案中指出的略微错误 ,你也可以为你的cmocks提供一个隐藏的设置到你的project.yml文件中,如下所示:

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

该设置已经使用Ceedling 0.27,0.28和0.28.1进行了测试