From e5f89062a0385726393df0281cf3aa12d1481a81 Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Tue, 7 Jul 2026 17:08:36 -0400 Subject: [PATCH] Update to latest Unity, raising warning / error level in the process. Clean up some warnings. Purposefully accept them in tests where we're verifying it still mocks when those issues exist. --- examples/temp_sensor/rakefile.rb | 2 +- examples/temp_sensor/src/AdcModel.c | 2 ++ test/gcc_64_valgrind.yml | 9 +----- test/rakefile | 2 +- test/rakefile_helper.rb | 31 ++++++++++++++++--- test/system/test_compilation/config.yml | 6 ++++ .../const_ptr_return_and_arg.yml | 9 ++++++ .../nonstandard_parsed_stuff_2.yml | 9 ++++-- .../unity_void_pointer_compare.yml | 16 +++++----- .../void_pointer_no_array_plugin.yml | 8 ++--- ...oid_pointer_treat_as_void_array_plugin.yml | 12 +++---- .../wrong_expect_and_return.yml | 8 +++++ vendor/unity | 2 +- 13 files changed, 79 insertions(+), 37 deletions(-) diff --git a/examples/temp_sensor/rakefile.rb b/examples/temp_sensor/rakefile.rb index a5e0264..278852b 100644 --- a/examples/temp_sensor/rakefile.rb +++ b/examples/temp_sensor/rakefile.rb @@ -20,7 +20,7 @@ REQUIRED_DIRS.each do |v| end # Load default configuration, for now -DEFAULT_CONFIG_FILE = 'gcc_64.yml'.freeze +DEFAULT_CONFIG_FILE = 'gcc.yml'.freeze configure_toolchain(DEFAULT_CONFIG_FILE) task :unit do diff --git a/examples/temp_sensor/src/AdcModel.c b/examples/temp_sensor/src/AdcModel.c index 9bd83d7..427d828 100644 --- a/examples/temp_sensor/src/AdcModel.c +++ b/examples/temp_sensor/src/AdcModel.c @@ -23,11 +23,13 @@ void AdcModel_ProcessInput(uint16 millivolts) bool AdcModel_DoNothingExceptTestASpecialType(EXAMPLE_STRUCT_T ExampleStruct) { //This doesn't really do anything. it's only here to make sure I can compare a struct. + (void)ExampleStruct; return FALSE; } bool AdModel_DoNothingExceptTestPointers(uint32* pExample) { //This doesn't really do anything. it's only here to make sure I can compare a pointer value. + (void)pExample; return FALSE; } diff --git a/test/gcc_64_valgrind.yml b/test/gcc_64_valgrind.yml index a3af73b..124eb2c 100644 --- a/test/gcc_64_valgrind.yml +++ b/test/gcc_64_valgrind.yml @@ -5,7 +5,7 @@ # SPDX-License-Identifier: MIT # ========================================================================= -# gcc_64 with debug symbols enabled for meaningful valgrind output. +# gcc with debug symbols enabled for meaningful valgrind output. # Used by the CI valgrind job to check for memory leaks and errors. --- @@ -15,7 +15,6 @@ :executable: gcc :arguments: - "-c" - - "-m64" - "-g" - "-Wall" - "-Wno-address" @@ -31,18 +30,12 @@ :arguments: - "${1}" - "-lm" - - "-m64" - "-o ${2}" :extension: :object: ".o" :executable: ".exe" :defines: :test: - - UNITY_EXCLUDE_STDINT_H - - UNITY_EXCLUDE_LIMITS_H - UNITY_INCLUDE_DOUBLE - UNITY_SUPPORT_TEST_CASES - UNITY_SUPPORT_64 - - UNITY_INT_WIDTH=32 - - UNITY_LONG_WIDTH=64 - - UNITY_POINTER_WIDTH=64 diff --git a/test/rakefile b/test/rakefile index a57b7f5..1813894 100644 --- a/test/rakefile +++ b/test/rakefile @@ -14,7 +14,7 @@ require './rakefile_helper' include RakefileHelpers -DEFAULT_CONFIG_FILE = 'gcc_64.yml' +DEFAULT_CONFIG_FILE = 'gcc.yml' CMOCK_TEST_ROOT = File.expand_path(File.dirname(__FILE__)) SYSTEM_TEST_SUPPORT_DIRS = [ diff --git a/test/rakefile_helper.rb b/test/rakefile_helper.rb index 8c9adba..040033c 100644 --- a/test/rakefile_helper.rb +++ b/test/rakefile_helper.rb @@ -194,7 +194,21 @@ module RakefileHelpers result.join(' ') end - def compile(file, extra_defines = []) + def compiler_basename + exe = $unity_cfg[:tools][:test_compiler][:executable] + File.basename(exe.is_a?(Array) ? exe.join : exe.to_s) + end + + def extra_flags_for_compiler(flags_config) + return [] unless flags_config + + basename = compiler_basename + flags_config.each_with_object([]) do |(compiler_key, flags), result| + result.concat(Array(flags)) if basename.include?(compiler_key.to_s) + end + end + + def compile(file, extra_defines = [], extra_flags = []) tool = $unity_cfg[:tools][:test_compiler] ext = $unity_cfg[:extension][:object] || '.o' build_root = $proj[:project][:build_root] || 'build/' @@ -206,6 +220,7 @@ module RakefileHelpers $proj[:paths][:include], all_defines(extra_defines), file, obj_file) + cmd_str += ' ' + extra_flags.join(' ') unless extra_flags.empty? execute(cmd_str) File.basename(obj_file) end @@ -356,6 +371,9 @@ module RakefileHelpers test = SYSTEST_GENERATED_FILES_PATH + test_base + C_EXTENSION cmock_config = name + '_cmock.yml' + yaml_content = load_yaml(yaml) + extra_flags = extra_flags_for_compiler((yaml_content || {})[:flags]) + report "Executing system tests in #{File.basename(test)}..." # Detect dependencies and build required modules @@ -369,17 +387,17 @@ module RakefileHelpers end # Compile corresponding source file if it exists src_file = find_source_file(header, include_dirs) - obj_list << compile(src_file) unless src_file.nil? + obj_list << compile(src_file, [], extra_flags) unless src_file.nil? end # Generate and build the test suite runner runner_name = test_base + '_runner.c' runner_path = $proj[:paths][:source].first + runner_name UnityTestRunnerGenerator.new(SYSTEST_GENERATED_FILES_PATH + cmock_config).run(test, runner_path) - obj_list << compile(runner_path) + obj_list << compile(runner_path, [], extra_flags) # Build the test module - obj_list << compile(test) + obj_list << compile(test, [], extra_flags) # Link the test executable link_it(test_base, obj_list) @@ -498,6 +516,9 @@ module RakefileHelpers end end + compile_config = load_yaml(SYSTEST_COMPILE_MOCKABLES_PATH + 'config.yml') + extra_flags = extra_flags_for_compiler((compile_config || {})[:flags]) + report "\n" report "------------------------------------\n" report "SYSTEM TEST MOCK COMPILATION SUMMARY\n" @@ -507,7 +528,7 @@ module RakefileHelpers mock_filename = 'mock_' + File.basename(header).ext('.c') CMock.new(SYSTEST_COMPILE_MOCKABLES_PATH + 'config.yml').setup_mocks(header) report "Compiling #{mock_filename}..." - compile(SYSTEST_GENERATED_FILES_PATH + mock_filename) + compile(SYSTEST_GENERATED_FILES_PATH + mock_filename, [], extra_flags) pass_count += 1 end report "#{pass_count} Tests 0 Failures 0 Ignored\nOK\n" diff --git a/test/system/test_compilation/config.yml b/test/system/test_compilation/config.yml index 00d93fe..ec02ed8 100644 --- a/test/system/test_compilation/config.yml +++ b/test/system/test_compilation/config.yml @@ -6,6 +6,12 @@ # ========================================================================= --- +:flags: + :gcc: + - -Wno-ignored-qualifiers + :clang: + - -Wno-ignored-qualifiers + :cmock: :plugins: [] :includes: [] diff --git a/test/system/test_interactions/const_ptr_return_and_arg.yml b/test/system/test_interactions/const_ptr_return_and_arg.yml index bc43b70..18cadc2 100644 --- a/test/system/test_interactions/const_ptr_return_and_arg.yml +++ b/test/system/test_interactions/const_ptr_return_and_arg.yml @@ -10,6 +10,15 @@ :plugins: - # none +# We are purposefully trying various (sometimes pointless) configurations +# of const, so that we can ensure cmock handles them all, for compilers that +# accept that style. Ignore this warning so it can be tested +:flags: + :gcc: + - -Wno-ignored-qualifiers + :clang: + - -Wno-ignored-qualifiers + :systest: :types: | diff --git a/test/system/test_interactions/nonstandard_parsed_stuff_2.yml b/test/system/test_interactions/nonstandard_parsed_stuff_2.yml index 70ecfdb..caac744 100644 --- a/test/system/test_interactions/nonstandard_parsed_stuff_2.yml +++ b/test/system/test_interactions/nonstandard_parsed_stuff_2.yml @@ -40,7 +40,8 @@ test() { unsigned char a[] = { 1, 2, 3, 4, 5, 6 }; - unsigned char** pa = (unsigned char**)(&a); + unsigned char* aa[] = { &a[0], &a[1], &a[2], &a[3], &a[4], &a[5], &a[6], &a[7] }; + unsigned char** pa = (unsigned char**)(aa); bar_ExpectAndReturn(pa); foo_Expect(pa); @@ -54,9 +55,11 @@ test() { unsigned char a[] = { 1, 2, 3, 4, 5, 6 }; + unsigned char* aa[] = { &a[0], &a[1], &a[2], &a[3], &a[4], &a[5], &a[6], &a[7] }; unsigned char b[] = { 5, 6, 7, 8, 9, 0 }; - unsigned char** pa = (unsigned char**)(&a); - unsigned char** pb = (unsigned char**)(&b); + unsigned char* bb[] = { &b[0], &b[1], &b[2], &b[3], &b[4], &b[5], &b[6], &b[7] }; + unsigned char** pa = (unsigned char**)(aa); + unsigned char** pb = (unsigned char**)(bb); bar_ExpectAndReturn(pa); foo_Expect(pb); diff --git a/test/system/test_interactions/unity_void_pointer_compare.yml b/test/system/test_interactions/unity_void_pointer_compare.yml index a99466c..33a4eb7 100644 --- a/test/system/test_interactions/unity_void_pointer_compare.yml +++ b/test/system/test_interactions/unity_void_pointer_compare.yml @@ -45,8 +45,8 @@ :code: | test() { - char* a = "Hello"; - char* b = "Hello"; + char* a = (char*)("Hello"); + char* b = (char*)("Hello"); ret_v_ptr_ExpectAndReturn(a); get_v_ptr_Expect(b); get_v_ptr_typedefed_Expect((VOID_PTR)b); @@ -59,8 +59,8 @@ :code: | test() { - char* a = "Hello"; - char* b = "Hello"; + char* a = (char*)("Hello"); + char* b = (char*)("Hello"); ret_v_ptr_ExpectAndReturn(a); get_v_ptr_ExpectWithArray(b,5); get_v_ptr_typedefed_ExpectWithArray((VOID_PTR)b,5); @@ -73,8 +73,8 @@ :code: | test() { - char* a = "Hello"; - char* b = "Jello"; + char* a = (char*)("Hello"); + char* b = (char*)("Jello"); ret_v_ptr_ExpectAndReturn(a); get_v_ptr_Expect(b); get_v_ptr_typedefed_Expect((VOID_PTR)b); @@ -87,8 +87,8 @@ :code: | test() { - char* a = "Hello"; - char* b = "Hella"; + char* a = (char*)("Hello"); + char* b = (char*)("Hella"); ret_v_ptr_ExpectAndReturn(a); get_v_ptr_ExpectWithArray(b,5); get_v_ptr_typedefed_ExpectWithArray((VOID_PTR)b,5); diff --git a/test/system/test_interactions/void_pointer_no_array_plugin.yml b/test/system/test_interactions/void_pointer_no_array_plugin.yml index 79a8154..aed837f 100644 --- a/test/system/test_interactions/void_pointer_no_array_plugin.yml +++ b/test/system/test_interactions/void_pointer_no_array_plugin.yml @@ -54,7 +54,7 @@ :code: | test() { - char* a = "Hello"; + char* a = (char*)("Hello"); get_v_ptr_Expect(a); function_a(a); } @@ -84,7 +84,7 @@ :code: | test() { - char* a = "Hello"; + char* a = (char*)("Hello"); get_v_ptr_Expect(NULL); function_a(a); } @@ -94,7 +94,7 @@ :code: | test() { - char* a = "Hello"; + char* a = (char*)("Hello"); get_const_v_ptr_Expect(a); function_b(a); } @@ -115,7 +115,7 @@ :code: | test() { - char* a = "Hello"; + char* a = (char*)("Hello"); get_my_void_ptr_Expect(a); function_c(a); } diff --git a/test/system/test_interactions/void_pointer_treat_as_void_array_plugin.yml b/test/system/test_interactions/void_pointer_treat_as_void_array_plugin.yml index 5d9feed..3c5f173 100644 --- a/test/system/test_interactions/void_pointer_treat_as_void_array_plugin.yml +++ b/test/system/test_interactions/void_pointer_treat_as_void_array_plugin.yml @@ -43,7 +43,7 @@ :code: | test() { - char* a = "Hello"; + char* a = (char*)("Hello"); get_my_void_ptr_Expect(a); function_a(a); } @@ -53,8 +53,8 @@ :code: | test() { - char* a = "Hello"; - char* b = "Hello"; + char* a = (char*)("Hello"); + char* b = (char*)("Hello"); get_my_void_ptr_ExpectWithArray(a, 5); function_a(b); } @@ -64,8 +64,8 @@ :code: | test() { - char* a = "Hello"; - char* b = "Jello"; + char* a = (char*)("Hello"); + char* b = (char*)("Jello"); get_my_void_ptr_ExpectWithArray(a, 5); function_a(b); } @@ -84,7 +84,7 @@ :code: | test() { - char* a = "Hello"; + char* a = (char*)("Hello"); get_my_void_ptr_ExpectWithArray(a, 0); function_a(a); } diff --git a/test/system/test_interactions/wrong_expect_and_return.yml b/test/system/test_interactions/wrong_expect_and_return.yml index 13a8734..c65bdad 100644 --- a/test/system/test_interactions/wrong_expect_and_return.yml +++ b/test/system/test_interactions/wrong_expect_and_return.yml @@ -11,6 +11,14 @@ - :ignore - :expect_any_args +# We are purposefully testing some unreachable code in this module, so +# we need to block this warning so we can run this test +:flags: + :gcc: + - -Wno-unreachable-code + :clang: + - -Wno-unreachable-code + :systest: :types: | #define UINT32 unsigned int diff --git a/vendor/unity b/vendor/unity index bbf8f37..76e0803 160000 --- a/vendor/unity +++ b/vendor/unity @@ -1 +1 @@ -Subproject commit bbf8f3728a937c7627b8094de7ae13559d220ed5 +Subproject commit 76e0803cb48cbf0e317a3a9741a63a74dd8a56cb