From 29ef16e54b3b4732bb67365c3fee00f712aac7fc Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Tue, 16 Jun 2026 15:20:21 -0400 Subject: [PATCH] Tidy handling of system tests to depend more on the defines involved then separate tracking. Remove yml files that are no longer needed. --- src/cmock.h | 2 +- test/rakefile | 71 ++++++++----------- test/rakefile_helper.rb | 47 +++++++++--- test/system/test_compilation/const.h | 12 ++-- .../nonstandard_parsed_stuff_1.yml | 2 +- .../test_interactions/out_of_memory.yml | 29 ++++++-- test/targets/clang.yml | 12 ---- test/targets/gcc_32.yml | 14 ---- test/targets/gcc_64.yml | 12 ---- test/targets/iar_arm.yml | 2 - test/targets/tiny.yml | 1 - 11 files changed, 99 insertions(+), 105 deletions(-) delete mode 100644 test/targets/clang.yml delete mode 100644 test/targets/gcc_32.yml delete mode 100644 test/targets/gcc_64.yml diff --git a/src/cmock.h b/src/cmock.h index d7b2a5b..ea8a8db 100644 --- a/src/cmock.h +++ b/src/cmock.h @@ -39,7 +39,7 @@ CMOCK_MEM_INDEX_TYPE CMock_Guts_MemEndOfChain(CMOCK_MEM_INDEX_TYPE root_index) void* CMock_Guts_GetAddressFor(CMOCK_MEM_INDEX_TYPE index) CMOCK_FUNCTION_ATTR(pure); -CMOCK_MEM_INDEX_TYPE CMock_Guts_MemBytesCapacity(void) CMOCK_FUNCTION_ATTR(const); +CMOCK_MEM_INDEX_TYPE CMock_Guts_MemBytesCapacity(void) CMOCK_FUNCTION_ATTR(const); CMOCK_MEM_INDEX_TYPE CMock_Guts_MemBytesFree(void) CMOCK_FUNCTION_ATTR(pure); CMOCK_MEM_INDEX_TYPE CMock_Guts_MemBytesUsed(void) CMOCK_FUNCTION_ATTR(pure); void CMock_Guts_MemFreeAll(void); diff --git a/test/rakefile b/test/rakefile index 9e0c68e..a57b7f5 100644 --- a/test/rakefile +++ b/test/rakefile @@ -50,18 +50,21 @@ task :test => ['test:all'] namespace :test do desc "Run all unit, c, and system tests" - task :all => [:config_toolchains, :clobber, :prep_system_tests, 'test:units', 'test:c', 'test:system'] + task :all => [:config_toolchains, :clobber, :prep_system_tests, 'test:unit', 'test:c', 'test:system'] desc "Run Unit Tests" - task :units => [:config_toolchains, :prep_system_tests] do + task :unit => [:config_toolchains, :prep_system_tests] do run_ruby_unit_tests end #individual unit tests - FileList['unit/*_test.rb'].each do |test| - Rake::TestTask.new(File.basename(test,'.*').sub('_test','') => [:config_toolchains]) do |t| - t.pattern = test - t.verbose = true + namespace :unit do + FileList['unit/*_test.rb'].each do |test| + desc "Run unit test #{File.basename(test,'.*')}" + Rake::TestTask.new(File.basename(test,'.*').sub('_test','') => [:config_toolchains]) do |t| + t.pattern = test + t.verbose = true + end end end @@ -74,36 +77,29 @@ namespace :test do desc "Run System Tests" task :system => [:config_toolchains, :clobber, :prep_system_tests] do - # Get a list of all system tests, removing unsupported tests for this toolchain - # including those explicitly not included, plus those implicitly based on needs - unsupported = unsupported_tests() - criteria = { - 'out_of_memory' => { :defines => ['CMOCK_MEM_STATIC', 'CMOCK_MEM_SIZE=1024']} - } - criteria.each_pair do |k,v| - crit_defs = v[:defines] || [] - test_defs = $unity_cfg.dig(:defines,:test) - conf_defs = (test_defs.is_a?(Hash) ? test_defs['*'] : nil) || test_defs || [] - if (crit_defs & conf_defs).empty? - unsupported |= [k] - end - end - sys_unsupported = unsupported.map {|a| 'system/test_interactions/'+a+'.yml'} - - # Determine which system tests remain after those are removed - sys_tests_to_run = FileList['system/test_interactions/*.yml'] - sys_unsupported - compile_unsupported = unsupported.map {|a| SYSTEST_COMPILE_MOCKABLES_PATH+a+'.h'} - compile_tests_to_run = FileList[SYSTEST_COMPILE_MOCKABLES_PATH + '*.h'] - compile_unsupported - unless (sys_unsupported.empty? and compile_unsupported.empty?) - report "\nIgnoring these system tests..." - sys_unsupported.each {|a| report a} - compile_unsupported.each {|a| report a} - end report "\nRunning system tests..." - tests_failed = run_system_test_interactions(sys_tests_to_run) + tests_failed = run_system_test_interactions(FileList['system/test_interactions/*.yml']) raise "System tests failed." if (tests_failed > 0) - run_system_test_compilations(compile_tests_to_run) + run_system_test_compilations(FileList[SYSTEST_COMPILE_MOCKABLES_PATH + '*.h']) + end + + #individual system tests + namespace :system do + FileList['system/test_interactions/*.yml'].each do |test| + basename = File.basename(test,'.*') + desc "Run system test #{basename}" + task basename => [:config_toolchains, :prep_system_tests] do + run_system_test_interactions([test]) + end + end + FileList[SYSTEST_COMPILE_MOCKABLES_PATH + '*.h'].each do |test| + basename = File.basename(test,'.*') + desc "Run system test #{basename}" + task basename => [:config_toolchains, :prep_system_tests] do + run_system_test_compilations([test]) + end + end end desc "Test cmock examples" @@ -111,15 +107,6 @@ namespace :test do run_examples() end - #individual system tests - FileList['system/test_interactions/*.yml'].each do |test| - basename = File.basename(test,'.*') - #desc "Run system test #{basename}" - task basename => [:config_toolchains] do - run_system_test_interactions([test]) - end - end - desc "Profile Mock Generation" task :profile => [:config_toolchains, :clobber, :prep_system_tests] do run_system_test_profiles(FileList[SYSTEST_COMPILE_MOCKABLES_PATH + '*.h']) diff --git a/test/rakefile_helper.rb b/test/rakefile_helper.rb index b4a414e..6795bcd 100644 --- a/test/rakefile_helper.rb +++ b/test/rakefile_helper.rb @@ -144,10 +144,22 @@ module RakefileHelpers (($unity_cfg[:paths] || {})[:test] || []).select { |p| p.is_a?(Array) } end - # Returns the unsupported test list, regardless of whether it came from - # a CMock overlay or a CMock-only target file. + # Returns the full unsupported test list for the current toolchain, combining: + # - explicit :unsupported lists from the CMock overlay and Unity target files + # - implicit criteria (tests that require defines not present in the toolchain) + UNSUPPORTED_CRITERIA = { + 'out_of_memory' => { :defines => ['CMOCK_MEM_STATIC'] }, + 'unity_64bit_support' => { :defines => ['UNITY_SUPPORT_64'] } + }.freeze + def unsupported_tests - ($cmock_cfg[:unsupported] || []) | ($unity_cfg[:unsupported] || []) + result = ($cmock_cfg[:unsupported] || []) | ($unity_cfg[:unsupported] || []) + test_defs = $unity_cfg.dig(:defines, :test) + conf_defs = (test_defs.is_a?(Hash) ? test_defs['*'] : nil) || test_defs || [] + UNSUPPORTED_CRITERIA.each_pair do |name, crit| + result |= [name] if (crit[:defines] & conf_defs).empty? + end + result end # Resolve argument template tokens and produce a flat argument string. @@ -228,7 +240,7 @@ module RakefileHelpers { command: "#{executable} ", pre_support: pre, post_support: post } end - def execute(command_string, verbose=true, raise_on_failure=true) + def execute(command_string, verbose=false, raise_on_failure=true) report(command_string) if verbose output = `#{command_string}`.chomp report(output) if (verbose && !output.nil? && (output.length > 0)) @@ -320,20 +332,30 @@ module RakefileHelpers def run_system_test_interactions(test_case_files) load '../lib/cmock.rb' + unsupported = unsupported_tests + test_case_files = test_case_files.reject do |f| + name = File.basename(f, YAML_EXTENSION) + if unsupported.include?(name) + report "Ignoring system test: #{name}" + true + end + end + SystemTestGenerator.new.generate_files(test_case_files) - test_files = FileList.new(SYSTEST_GENERATED_FILES_PATH + 'test*.c') load_configuration($cfg_file) include_dirs = get_local_include_dirs # Build and execute each unit test - test_files.each do |test| + test_case_files.each do |yaml| obj_list = [] - test_base = File.basename(test, C_EXTENSION) - cmock_config = test_base.gsub(/test_/, '') + '_cmock.yml' + name = File.basename(yaml, YAML_EXTENSION) + test_base = 'test_' + name + test = SYSTEST_GENERATED_FILES_PATH + test_base + C_EXTENSION + cmock_config = name + '_cmock.yml' report "Executing system tests in #{File.basename(test)}..." @@ -461,6 +483,15 @@ module RakefileHelpers load '../lib/cmock.rb' load_configuration($cfg_file) + unsupported = unsupported_tests + mockables = mockables.reject do |f| + name = File.basename(f, '.h') + if unsupported.include?(name) + report "Ignoring system test compilation: #{name}" + true + end + end + report "\n" report "------------------------------------\n" report "SYSTEM TEST MOCK COMPILATION SUMMARY\n" diff --git a/test/system/test_compilation/const.h b/test/system/test_compilation/const.h index 42aa7f2..fc26581 100644 --- a/test/system/test_compilation/const.h +++ b/test/system/test_compilation/const.h @@ -24,15 +24,15 @@ void const_variants2( const int * const_retval1(void); /* nicety version for pointer to constant int */ int const * const_retval2(void); /* formal version for pointer to constant int */ -//int * const const_retval3(void); /* formal version for constant pointer to int */ -//int const * const const_retval4(void); /* formal version for constant pointer to constant int */ +int * const const_retval3(void); /* formal version for constant pointer to int */ +int const * const const_retval4(void); /* formal version for constant pointer to constant int */ const int* const_retval5(void); /* sticky-left nicety version for pointer to constant int */ int const* const_retval6(void); /* sticky-left formal version for pointer to constant int */ -//int* const const_retval7(void); /* sticky-left formal version for constant pointer to int */ -//int const* const const_retval8(void); /* sticky-left formal version for constant pointer to constant int */ +int* const const_retval7(void); /* sticky-left formal version for constant pointer to int */ +int const* const const_retval8(void); /* sticky-left formal version for constant pointer to constant int */ const int *const_retval9(void); /* sticky-right nicety version for pointer to constant int */ int const *const_retvalA(void); /* sticky-right formal version for pointer to constant int */ -//int *const const_retvalB(void); /* sticky-right formal version for constant pointer to int */ -//int const *const const_retvalC(void); /* sticky-right formal version for constant pointer to constant int */ +int *const const_retvalB(void); /* sticky-right formal version for constant pointer to int */ +int const *const const_retvalC(void); /* sticky-right formal version for constant pointer to constant int */ diff --git a/test/system/test_interactions/nonstandard_parsed_stuff_1.yml b/test/system/test_interactions/nonstandard_parsed_stuff_1.yml index b21f970..e55c70e 100644 --- a/test/system/test_interactions/nonstandard_parsed_stuff_1.yml +++ b/test/system/test_interactions/nonstandard_parsed_stuff_1.yml @@ -27,7 +27,7 @@ const char const * bars(void); :source: - :header: | + :header: | #include "CException.h" void function_a(void); void function_b(void); diff --git a/test/system/test_interactions/out_of_memory.yml b/test/system/test_interactions/out_of_memory.yml index d1f463c..d0afdae 100644 --- a/test/system/test_interactions/out_of_memory.yml +++ b/test/system/test_interactions/out_of_memory.yml @@ -13,9 +13,10 @@ :systest: :types: | + #define BIG_FAT_STRUCT_SIZE (512) typedef struct _BIG_FAT_STRUCT_T { - char bytes[512]; + char bytes[BIG_FAT_STRUCT_SIZE]; } BIG_FAT_STRUCT_T; :mockable: | @@ -52,9 +53,17 @@ :code: | test() { + int i=0; BIG_FAT_STRUCT_T expected = { { 8, 0 } }; - foo_Expect(expected); - function_a(); + // Fill expectations until there is not enough room for more. + // We know we can ask one more when there is only enough room for 2 blocks, ignoring overhead. + while (CMock_Guts_MemBytesFree() > (CMOCK_MEM_SIZE*2)) { + i++; + foo_Expect(expected); + } + for (; i>0; i--) { + function_a(); + } } - :pass: FALSE @@ -62,11 +71,19 @@ :code: | test() { + int i=0; BIG_FAT_STRUCT_T expected1 = { { 9, 1, 0 } }; BIG_FAT_STRUCT_T expected2 = { { 9, 2, 0 } }; - foo_Expect(expected1); - foo_Expect(expected2); - function_b(); + // Ask for more room than we have + while (CMock_Guts_MemBytesFree() > 0) { + foo_Expect(expected1); + foo_Expect(expected2); + } + + // It should not actually get here + for (i=0; i < (CMOCK_MEM_SIZE/BIG_FAT_STRUCT_SIZE - 1); i++) { + function_b(); + } } ... diff --git a/test/targets/clang.yml b/test/targets/clang.yml deleted file mode 100644 index 8af2342..0000000 --- a/test/targets/clang.yml +++ /dev/null @@ -1,12 +0,0 @@ -# ========================================================================= -# CMock - Automatic Mock Generation for C -# ThrowTheSwitch.org -# Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams -# SPDX-License-Identifier: MIT -# ========================================================================= - -# CMock overlay for vendor/unity/test/targets/clang_strict.yml -# Only contains additions not present in the Unity base target. -:unsupported: - - out_of_memory - - callingconv diff --git a/test/targets/gcc_32.yml b/test/targets/gcc_32.yml deleted file mode 100644 index 5206d66..0000000 --- a/test/targets/gcc_32.yml +++ /dev/null @@ -1,14 +0,0 @@ -# ========================================================================= -# CMock - Automatic Mock Generation for C -# ThrowTheSwitch.org -# Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams -# SPDX-License-Identifier: MIT -# ========================================================================= - -# CMock overlay for vendor/unity/test/targets/gcc_32.yml -# Only contains additions not present in the Unity base target. ---- -:unsupported: - - out_of_memory - - unity_64bit_support - - callingconv diff --git a/test/targets/gcc_64.yml b/test/targets/gcc_64.yml deleted file mode 100644 index 3eb837c..0000000 --- a/test/targets/gcc_64.yml +++ /dev/null @@ -1,12 +0,0 @@ -# ========================================================================= -# CMock - Automatic Mock Generation for C -# ThrowTheSwitch.org -# Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams -# SPDX-License-Identifier: MIT -# ========================================================================= - -# CMock overlay for vendor/unity/test/targets/gcc_64.yml -# Only contains additions not present in the Unity base target. -:unsupported: - - out_of_memory - - callingconv diff --git a/test/targets/iar_arm.yml b/test/targets/iar_arm.yml index 2b46d6b..b9eb4cc 100644 --- a/test/targets/iar_arm.yml +++ b/test/targets/iar_arm.yml @@ -9,8 +9,6 @@ # Only contains additions not present in the Unity base target. :unsupported: - - out_of_memory - nonstandard_parsed_stuff_1 - const - callingconv - - unity_64bit_support diff --git a/test/targets/tiny.yml b/test/targets/tiny.yml index b01bc16..0f6435a 100644 --- a/test/targets/tiny.yml +++ b/test/targets/tiny.yml @@ -31,7 +31,6 @@ - struct_union_enum_expect_and_return - struct_union_enum_expect_and_return_with_plugins - stubs_with_callbacks - - unity_64bit_support - unity_ignores - callingconv - C