From c06bbe791c9c4d7c58d27c531cab035666c1f134 Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Fri, 29 May 2026 16:09:22 -0400 Subject: [PATCH] run examples fully and pass optional yaml file to them. begin to automatically reject tests based on criteria. --- examples/make_example/Makefile | 2 +- examples/make_example/test/test_main.c | 2 +- examples/temp_sensor/rakefile_helper.rb | 10 ++++---- scripts/create_makefile.rb | 2 +- test/rakefile | 32 ++++++++++++++++++------- test/rakefile_helper.rb | 28 +++++++++++++++------- vendor/unity | 2 +- 7 files changed, 52 insertions(+), 26 deletions(-) diff --git a/examples/make_example/Makefile b/examples/make_example/Makefile index 329f790..73baf3f 100644 --- a/examples/make_example/Makefile +++ b/examples/make_example/Makefile @@ -14,7 +14,7 @@ all: setup test ${BUILD_DIR}/main run setup: mkdir -p ${BUILD_DIR} mkdir -p ${OBJ} - ruby ../../scripts/create_makefile.rb --silent + ruby ../../scripts/create_makefile.rb clean: rm -rf ${BUILD_DIR} diff --git a/examples/make_example/test/test_main.c b/examples/make_example/test/test_main.c index 8e9e3ea..2100742 100644 --- a/examples/make_example/test/test_main.c +++ b/examples/make_example/test/test_main.c @@ -6,7 +6,7 @@ ========================================================================= */ #include "unity.h" -#include "mock_foo.h" +#include "Mockfoo.h" void setUp(void) { diff --git a/examples/temp_sensor/rakefile_helper.rb b/examples/temp_sensor/rakefile_helper.rb index 07f51ab..c31befb 100644 --- a/examples/temp_sensor/rakefile_helper.rb +++ b/examples/temp_sensor/rakefile_helper.rb @@ -179,8 +179,8 @@ module RakefileHelpers def compile(file, extra_defines = []) tool = $unity_cfg[:tools][:test_compiler] - ext = $unity_cfg[:extension][:object] - build_root = $proj[:project][:build_root] + ext = $unity_cfg[:extension][:object] || '.o' + build_root = $proj[:project][:build_root] || 'build/' obj_file = build_root + File.basename(file, C_EXTENSION) + ext cmd_str = "#{tackit(tool[:executable])} #{ @@ -195,8 +195,8 @@ module RakefileHelpers def link_it(exe_name, obj_list) tool = $unity_cfg[:tools][:test_linker] - ext = $unity_cfg[:extension][:executable] - build_root = $proj[:project][:build_root] + ext = $unity_cfg[:extension][:executable] || '' + build_root = $proj[:project][:build_root] || 'build/' input_files = obj_list.uniq.map { |obj| build_root + obj }.join(' ') output_file = build_root + exe_name + ext @@ -288,7 +288,7 @@ module RakefileHelpers # Execute unit test and generate results file simulator = build_simulator_fields build_root = $proj[:project][:build_root] - executable = build_root + test_base + $unity_cfg[:extension][:executable] + executable = build_root + test_base + ($unity_cfg[:extension][:executable] || '') cmd_str = if simulator.nil? executable else diff --git a/scripts/create_makefile.rb b/scripts/create_makefile.rb index 93870c0..3050547 100644 --- a/scripts/create_makefile.rb +++ b/scripts/create_makefile.rb @@ -24,7 +24,7 @@ CMOCK_OBJ = File.join(OBJ_DIR, 'cmock.o') RUNNERS_DIR = File.join(TEST_BUILD_DIR, 'runners') MOCKS_DIR = File.join(TEST_BUILD_DIR, 'mocks') TEST_BIN_DIR = TEST_BUILD_DIR -MOCK_PREFIX = ENV.fetch('TEST_MOCK_PREFIX', 'mock_') +MOCK_PREFIX = ENV.fetch('TEST_MOCK_PREFIX', 'Mock') MOCK_SUFFIX = ENV.fetch('TEST_MOCK_SUFFIX', '') TEST_MAKEFILE = ENV.fetch('TEST_MAKEFILE', File.join(TEST_BUILD_DIR, 'MakefileTestSupport')) MOCK_MATCHER = /#{MOCK_PREFIX}[A-Za-z_][A-Za-z0-9_\-.]+#{MOCK_SUFFIX}/ diff --git a/test/rakefile b/test/rakefile index 3e2df22..35977cf 100644 --- a/test/rakefile +++ b/test/rakefile @@ -27,8 +27,8 @@ SYSTEM_TEST_SUPPORT_DIRS.each do |dir| CLOBBER.include(dir) end -$config_file = DEFAULT_CONFIG_FILE -$overlay_file = nil +$cmock_test_config_file = DEFAULT_CONFIG_FILE +$cmock_test_overlay_file = nil task :prep_system_tests => SYSTEM_TEST_SUPPORT_DIRS task :default => [:test] @@ -37,12 +37,12 @@ task :cruise => :ci desc "Load configuration" task :config, [:config_file, :cmock_overlay] do |t, args| - $config_file = args[:config_file] - $overlay_file = args[:cmock_overlay] + $cmock_test_config_file = args[:config_file] + $cmock_test_overlay_file = args[:cmock_overlay] end task :config_toolchains do - configure_toolchain($config_file, $overlay_file) + configure_toolchain($cmock_test_config_file, $cmock_test_overlay_file) end # Still support testing everything with just 'test' but switch default to ceedling-like test:all @@ -74,10 +74,24 @@ 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 compiler - sys_unsupported = unsupported_tests.map {|a| 'system/test_interactions/'+a+'.yml'} + # 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] || [] + conf_defs = $unity_cfg.dig(:defines,:test,'*') || $unity_cfg.dig(:defines,:test) || [] + 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_tests.map {|a| SYSTEST_COMPILE_MOCKABLES_PATH+a+'.h'} + 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..." @@ -93,7 +107,7 @@ namespace :test do desc "Test cmock examples" task :examples => [:config_toolchains, :prep_system_tests] do - run_examples(true) + run_examples() end #individual system tests diff --git a/test/rakefile_helper.rb b/test/rakefile_helper.rb index 0fcdf7e..f5f79fe 100644 --- a/test/rakefile_helper.rb +++ b/test/rakefile_helper.rb @@ -147,7 +147,7 @@ module RakefileHelpers # Returns the unsupported test list, regardless of whether it came from # a CMock overlay or a CMock-only target file. def unsupported_tests - $cmock_cfg[:unsupported] || $unity_cfg[:unsupported] || [] + ($cmock_cfg[:unsupported] || []) | ($unity_cfg[:unsupported] || []) end # Resolve argument template tokens and produce a flat argument string. @@ -229,6 +229,7 @@ module RakefileHelpers end def execute(command_string, verbose=true, raise_on_failure=true) + report(command_string) if verbose output = `#{command_string}`.chomp report(output) if (verbose && !output.nil? && (output.length > 0)) if ($?.exitstatus != 0) and (raise_on_failure) @@ -521,7 +522,7 @@ module RakefileHelpers raise "C unit tests failed." if result =~ /FAILED/ end - def run_examples(verbose=false, raise_on_failure=true) + def run_examples() report "\n" report "-----------------\n" report "VALIDATE EXAMPLES\n" @@ -529,11 +530,20 @@ module RakefileHelpers total_tests = 0 total_failures = 0 total_ignored = 0 - [ "cd #{File.join("..", "examples", "make_example")} && make clean && make setup && make test", - "cd #{File.join("..", "examples", "temp_sensor")} && rake ci" - ].each do |cmd| - report "Testing '#{cmd}'" - execute(cmd, verbose, false).each_line do |line| + puts "DEBUG DIS #{$cmock_test_config_file}" + cfg_file = "#{($cmock_test_config_file =~ /[\\\/]/) ? '../' : ''}#{$cmock_test_config_file}" + + # Determine which examples are valid for this platform + examples = { + :make_example => "cd #{File.join("..", "examples", "make_example")} && make clean && make setup && make test", + :rake_example => "cd #{File.join("..", "examples", "temp_sensor")} && rake config[\"#{cfg_file}\"] ci" + } + examples.delete(:make_example) unless ($cmock_test_config_file =~ /gcc/) + + # Run the examples + examples.each_pair do |key, cmd| + report "Testing Example: '#{key}'" + execute(cmd, true, false).each_line do |line| if line =~ /(\d+) TOTAL TESTS (\d+) TOTAL FAILURES (\d+) IGNORED/ total_tests += Regexp.last_match(1).to_i total_failures += Regexp.last_match(2).to_i @@ -541,10 +551,12 @@ module RakefileHelpers end end end + + # Report the results from the examples result = "#{total_tests} Tests #{total_failures} Failures #{total_ignored} Ignored\n" result += total_failures > 0 ? "FAILED\n" : "OK\n" save_test_results('examples', result) - raise "Examples failed." if total_failures > 0 && raise_on_failure + raise "Examples failed." if total_failures > 0 end def fail_out(msg) diff --git a/vendor/unity b/vendor/unity index 444fbda..bbf8f37 160000 --- a/vendor/unity +++ b/vendor/unity @@ -1 +1 @@ -Subproject commit 444fbda72a77932c3c96aed6c203d96963c1b7bf +Subproject commit bbf8f3728a937c7627b8094de7ae13559d220ed5