diff --git a/Rakefile b/Rakefile index 32498fa..34ffdb5 100644 --- a/Rakefile +++ b/Rakefile @@ -62,7 +62,9 @@ namespace :test do desc "Run C Unit Tests" task :c => [:prep_system_tests] do - build_and_test_c_files + unless ($cfg['unsupported'].include? "C") + build_and_test_c_files + end end desc "Run System Tests" diff --git a/lib/cmock_generator_utils.rb b/lib/cmock_generator_utils.rb index 0f4511c..d24a243 100644 --- a/lib/cmock_generator_utils.rb +++ b/lib/cmock_generator_utils.rb @@ -37,7 +37,7 @@ class CMockGeneratorUtils def code_add_base_expectation(func_name, global_ordering_supported=true) lines = " CMOCK_MEM_INDEX_TYPE cmock_guts_index = CMock_Guts_MemNew(sizeof(CMOCK_#{func_name}_CALL_INSTANCE));\n" lines << " CMOCK_#{func_name}_CALL_INSTANCE* cmock_call_instance = (CMOCK_#{func_name}_CALL_INSTANCE*)CMock_Guts_GetAddressFor(cmock_guts_index);\n" - lines << " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, \"CMock has run out of memory. Please allocate more.\");\n" + lines << " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringOutOfMemory);\n" lines << " memset(cmock_call_instance, 0, sizeof(*cmock_call_instance));\n" lines << " Mock.#{func_name}_CallInstance = CMock_Guts_MemChain(Mock.#{func_name}_CallInstance, cmock_guts_index);\n" lines << " Mock.#{func_name}_IgnoreBool = (int)0;\n" if (@ignore) diff --git a/src/cmock.c b/src/cmock.c index b2a0824..0aa720d 100644 --- a/src/cmock.c +++ b/src/cmock.c @@ -5,8 +5,10 @@ ========================================== */ #include "unity.h" +#include "cmock.h" -#include "cmock_internals.h" +//public constants to be used by mocks +const char* CMockStringOutOfMemory = "CMock has run out of memory. Please allocate more."; //private variables #ifdef CMOCK_MEM_DYNAMIC diff --git a/src/cmock.h b/src/cmock.h index 2a5310c..af960a3 100644 --- a/src/cmock.h +++ b/src/cmock.h @@ -7,6 +7,8 @@ #ifndef CMOCK_FRAMEWORK_H #define CMOCK_FRAMEWORK_H +#include "cmock_internals.h" + //should be big enough to index full range of CMOCK_MEM_MAX #ifndef CMOCK_MEM_INDEX_TYPE #define CMOCK_MEM_INDEX_TYPE unsigned int diff --git a/src/cmock_internals.h b/src/cmock_internals.h index 08fb15c..149e125 100644 --- a/src/cmock_internals.h +++ b/src/cmock_internals.h @@ -7,7 +7,8 @@ #ifndef CMOCK_FRAMEWORK_INTERNALS_H #define CMOCK_FRAMEWORK_INTERNALS_H -#include "cmock.h" +//These are constants that the generated mocks have access to +const char* CMockStringOutOfMemory; //define CMOCK_MEM_DYNAMIC to grab memory as needed with malloc //when you do that, CMOCK_MEM_SIZE is used for incremental size instead of total diff --git a/targets/clang_strict.yml b/targets/clang_strict.yml index 5286971..3380e74 100644 --- a/targets/clang_strict.yml +++ b/targets/clang_strict.yml @@ -83,6 +83,7 @@ linker: destination: *systest_build_path unsupported: + - out_of_memory - callingconv colour: true diff --git a/targets/gcc.yml b/targets/gcc.yml index 76c7551..2375a73 100644 --- a/targets/gcc.yml +++ b/targets/gcc.yml @@ -50,6 +50,7 @@ linker: destination: *systest_build_path unsupported: + - out_of_memory - unity_64bit_support - callingconv diff --git a/targets/gcc_64.yml b/targets/gcc_64.yml index d21686a..0ac60b2 100644 --- a/targets/gcc_64.yml +++ b/targets/gcc_64.yml @@ -51,6 +51,7 @@ linker: destination: *systest_build_path unsupported: + - out_of_memory - callingconv colour: true diff --git a/targets/gcc_tiny.yml b/targets/gcc_tiny.yml new file mode 100644 index 0000000..ccd492e --- /dev/null +++ b/targets/gcc_tiny.yml @@ -0,0 +1,79 @@ +--- +compiler: + path: gcc + source_path: &systest_generated_path 'test/system/generated/' + unit_tests_path: &unit_tests_path 'examples/test/' + mocks_path: &systest_mocks_path 'test/system/generated/' + build_path: &systest_build_path 'test/system/build/' + options: + - '-c' + - '-Wall' + - '-Wextra' + - '-Wunused-parameter' + - '-Wno-address' + - '-Wno-invalid-token-paste' + - '-std=c99' + - '-pedantic' + - '-O0' + includes: + prefix: '-I' + items: + - *systest_generated_path + - *unit_tests_path + - *systest_mocks_path + - 'src/' + - 'vendor/unity/src/' + - 'vendor/c_exception/lib/' + - 'test/system/test_compilation/' + - 'test/' + defines: + prefix: '-D' + items: + - 'CMOCK_MEM_STATIC' + - 'CMOCK_MEM_SIZE=1024' + object_files: + prefix: '-o' + extension: '.o' + destination: *systest_build_path + +linker: + path: gcc + options: + - -lm + includes: + prefix: '-I' + object_files: + path: *systest_build_path + extension: '.o' + bin_files: + prefix: '-o' + extension: '.exe' + destination: *systest_build_path + +unsupported: + - all_plugins_but_other_limits + - all_plugins_coexist + - array_and_pointer_handling + - const_primitives_handling + - enforce_strict_ordering + - expect_and_return_custom_types + - expect_and_return_treat_as + - expect_and_throw + - expect_any_args + - fancy_pointer_handling + - function_pointer_handling + - newer_standards_stuff1 + - nonstandard_pased_stuff_1 + - nonstandard_pased_stuff_2 + - parsing_challenges + - return_thru_ptr_and_expect_any_args + - return_thru_ptr_ignore_arg + - struct_union_enum_expect_and_return + - struct_union_enum_expect_and_return_with_plugins + - stubs_with_callbacks + - unity_64bit_support + - unity_ignores + - callingconv + - C + +colour: true diff --git a/targets/iar_arm_v4.yml b/targets/iar_arm_v4.yml index fdda582..6e88a74 100644 --- a/targets/iar_arm_v4.yml +++ b/targets/iar_arm_v4.yml @@ -15,7 +15,7 @@ compiler: - --no_code_motion - --no_tbaa - --no_clustering - - --no_scheduling + - --no_scheduling - --debug - --cpu_mode thumb - --endian little @@ -50,7 +50,7 @@ compiler: prefix: '-o' extension: '.r79' destination: *systest_build_path - + linker: path: [*tools_root, 'common\bin\xlink.exe'] options: @@ -80,7 +80,7 @@ linker: prefix: '-o' extension: '.d79' destination: *systest_build_path - + simulator: path: [*tools_root, 'common\bin\CSpyBat.exe'] pre_support: @@ -100,6 +100,7 @@ simulator: - sim unsupported: + - out_of_memory - nonstandard_parsed_stuff_1 - const - callingconv diff --git a/targets/iar_arm_v5.yml b/targets/iar_arm_v5.yml index e44f631..f5a8541 100644 --- a/targets/iar_arm_v5.yml +++ b/targets/iar_arm_v5.yml @@ -14,7 +14,7 @@ compiler: - --no_code_motion - --no_tbaa - --no_clustering - - --no_scheduling + - --no_scheduling - --debug - --cpu_mode thumb - --endian=little @@ -49,7 +49,7 @@ compiler: prefix: '-o' extension: '.r79' destination: *systest_build_path - + linker: path: [*tools_root, 'arm\bin\ilinkarm.exe'] options: @@ -65,7 +65,7 @@ linker: prefix: '-o' extension: '.out' destination: *systest_build_path - + simulator: path: [*tools_root, 'common\bin\CSpyBat.exe'] pre_support: @@ -85,6 +85,7 @@ simulator: - sim unsupported: + - out_of_memory - nonstandard_parsed_stuff_1 - const - callingconv diff --git a/test/c/TestCMockC.c b/test/c/TestCMockC.c index 5fb32b6..385c177 100644 --- a/test/c/TestCMockC.c +++ b/test/c/TestCMockC.c @@ -5,7 +5,7 @@ ========================================== */ #include "unity.h" -#include "cmock_internals.h" +#include "cmock.h" #define TEST_MEM_INDEX_SIZE (sizeof(CMOCK_MEM_INDEX_TYPE)) diff --git a/test/c/TestCMockC.yml b/test/c/TestCMockC.yml index cd76154..d1e61ba 100644 --- a/test/c/TestCMockC.yml +++ b/test/c/TestCMockC.yml @@ -6,6 +6,7 @@ - 'vendor/unity/src/unity.c' :options: - 'TEST' + - 'CMOCK_MEM_STATIC' - 'CMOCK_MEM_SIZE=128' - 'CMOCK_MEM_ALIGN=2' - 'CMOCK_MEM_INDEX_TYPE=int' diff --git a/test/system/test_interactions/out_of_memory.yml b/test/system/test_interactions/out_of_memory.yml new file mode 100644 index 0000000..ed7bed5 --- /dev/null +++ b/test/system/test_interactions/out_of_memory.yml @@ -0,0 +1,65 @@ +--- +:cmock: + :plugins: [] + :treat_as: + custom_type: INT + +:systest: + :types: | + typedef struct _BIG_FAT_STRUCT_T + { + char bytes[512]; + } BIG_FAT_STRUCT_T; + + :mockable: | + void foo(BIG_FAT_STRUCT_T a); + + :source: + :header: | + void function_a(void); + void function_b(void); + + :code: | + void function_a(void) + { + BIG_FAT_STRUCT_T stuff = { { 8, 0 } }; + foo(stuff); + } + + void function_b(void) + { + BIG_FAT_STRUCT_T stuff1 = { { 9, 1, 0 } }; + BIG_FAT_STRUCT_T stuff2 = { { 9, 2, 0 } }; + foo(stuff1); + foo(stuff2); + } + + :tests: + :common: | + void setUp(void) {} + void tearDown(void) {} + + :units: + - :pass: TRUE + :should: 'successfully should be able to run function a because it only takes half the memory' + :code: | + test() + { + BIG_FAT_STRUCT_T expected = { { 8, 0 } }; + foo_Expect(expected); + function_a(); + } + + - :pass: FALSE + :should: 'should error out because we do not have eough memory to handle two of these structures' + :code: | + test() + { + BIG_FAT_STRUCT_T expected1 = { { 9, 1, 0 } }; + BIG_FAT_STRUCT_T expected2 = { { 9, 2, 0 } }; + foo_Expect(expected1); + foo_Expect(expected2); + function_b(); + } + +... diff --git a/test/unit/cmock_generator_utils_test.rb b/test/unit/cmock_generator_utils_test.rb index 0e96ced..b832077 100644 --- a/test/unit/cmock_generator_utils_test.rb +++ b/test/unit/cmock_generator_utils_test.rb @@ -58,7 +58,7 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do expected = " CMOCK_MEM_INDEX_TYPE cmock_guts_index = CMock_Guts_MemNew(sizeof(CMOCK_Apple_CALL_INSTANCE));\n" + " CMOCK_Apple_CALL_INSTANCE* cmock_call_instance = (CMOCK_Apple_CALL_INSTANCE*)CMock_Guts_GetAddressFor(cmock_guts_index);\n" + - " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, \"CMock has run out of memory. Please allocate more.\");\n" + + " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringOutOfMemory);\n" + " memset(cmock_call_instance, 0, sizeof(*cmock_call_instance));\n" + " Mock.Apple_CallInstance = CMock_Guts_MemChain(Mock.Apple_CallInstance, cmock_guts_index);\n" + " cmock_call_instance->LineNumber = cmock_line;\n" @@ -70,7 +70,7 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do expected = " CMOCK_MEM_INDEX_TYPE cmock_guts_index = CMock_Guts_MemNew(sizeof(CMOCK_Apple_CALL_INSTANCE));\n" + " CMOCK_Apple_CALL_INSTANCE* cmock_call_instance = (CMOCK_Apple_CALL_INSTANCE*)CMock_Guts_GetAddressFor(cmock_guts_index);\n" + - " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, \"CMock has run out of memory. Please allocate more.\");\n" + + " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringOutOfMemory);\n" + " memset(cmock_call_instance, 0, sizeof(*cmock_call_instance));\n" + " Mock.Apple_CallInstance = CMock_Guts_MemChain(Mock.Apple_CallInstance, cmock_guts_index);\n" + " Mock.Apple_IgnoreBool = (int)0;\n" + @@ -85,7 +85,7 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do expected = " CMOCK_MEM_INDEX_TYPE cmock_guts_index = CMock_Guts_MemNew(sizeof(CMOCK_Apple_CALL_INSTANCE));\n" + " CMOCK_Apple_CALL_INSTANCE* cmock_call_instance = (CMOCK_Apple_CALL_INSTANCE*)CMock_Guts_GetAddressFor(cmock_guts_index);\n" + - " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, \"CMock has run out of memory. Please allocate more.\");\n" + + " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringOutOfMemory);\n" + " memset(cmock_call_instance, 0, sizeof(*cmock_call_instance));\n" + " Mock.Apple_CallInstance = CMock_Guts_MemChain(Mock.Apple_CallInstance, cmock_guts_index);\n" + " Mock.Apple_IgnoreBool = (int)0;\n" +