From e8c7ad9706841ce0af3adb685d60457459411677 Mon Sep 17 00:00:00 2001 From: Aurelien CHAPPUIS Date: Tue, 18 Sep 2018 12:06:40 +0200 Subject: [PATCH 01/12] Try to find 'array pair' in parameters following this pattern : * , <@array_size_type> <@array_size_name> When such a pattern is used, the second parameter is used as the array size in _Expect method. --- lib/cmock_config.rb | 2 ++ lib/cmock_generator_utils.rb | 8 +++++++- lib/cmock_header_parser.rb | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/cmock_config.rb b/lib/cmock_config.rb index 398c582..db62f44 100644 --- a/lib/cmock_config.rb +++ b/lib/cmock_config.rb @@ -36,6 +36,8 @@ class CMockConfig :includes_c_pre_header => nil, :includes_c_post_header => nil, :orig_header_include_fmt => "#include \"%s\"", + :array_size_type => [], + :array_size_name => 'size|len', } def initialize(options=nil) diff --git a/lib/cmock_generator_utils.rb b/lib/cmock_generator_utils.rb index eb12e23..1e20782 100644 --- a/lib/cmock_generator_utils.rb +++ b/lib/cmock_generator_utils.rb @@ -100,7 +100,13 @@ class CMockGeneratorUtils def code_call_argument_loader(function) if (function[:args_string] != "void") args = function[:args].map do |m| - (@arrays and m[:ptr?]) ? "#{m[:name]}, 1" : m[:name] + if (@arrays and m[:ptr?] and not m[:array_data?]) + "#{m[:name]}, 1" + elsif (@arrays and m[:array_size?]) + "#{m[:name]}, #{m[:name]}" + else + m[:name] + end end " CMockExpectParameters_#{function[:name]}(cmock_call_instance, #{args.join(', ')});\n" else diff --git a/lib/cmock_header_parser.rb b/lib/cmock_header_parser.rb index ee0fe6a..a2bf781 100644 --- a/lib/cmock_header_parser.rb +++ b/lib/cmock_header_parser.rb @@ -17,6 +17,8 @@ class CMockHeaderParser @treat_as_void = (['void'] + cfg.treat_as_void).uniq @declaration_parse_matcher = /([\d\w\s\*\(\),\[\]]+??)\(([\d\w\s\*\(\),\.\[\]+-]*)\)$/m @standards = (['int','short','char','long','unsigned','signed'] + cfg.treat_as.keys).uniq + @array_size_name = cfg.array_size_name + @array_size_type = (['int', 'size_t'] + cfg.array_size_type).uniq @when_no_prototypes = cfg.when_no_prototypes @local_as_void = @treat_as_void @verbosity = cfg.verbosity @@ -186,6 +188,18 @@ class CMockHeaderParser arg_info.delete(:c_calling_convention) # don't care about this args << arg_info end + + # Try to find array pair in parameters following this pattern : * , <@array_size_type> <@array_size_name> + args.each_with_index {|val, index| + next_index = index + 1 + if (args.length > next_index) + if (val[:ptr?] == true and args[next_index][:name].match(@array_size_name) and @array_size_type.include?(args[next_index][:type])) + val[:array_data?] = true + args[next_index][:array_size?] = true + end + end + } + return args end From 8d16dca722e3c2416a1c39103d5678cb18fce6e6 Mon Sep 17 00:00:00 2001 From: Aurelien CHAPPUIS Date: Tue, 18 Sep 2018 15:06:10 +0200 Subject: [PATCH 02/12] Update cmock_header_parser_test.rb tests to include new configuration items array_size_type and array_size_name --- test/unit/cmock_header_parser_test.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/unit/cmock_header_parser_test.rb b/test/unit/cmock_header_parser_test.rb index add920f..dda8da4 100644 --- a/test/unit/cmock_header_parser_test.rb +++ b/test/unit/cmock_header_parser_test.rb @@ -22,6 +22,8 @@ describe CMockHeaderParser, "Verify CMockHeaderParser Module" do @config.expect :when_no_prototypes, :error @config.expect :verbosity, 1 @config.expect :treat_externs, :exclude + @config.expect :array_size_type, ['int', 'size_t'] + @config.expect :array_size_name, 'size|len' @parser = CMockHeaderParser.new(@config) end From b2adf60b2fab4cd9b40a8038254b4533e1db8315 Mon Sep 17 00:00:00 2001 From: Xenoamor Date: Mon, 28 Jan 2019 15:53:33 +0000 Subject: [PATCH 03/12] Fix bug where if folder mocks doesn't exist it fails --- lib/cmock_generator.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/cmock_generator.rb b/lib/cmock_generator.rb index 8cfe07b..a3a1686 100644 --- a/lib/cmock_generator.rb +++ b/lib/cmock_generator.rb @@ -57,9 +57,7 @@ class CMockGenerator private if $ThisIsOnlyATest.nil? ############################## def create_mock_subdir() - if @subdir - @file_writer.create_subdir(@subdir) - end + @file_writer.create_subdir(@subdir) end def create_mock_header_file(parsed_stuff) From b409ba6a1dee4d825b0930d94c90aa72c486fd16 Mon Sep 17 00:00:00 2001 From: Brendan McDonnell <35789100+bmcdonnell@users.noreply.github.com> Date: Fri, 1 Mar 2019 21:52:12 -0500 Subject: [PATCH 04/12] Grammar fix--"fewer times", not "less times" --- docs/CMock_Summary.md | 4 ++-- src/cmock.c | 2 +- test/system/test_interactions/enforce_strict_ordering.yml | 2 +- test/system/test_interactions/expect_any_args.yml | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/CMock_Summary.md b/docs/CMock_Summary.md index 87f9c00..af7c76c 100644 --- a/docs/CMock_Summary.md +++ b/docs/CMock_Summary.md @@ -153,7 +153,7 @@ only needs to be called once per test. It will then ignore any further calls to particular mock. The IgnoreAndReturn works similarly, except that it has the added benefit of knowing what to return when that call happens. If the mock is called more times than IgnoreAndReturn was called, it will keep returning the last value without -complaint. If it's called less times, it will also ignore that. You SAID you didn't +complaint. If it's called fewer times, it will also ignore that. You SAID you didn't care how many times it was called, right? * `void func(void)` => `void func_Ignore(void)` @@ -574,7 +574,7 @@ based on other settings, particularly Unity's settings. * `CMOCK_MEM_SIZE` In static mode this is the total amount of memory you are allocating to Cmock. In Dynamic mode this is the size of each chunk allocated - at once (larger numbers grab more memory but require less mallocs). + at once (larger numbers grab more memory but require fewer mallocs). * `CMOCK_MEM_ALIGN` The way to align your data to. Not everything is as flexible as diff --git a/src/cmock.c b/src/cmock.c index 318f4c7..404fb82 100644 --- a/src/cmock.c +++ b/src/cmock.c @@ -10,7 +10,7 @@ //public constants to be used by mocks const char* CMockStringOutOfMemory = "CMock has run out of memory. Please allocate more."; const char* CMockStringCalledMore = "Called more times than expected."; -const char* CMockStringCalledLess = "Called less times than expected."; +const char* CMockStringCalledLess = "Called fewer times than expected."; const char* CMockStringCalledEarly = "Called earlier than expected."; const char* CMockStringCalledLate = "Called later than expected."; const char* CMockStringCallOrder = "Called out of order."; diff --git a/test/system/test_interactions/enforce_strict_ordering.yml b/test/system/test_interactions/enforce_strict_ordering.yml index 53d1a68..7d777a4 100644 --- a/test/system/test_interactions/enforce_strict_ordering.yml +++ b/test/system/test_interactions/enforce_strict_ordering.yml @@ -100,7 +100,7 @@ - :pass: FALSE :should: 'fail because bar() is called twice but is expected once' - :verify_error: 'Called less times than expected' + :verify_error: 'Called fewer times than expected' :code: | test() { diff --git a/test/system/test_interactions/expect_any_args.yml b/test/system/test_interactions/expect_any_args.yml index 452bfb0..06eb6bb 100644 --- a/test/system/test_interactions/expect_any_args.yml +++ b/test/system/test_interactions/expect_any_args.yml @@ -66,7 +66,7 @@ } - :pass: FALSE - :should: 'ignore foo() call details and notice if we called foo() less times than expected' + :should: 'ignore foo() call details and notice if we called foo() fewer times than expected' :code: | test() { From 727a5cc8a807faec915e8255b6a38f97b607feef Mon Sep 17 00:00:00 2001 From: Dom Postorivo Date: Wed, 20 Mar 2019 00:00:41 -0400 Subject: [PATCH 05/12] adjusted travis to use ruby 2.3 to make OSX build pass --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 88f52b0..ca02fea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,10 +5,9 @@ os: - linux rvm: - - "2.2.2" + - "2.3" before_install: - - if [ "$TRAVIS_OS_NAME" == "osx" ]; then rvm install 2.1 && rvm use 2.1 && ruby -v; fi - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install --assume-yes --quiet gcc-multilib; fi install: From 80454dc1f3472555d305714e22ebd3a4656a3f27 Mon Sep 17 00:00:00 2001 From: Xenoamor Date: Mon, 28 Jan 2019 15:53:33 +0000 Subject: [PATCH 06/12] Fix bug where if folder mocks doesn't exist it fails --- lib/cmock_generator.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/cmock_generator.rb b/lib/cmock_generator.rb index 8cfe07b..a3a1686 100644 --- a/lib/cmock_generator.rb +++ b/lib/cmock_generator.rb @@ -57,9 +57,7 @@ class CMockGenerator private if $ThisIsOnlyATest.nil? ############################## def create_mock_subdir() - if @subdir - @file_writer.create_subdir(@subdir) - end + @file_writer.create_subdir(@subdir) end def create_mock_header_file(parsed_stuff) From a5616dc2df8459a7c2f08a41e12653dacf9f2444 Mon Sep 17 00:00:00 2001 From: merazmus Date: Fri, 22 Mar 2019 09:10:16 +0100 Subject: [PATCH 07/12] Fix missing framework header in mock header files --- lib/cmock_generator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cmock_generator.rb b/lib/cmock_generator.rb index 8cfe07b..44e9740 100644 --- a/lib/cmock_generator.rb +++ b/lib/cmock_generator.rb @@ -95,6 +95,7 @@ class CMockGenerator file << "/* AUTOGENERATED FILE. DO NOT EDIT. */\n" file << "#ifndef _#{define_name}_H\n" file << "#define _#{define_name}_H\n\n" + file << "#include \"#{@framework}.h\"\n" @includes_h_pre_orig_header.each {|inc| file << "#include #{inc}\n"} file << @config.orig_header_include_fmt.gsub(/%s/, "#{orig_filename}") + "\n" @includes_h_post_orig_header.each {|inc| file << "#include #{inc}\n"} @@ -144,7 +145,6 @@ class CMockGenerator file << "#include \n" file << "#include \n" file << "#include \n" - file << "#include \"#{@framework}.h\"\n" file << "#include \"cmock.h\"\n" @includes_c_pre_header.each {|inc| file << "#include #{inc}\n"} file << "#include \"#{header_file}\"\n" From af59c531f7fc3c88e52b50a409d920e5f0e0bc48 Mon Sep 17 00:00:00 2001 From: merazmus Date: Fri, 22 Mar 2019 09:11:58 +0100 Subject: [PATCH 08/12] Update unit tests --- test/unit/cmock_generator_main_test.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/unit/cmock_generator_main_test.rb b/test/unit/cmock_generator_main_test.rb index fbfe41c..2993082 100644 --- a/test/unit/cmock_generator_main_test.rb +++ b/test/unit/cmock_generator_main_test.rb @@ -92,6 +92,7 @@ describe CMockGenerator, "Verify CMockGenerator Module" do "/* AUTOGENERATED FILE. DO NOT EDIT. */\n", "#ifndef _#{define_name}\n", "#define _#{define_name}\n\n", + "#include \"unity.h\"\n", "#include \"ConfigRequiredHeader1.h\"\n", "#include \"ConfigRequiredHeader2.h\"\n", "#include \"#{orig_filename}\"\n", @@ -147,6 +148,7 @@ describe CMockGenerator, "Verify CMockGenerator Module" do "/* AUTOGENERATED FILE. DO NOT EDIT. */\n", "#ifndef _#{define_name}\n", "#define _#{define_name}\n\n", + "#include \"unity.h\"\n", "#include \"ConfigRequiredHeader1.h\"\n", "#include \"ConfigRequiredHeader2.h\"\n", "#include \"#{orig_filename}\"\n", @@ -185,6 +187,7 @@ describe CMockGenerator, "Verify CMockGenerator Module" do "/* AUTOGENERATED FILE. DO NOT EDIT. */\n", "#ifndef _#{define_name}\n", "#define _#{define_name}\n\n", + "#include \"unity.h\"\n", "#include \"ConfigRequiredHeader1.h\"\n", "#include \"ConfigRequiredHeader2.h\"\n", "#include \"#{orig_filename}\"\n", @@ -222,6 +225,7 @@ describe CMockGenerator, "Verify CMockGenerator Module" do "/* AUTOGENERATED FILE. DO NOT EDIT. */\n", "#ifndef _#{define_name}\n", "#define _#{define_name}\n\n", + "#include \"unity.h\"\n", "#include \"ConfigRequiredHeader1.h\"\n", "#include \"ConfigRequiredHeader2.h\"\n", "#include \"#{orig_filename}\"\n", @@ -308,7 +312,6 @@ describe CMockGenerator, "Verify CMockGenerator Module" do "#include \n", "#include \n", "#include \n", - "#include \"unity.h\"\n", "#include \"cmock.h\"\n", "#include \"MockPoutPoutFish.h\"\n", "\n", From 99c2223a1daa3877d306e585c80f16f2ba0842b7 Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Wed, 3 Jul 2019 11:09:06 -0400 Subject: [PATCH 09/12] Back out broken changes. (See issue #210. Thanks @HamboLagos) --- src/cmock.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cmock.c b/src/cmock.c index 404fb82..be26fba 100644 --- a/src/cmock.c +++ b/src/cmock.c @@ -26,8 +26,7 @@ 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 CMOCK_MEM_INDEX_TYPE CMock_Guts_BufferArray[(CMOCK_MEM_SIZE + CMOCK_MEM_INDEX_SIZE - 1) / CMOCK_MEM_INDEX_SIZE]; -#define CMock_Guts_Buffer ((unsigned char*)CMock_Guts_BufferArray) +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 From 5eab75a078fe7e17ce355d8a34ca6d37ad4f47dc Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Sat, 6 Jul 2019 12:11:56 -0400 Subject: [PATCH 10/12] Reimplement PR 227 with fixed tests. --- examples/temp_sensor/rakefile_helper.rb | 2 +- lib/cmock_generator_utils.rb | 2 +- test/unit/cmock_generator_utils_test.rb | 8 ++++---- vendor/unity | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/temp_sensor/rakefile_helper.rb b/examples/temp_sensor/rakefile_helper.rb index a442622..61d2377 100644 --- a/examples/temp_sensor/rakefile_helper.rb +++ b/examples/temp_sensor/rakefile_helper.rb @@ -151,7 +151,7 @@ module RakefileHelpers report command_string output = `#{command_string}`.chomp report(output) if (verbose && !output.nil? && (output.length > 0)) - unless $?.exitstatus.zero? || ok_to_fail + unless (!$?.nil? && $?.exitstatus.zero?) || ok_to_fail raise "Command failed. (Returned #{$?.exitstatus})" end return output diff --git a/lib/cmock_generator_utils.rb b/lib/cmock_generator_utils.rb index eb12e23..66e7c1f 100644 --- a/lib/cmock_generator_utils.rb +++ b/lib/cmock_generator_utils.rb @@ -73,7 +73,7 @@ class CMockGeneratorUtils if (arg[:ptr?] or @treat_as.include?(arg[:type])) " #{dest} = #{arg[:name]};\n" else - " memcpy(&#{dest}, &#{arg[:name]}, sizeof(#{arg[:type]}));\n" + " memcpy((void*)(&#{dest}), (void*)(&#{arg[:name]}), sizeof(#{arg[:type]}));\n" end end diff --git a/test/unit/cmock_generator_utils_test.rb b/test/unit/cmock_generator_utils_test.rb index bd59749..fc3cacb 100644 --- a/test/unit/cmock_generator_utils_test.rb +++ b/test/unit/cmock_generator_utils_test.rb @@ -106,7 +106,7 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do expected3 = " cmock_call_instance->Expected_Kiwi = Kiwi;\n" arg4 = { :name => "Lime", :const? => false, :type => 'LIME_T', :ptr? => false } - expected4 = " memcpy(&cmock_call_instance->Expected_Lime, &Lime, sizeof(LIME_T));\n" + expected4 = " memcpy((void*)(&cmock_call_instance->Expected_Lime), (void*)(&Lime), sizeof(LIME_T));\n" assert_equal(expected1, @cmock_generator_utils_simple.code_add_an_arg_expectation(arg1)) assert_equal(expected2, @cmock_generator_utils_simple.code_add_an_arg_expectation(arg2)) @@ -131,7 +131,7 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do " cmock_call_instance->ReturnThruPtr_Kiwi_Used = 0;\n" arg4 = { :name => "Lime", :const? => false, :type => 'LIME_T', :ptr? => false } - expected4 = " memcpy(&cmock_call_instance->Expected_Lime, &Lime, sizeof(LIME_T));\n" + + expected4 = " memcpy((void*)(&cmock_call_instance->Expected_Lime), (void*)(&Lime), sizeof(LIME_T));\n" + " cmock_call_instance->IgnoreArg_Lime = 0;\n" assert_equal(expected1, @cmock_generator_utils_complex.code_add_an_arg_expectation(arg1)) @@ -153,7 +153,7 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do } expected = "void CMockExpectParameters_Melon(CMOCK_Melon_CALL_INSTANCE* cmock_call_instance, stuff)\n{\n" + " cmock_call_instance->Expected_MyIntPtr = MyIntPtr;\n" + - " memcpy(&cmock_call_instance->Expected_MyMyType, &MyMyType, sizeof(MY_TYPE));\n" + + " memcpy((void*)(&cmock_call_instance->Expected_MyMyType), (void*)(&MyMyType), sizeof(MY_TYPE));\n" + " cmock_call_instance->Expected_MyStr = MyStr;\n" + "}\n\n" assert_equal(expected, @cmock_generator_utils_simple.code_add_argument_loader(function)) @@ -169,7 +169,7 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do " cmock_call_instance->Expected_MyIntPtr_Depth = MyIntPtr_Depth;\n" + " cmock_call_instance->IgnoreArg_MyIntPtr = 0;\n" + " cmock_call_instance->ReturnThruPtr_MyIntPtr_Used = 0;\n" + - " memcpy(&cmock_call_instance->Expected_MyMyType, &MyMyType, sizeof(MY_TYPE));\n" + + " memcpy((void*)(&cmock_call_instance->Expected_MyMyType), (void*)(&MyMyType), sizeof(MY_TYPE));\n" + " cmock_call_instance->IgnoreArg_MyMyType = 0;\n" + " cmock_call_instance->Expected_MyStr = MyStr;\n" + " cmock_call_instance->IgnoreArg_MyStr = 0;\n" + diff --git a/vendor/unity b/vendor/unity index 031f3bb..0892db2 160000 --- a/vendor/unity +++ b/vendor/unity @@ -1 +1 @@ -Subproject commit 031f3bbe45f8adf504ca3d13e6f093869920b091 +Subproject commit 0892db23760b0dbe06f2644384ad29c3f7d14779 From 035141e2abe255de3c86aebaea38a048578954b7 Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Sun, 7 Jul 2019 14:15:35 -0400 Subject: [PATCH 11/12] - Added capacity accessor for easier testing - Made test size-agnostic for easier boundary checking. --- src/cmock.c | 8 ++++++++ src/cmock.h | 1 + test/c/TestCMockC.c | 20 +++++++++++++++----- test/c/TestCMockC.yml | 1 + test/c/TestCMockC_Runner.c | 16 +++++++++------- 5 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/cmock.c b/src/cmock.c index be26fba..87e1d63 100644 --- a/src/cmock.c +++ b/src/cmock.c @@ -168,6 +168,14 @@ void* CMock_Guts_GetAddressFor(CMOCK_MEM_INDEX_TYPE index) } } +//------------------------------------------------------- +// CMock_Guts_MemBytesCapacity +//------------------------------------------------------- +CMOCK_MEM_INDEX_TYPE CMock_Guts_MemBytesCapacity(void) +{ + return (sizeof(CMock_Guts_Buffer) - CMOCK_MEM_ALIGN_SIZE); +} + //------------------------------------------------------- // CMock_Guts_MemBytesFree //------------------------------------------------------- diff --git a/src/cmock.h b/src/cmock.h index a313448..22552da 100644 --- a/src/cmock.h +++ b/src/cmock.h @@ -30,6 +30,7 @@ CMOCK_MEM_INDEX_TYPE CMock_Guts_MemEndOfChain(CMOCK_MEM_INDEX_TYPE root_index); void* CMock_Guts_GetAddressFor(CMOCK_MEM_INDEX_TYPE index); +CMOCK_MEM_INDEX_TYPE CMock_Guts_MemBytesCapacity(void); CMOCK_MEM_INDEX_TYPE CMock_Guts_MemBytesFree(void); CMOCK_MEM_INDEX_TYPE CMock_Guts_MemBytesUsed(void); void CMock_Guts_MemFreeAll(void); diff --git a/test/c/TestCMockC.c b/test/c/TestCMockC.c index 2f6f3de..769a2b3 100644 --- a/test/c/TestCMockC.c +++ b/test/c/TestCMockC.c @@ -25,8 +25,18 @@ void test_MemNewWillReturnNullIfGivenIllegalSizes(void) TEST_ASSERT_NULL( CMock_Guts_GetAddressFor(CMOCK_GUTS_NONE) ); //verify we're cleared still - TEST_ASSERT_EQUAL(0, CMock_Guts_MemBytesUsed()); - TEST_ASSERT_EQUAL(CMOCK_MEM_SIZE, CMock_Guts_MemBytesFree()); + TEST_ASSERT_LESS_OR_EQUAL_UINT32(CMOCK_MEM_SIZE, CMock_Guts_MemBytesCapacity()); + TEST_ASSERT_EQUAL_UINT32(0, CMock_Guts_MemBytesUsed()); + TEST_ASSERT_LESS_OR_EQUAL_UINT32(CMOCK_MEM_SIZE, CMock_Guts_MemBytesFree()); +} + +void test_MemShouldProtectAgainstMemoryOverflow(void) +{ + (void)CMock_Guts_MemNew(CMOCK_MEM_SIZE - TEST_MEM_INDEX_SIZE); + + //verify we've used all the memory + TEST_ASSERT_LESS_OR_EQUAL_UINT32(TEST_MEM_INDEX_SIZE, CMock_Guts_MemBytesFree()); + TEST_ASSERT_GREATER_OR_EQUAL_UINT32(CMOCK_MEM_SIZE, CMock_Guts_MemBytesUsed()); } void test_MemChainWillReturnNullAndDoNothingIfGivenIllegalInformation(void) @@ -258,11 +268,11 @@ void test_ThatWeCanAskForAllSortsOfSizes(void) } //show that we can't ask for too much memory - TEST_ASSERT_EQUAL_HEX(CMOCK_GUTS_NONE, CMock_Guts_MemNew(12)); - TEST_ASSERT_EQUAL_HEX(CMOCK_GUTS_NONE, CMock_Guts_MemNew(5)); + TEST_ASSERT_EQUAL_HEX(CMOCK_GUTS_NONE, CMock_Guts_MemNew(CMOCK_MEM_SIZE - sum + 8)); + TEST_ASSERT_EQUAL_HEX(CMOCK_GUTS_NONE, CMock_Guts_MemNew(CMOCK_MEM_SIZE - sum + 1)); //but we CAN ask for something that will still fit - next = CMock_Guts_MemNew(4); + next = CMock_Guts_MemNew(CMOCK_MEM_SIZE - sum - 4); TEST_ASSERT_MESSAGE(next != CMOCK_GUTS_NONE, "Should Not Have Returned CMOCK_GUTS_NONE"); first = CMock_Guts_MemChain(first, next); diff --git a/test/c/TestCMockC.yml b/test/c/TestCMockC.yml index 7649385..06067b1 100644 --- a/test/c/TestCMockC.yml +++ b/test/c/TestCMockC.yml @@ -8,6 +8,7 @@ - 'TEST' - 'CMOCK_MEM_STATIC' - 'CMOCK_MEM_SIZE=128' + #- 'CMOCK_MEM_SIZE=40000' - 'CMOCK_MEM_ALIGN=2' - 'CMOCK_MEM_INDEX_TYPE=int' diff --git a/test/c/TestCMockC_Runner.c b/test/c/TestCMockC_Runner.c index ede1ab4..af559d8 100644 --- a/test/c/TestCMockC_Runner.c +++ b/test/c/TestCMockC_Runner.c @@ -12,6 +12,7 @@ extern void setUp(void); extern void tearDown(void); extern void test_MemNewWillReturnNullIfGivenIllegalSizes(void); +extern void test_MemShouldProtectAgainstMemoryOverflow(void); extern void test_MemChainWillReturnNullAndDoNothingIfGivenIllegalInformation(void); extern void test_MemNextWillReturnNullIfGivenABadRoot(void); extern void test_ThatWeCanClaimAndChainAFewElementsTogether(void); @@ -26,13 +27,14 @@ int main(void) UnityBegin(Unity.TestFile); RUN_TEST(test_MemNewWillReturnNullIfGivenIllegalSizes, 21); - RUN_TEST(test_MemChainWillReturnNullAndDoNothingIfGivenIllegalInformation, 32); - RUN_TEST(test_MemNextWillReturnNullIfGivenABadRoot, 46); - RUN_TEST(test_ThatWeCanClaimAndChainAFewElementsTogether, 57); - RUN_TEST(test_MemEndOfChain, 282); - RUN_TEST(test_ThatCMockStopsReturningMoreDataWhenItRunsOutOfMemory, 139); - RUN_TEST(test_ThatCMockStopsReturningMoreDataWhenAskForMoreThanItHasLeftEvenIfNotAtExactEnd, 185); - RUN_TEST(test_ThatWeCanAskForAllSortsOfSizes, 233); + RUN_TEST(test_MemShouldProtectAgainstMemoryOverflow, 33); + RUN_TEST(test_MemChainWillReturnNullAndDoNothingIfGivenIllegalInformation, 42); + RUN_TEST(test_MemNextWillReturnNullIfGivenABadRoot, 56); + RUN_TEST(test_ThatWeCanClaimAndChainAFewElementsTogether, 67); + RUN_TEST(test_MemEndOfChain, 149); + RUN_TEST(test_ThatCMockStopsReturningMoreDataWhenItRunsOutOfMemory, 195); + RUN_TEST(test_ThatCMockStopsReturningMoreDataWhenAskForMoreThanItHasLeftEvenIfNotAtExactEnd, 244); + RUN_TEST(test_ThatWeCanAskForAllSortsOfSizes, 298); UnityEnd(); return 0; From f909378a1d25f7de9405ca3c4f59d2aa3acfae6f Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Sun, 7 Jul 2019 14:43:20 -0400 Subject: [PATCH 12/12] Clean up example makefile to properly support externally supported paths. (This is a tiny fix to PR 193) --- examples/make_example/Makefile | 8 ++++---- scripts/create_makefile.rb | 16 ++++++++-------- vendor/unity | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/examples/make_example/Makefile b/examples/make_example/Makefile index 8a2f403..a0fe532 100644 --- a/examples/make_example/Makefile +++ b/examples/make_example/Makefile @@ -1,8 +1,8 @@ CC ?= gcc -BUILD_DIR ?= ./build -SRC_DIR ?= ./src -TEST_DIR ?= ./test -TEST_BUILD_DIR ?= ${BUILD_DIR}/test +export BUILD_DIR ?= ./build +export SRC_DIR ?= ./src +export TEST_DIR ?= ./test +export TEST_BUILD_DIR ?= ${BUILD_DIR}/test TEST_MAKEFILE = ${TEST_BUILD_DIR}/MakefileTestSupport OBJ ?= ${BUILD_DIR}/obj OBJ_DIR = ${OBJ} diff --git a/scripts/create_makefile.rb b/scripts/create_makefile.rb index e9a9ffb..0aac4bb 100644 --- a/scripts/create_makefile.rb +++ b/scripts/create_makefile.rb @@ -34,9 +34,9 @@ File.open(TEST_MAKEFILE, "w") do |mkfile| # Define make variables mkfile.puts "CC ?= gcc" - mkfile.puts "BUILD_DIR ?= ./build" - mkfile.puts "SRC_DIR ?= ./src" - mkfile.puts "TEST_DIR ?= ./test" + mkfile.puts "BUILD_DIR = #{BUILD_DIR}" + mkfile.puts "SRC_DIR = #{SRC_DIR}" + mkfile.puts "TEST_DIR = #{TEST_DIR}" mkfile.puts "TEST_CFLAGS ?= -DTEST" mkfile.puts "CMOCK_DIR ?= #{CMOCK_DIR}" mkfile.puts "UNITY_DIR ?= #{UNITY_DIR}" @@ -60,8 +60,8 @@ File.open(TEST_MAKEFILE, "w") do |mkfile| test_targets = [] generator = UnityTestRunnerGenerator.new - # headers that begin with prefix or end with suffix are not included - all_headers = Dir["#{SRC_DIR}/**/*.h"] + # headers that begin with prefix or end with suffix are not included + all_headers = Dir["#{SRC_DIR}/**/*.h"] def reject_mock_files(file) extn = File.extname file @@ -73,7 +73,7 @@ File.open(TEST_MAKEFILE, "w") do |mkfile| end all_headers = all_headers.reject { |f| reject_mock_files(f) } - + makefile_targets = [] test_sources.each do |test| @@ -96,7 +96,7 @@ File.open(TEST_MAKEFILE, "w") do |mkfile| if not makefile_targets.include? module_obj makefile_targets.push(module_obj) mkfile.puts "#{module_obj}: #{module_src}" - mkfile.puts "\t${CC} -o $@ -c $< ${TEST_CFLAGS} -I #{SRC_DIR} ${INCLUDE_PATH}" + mkfile.puts "\t${CC} -o $@ -c $< ${TEST_CFLAGS} -I ${SRC_DIR} ${INCLUDE_PATH}" mkfile.puts "" end @@ -112,7 +112,7 @@ File.open(TEST_MAKEFILE, "w") do |mkfile| if not makefile_targets.include? linkonlymodule_obj makefile_targets.push(linkonlymodule_obj) mkfile.puts "#{linkonlymodule_obj}: #{linkonlymodule_src}" - mkfile.puts "\t${CC} -o $@ -c $< ${TEST_CFLAGS} -I #{SRC_DIR} ${INCLUDE_PATH}" + mkfile.puts "\t${CC} -o $@ -c $< ${TEST_CFLAGS} -I ${SRC_DIR} ${INCLUDE_PATH}" mkfile.puts "" end end diff --git a/vendor/unity b/vendor/unity index 0892db2..1100c5d 160000 --- a/vendor/unity +++ b/vendor/unity @@ -1 +1 @@ -Subproject commit 0892db23760b0dbe06f2644384ad29c3f7d14779 +Subproject commit 1100c5d8f0af9f3a68df37e592564535c5de72c6