From 4b265c2f2759b76f0d0f27b5d50d67fa318a610a Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Thu, 5 Jan 2023 16:33:14 -0500 Subject: [PATCH 1/8] Attempt to clear permissions on the bundler scratch file --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1737d97..8df363a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -34,6 +34,7 @@ jobs: sudo gem install bundler sudo gem install rspec sudo gem install rubocop -v 0.57.2 + rm -rf ~/.bundle bundle install # Run Tests From e1545360915c8b3e99b87d3a4323ff732d454dd4 Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Thu, 5 Jan 2023 16:52:11 -0500 Subject: [PATCH 2/8] 2nd attempt to work around bundler headaches. --- .github/workflows/main.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8df363a..fe99669 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -34,8 +34,7 @@ jobs: sudo gem install bundler sudo gem install rspec sudo gem install rubocop -v 0.57.2 - rm -rf ~/.bundle - bundle install + bundle --no-cache install # Run Tests - name: Run All Unit Tests From f3179c6d1176085f7490781d731d9751ae19d0b5 Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Thu, 5 Jan 2023 16:56:07 -0500 Subject: [PATCH 3/8] attempt 3 --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fe99669..be2e55f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -34,7 +34,7 @@ jobs: sudo gem install bundler sudo gem install rspec sudo gem install rubocop -v 0.57.2 - bundle --no-cache install + bundle install --no-cache # Run Tests - name: Run All Unit Tests From 9c44090fa2854d0de136d9efddcaf8ead51af1a3 Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Thu, 5 Jan 2023 17:16:20 -0500 Subject: [PATCH 4/8] Attempt 4: another recommended fix on github. --- .github/workflows/main.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index be2e55f..8a3eb59 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,6 +21,7 @@ jobs: run: | sudo apt-get update --assume-yes sudo apt-get install --assume-yes --quiet gcc-multilib + sudo apt-get install --assume-yes --quiet ruby-dev # Checks out repository under $GITHUB_WORKSPACE - name: Checkout Latest Repo @@ -34,7 +35,7 @@ jobs: sudo gem install bundler sudo gem install rspec sudo gem install rubocop -v 0.57.2 - bundle install --no-cache + bundle install # Run Tests - name: Run All Unit Tests From 019f88b4d9a37d9aaae7e0e8b112d914be5fdb83 Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Thu, 5 Jan 2023 17:31:52 -0500 Subject: [PATCH 5/8] Attempt 5: Ugh. This is ugly. --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8a3eb59..fad6c78 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,7 +21,6 @@ jobs: run: | sudo apt-get update --assume-yes sudo apt-get install --assume-yes --quiet gcc-multilib - sudo apt-get install --assume-yes --quiet ruby-dev # Checks out repository under $GITHUB_WORKSPACE - name: Checkout Latest Repo @@ -35,6 +34,7 @@ jobs: sudo gem install bundler sudo gem install rspec sudo gem install rubocop -v 0.57.2 + sudo chmod 17777 -R /var/lib/gems bundle install # Run Tests From 16d12416fde6305458cad0b905bb077b421d57a2 Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Mon, 9 Jan 2023 14:16:30 -0500 Subject: [PATCH 6/8] Force ourselves to test with Ruby 3. Fix some issues that have been lurking. --- .github/workflows/main.yml | 5 +++++ lib/cmock_generator.rb | 6 +++++- src/cmock.c | 19 ++++++++++++++++--- test/c/TestCMockC.c | 2 +- test/unit/cmock_header_parser_test.rb | 12 ++++++------ 5 files changed, 33 insertions(+), 11 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fad6c78..eb961f5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,6 +16,11 @@ jobs: name: "Unit Tests" runs-on: ubuntu-latest steps: + - uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.0' # Not needed with a .ruby-version file + bundler-cache: true # runs 'bundle install' and caches + # Install Multilib - name: Install Multilib run: | diff --git a/lib/cmock_generator.rb b/lib/cmock_generator.rb index 7905524..b544d74 100644 --- a/lib/cmock_generator.rb +++ b/lib/cmock_generator.rb @@ -137,7 +137,11 @@ class CMockGenerator @file_writer.create_file(mock_project[:module_name] + '.c', @subdir) do |file, fullname| blank_project = mock_project.clone blank_project[:parsed_stuff] = { :functions => [] } - create_source_header_section(file, fullname, blank_project) if existing.empty? + if (existing.empty?) + create_source_header_section(file, fullname, blank_project) + else + file << existing << "\n" + end mock_project[:parsed_stuff][:functions].each do |function| create_function_skeleton(file, function, existing) end diff --git a/src/cmock.c b/src/cmock.c index 7749e3d..e6a1197 100644 --- a/src/cmock.c +++ b/src/cmock.c @@ -25,10 +25,9 @@ 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 = CMOCK_MEM_ALIGN_SIZE; #else -static long long CMock_Guts_Space[(CMOCK_MEM_SIZE + CMOCK_MEM_ALIGN_SIZE + sizeof(long long) - 1) / - sizeof(long long)]; +static long long CMock_Guts_Space[(CMOCK_MEM_SIZE + CMOCK_MEM_ALIGN_SIZE + sizeof(long long) - 1) / sizeof(long long)]; static unsigned char* CMock_Guts_Buffer = (unsigned char *)CMock_Guts_Space; -static CMOCK_MEM_INDEX_TYPE CMock_Guts_BufferSize = sizeof(CMock_Guts_Space); +static CMOCK_MEM_INDEX_TYPE CMock_Guts_BufferSize = CMOCK_MEM_SIZE + CMOCK_MEM_ALIGN_SIZE;//sizeof(CMock_Guts_Space); static CMOCK_MEM_INDEX_TYPE CMock_Guts_FreePtr = CMOCK_MEM_ALIGN_SIZE; #endif @@ -41,12 +40,16 @@ CMOCK_MEM_INDEX_TYPE CMock_Guts_MemNew(CMOCK_MEM_INDEX_TYPE size) /* verify arguments valid (we must be allocating space for at least 1 byte, and the existing chain must be in memory somewhere) */ if (size < 1) + { return CMOCK_GUTS_NONE; + } /* verify we have enough room */ size = size + CMOCK_MEM_INDEX_SIZE; if (size & CMOCK_MEM_ALIGN_MASK) + { size = (size + CMOCK_MEM_ALIGN_MASK) & ~CMOCK_MEM_ALIGN_MASK; + } if ((CMock_Guts_BufferSize - CMock_Guts_FreePtr) < size) { #ifndef CMOCK_MEM_DYNAMIC @@ -105,9 +108,13 @@ CMOCK_MEM_INDEX_TYPE CMock_Guts_MemChain(CMOCK_MEM_INDEX_TYPE root_index, CMOCK_ do { index = *(CMOCK_MEM_INDEX_TYPE*)((CMOCK_MEM_PTR_AS_INT)next - CMOCK_MEM_INDEX_SIZE); if (index >= CMock_Guts_FreePtr) + { return CMOCK_GUTS_NONE; + } if (index > 0) + { next = (void*)(&CMock_Guts_Buffer[index]); + } } while (index > 0); *(CMOCK_MEM_INDEX_TYPE*)((CMOCK_MEM_PTR_AS_INT)next - CMOCK_MEM_INDEX_SIZE) = (CMOCK_MEM_INDEX_TYPE)((CMOCK_MEM_PTR_AS_INT)obj - (CMOCK_MEM_PTR_AS_INT)CMock_Guts_Buffer); return root_index; @@ -124,16 +131,22 @@ CMOCK_MEM_INDEX_TYPE CMock_Guts_MemNext(CMOCK_MEM_INDEX_TYPE previous_item_index /* There is nothing "next" if the pointer isn't from our buffer */ if ((previous_item_index < CMOCK_MEM_ALIGN_SIZE) || (previous_item_index >= CMock_Guts_FreePtr)) + { return CMOCK_GUTS_NONE; + } previous_item = (void*)(&CMock_Guts_Buffer[previous_item_index]); /* if the pointer is good, then use it to look up the next index * (we know the first element always goes in zero, so NEXT must always be > 1) */ index = *(CMOCK_MEM_INDEX_TYPE*)((CMOCK_MEM_PTR_AS_INT)previous_item - CMOCK_MEM_INDEX_SIZE); if ((index > 1) && (index < CMock_Guts_FreePtr)) + { return index; + } else + { return CMOCK_GUTS_NONE; + } } /*------------------------------------------------------- diff --git a/test/c/TestCMockC.c b/test/c/TestCMockC.c index 769a2b3..a5c2194 100644 --- a/test/c/TestCMockC.c +++ b/test/c/TestCMockC.c @@ -32,7 +32,7 @@ void test_MemNewWillReturnNullIfGivenIllegalSizes(void) void test_MemShouldProtectAgainstMemoryOverflow(void) { - (void)CMock_Guts_MemNew(CMOCK_MEM_SIZE - TEST_MEM_INDEX_SIZE); + TEST_ASSERT_NOT_EQUAL_UINT( CMOCK_GUTS_NONE, 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()); diff --git a/test/unit/cmock_header_parser_test.rb b/test/unit/cmock_header_parser_test.rb index bee6a24..eedc0cb 100644 --- a/test/unit/cmock_header_parser_test.rb +++ b/test/unit/cmock_header_parser_test.rb @@ -41,7 +41,7 @@ describe CMockHeaderParser, "Verify CMockHeaderParser Module" do end it "create and initialize variables to defaults appropriately" do - assert_equal(nil, @parser.funcs) + assert_nil(@parser.funcs) assert_equal(['const', '__ramfunc', 'funky_attrib', 'SQLITE_API'], @parser.c_attributes) assert_equal(['void','MY_FUNKY_VOID'], @parser.treat_as_void) end @@ -377,7 +377,7 @@ describe CMockHeaderParser, "Verify CMockHeaderParser Module" do @parser.parse("module", source) end - assert_equal(nil, @parser.funcs) + assert_nil(@parser.funcs) # verify exception message begin @@ -401,7 +401,7 @@ describe CMockHeaderParser, "Verify CMockHeaderParser Module" do @parser.parse("module", source) end - assert_equal(nil, @parser.funcs) + assert_nil(@parser.funcs) # verify exception message begin @@ -429,7 +429,7 @@ describe CMockHeaderParser, "Verify CMockHeaderParser Module" do @parser.parse("module", source) end - assert_equal(nil, @parser.funcs) + assert_nil(@parser.funcs) # verify exception message begin @@ -670,7 +670,7 @@ describe CMockHeaderParser, "Verify CMockHeaderParser Module" do @parser.parse("module", source) end - assert_equal(nil, @parser.funcs) + assert_nil(@parser.funcs) # verify exception message begin @@ -699,7 +699,7 @@ describe CMockHeaderParser, "Verify CMockHeaderParser Module" do @parser.parse("module", source) end - assert_equal(nil, @parser.funcs) + assert_nil(@parser.funcs) # verify exception message begin From aefdb44f0cccbb314a6829ec4cd5bb94380621b5 Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Mon, 9 Jan 2023 14:25:05 -0500 Subject: [PATCH 7/8] Whooops. Forgot to remove this. --- .github/workflows/main.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index eb961f5..a0471ec 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,7 +20,7 @@ jobs: with: ruby-version: '3.0' # Not needed with a .ruby-version file bundler-cache: true # runs 'bundle install' and caches - + # Install Multilib - name: Install Multilib run: | @@ -39,7 +39,6 @@ jobs: sudo gem install bundler sudo gem install rspec sudo gem install rubocop -v 0.57.2 - sudo chmod 17777 -R /var/lib/gems bundle install # Run Tests From 5838025996e00eaa9999fd64648ebb5c591225c1 Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Mon, 9 Jan 2023 14:30:01 -0500 Subject: [PATCH 8/8] rubocop fix. --- 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 b544d74..826bf8b 100644 --- a/lib/cmock_generator.rb +++ b/lib/cmock_generator.rb @@ -137,7 +137,7 @@ class CMockGenerator @file_writer.create_file(mock_project[:module_name] + '.c', @subdir) do |file, fullname| blank_project = mock_project.clone blank_project[:parsed_stuff] = { :functions => [] } - if (existing.empty?) + if existing.empty? create_source_header_section(file, fullname, blank_project) else file << existing << "\n"