mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-06-05 21:15:20 +00:00
run examples fully and pass optional yaml file to them.
begin to automatically reject tests based on criteria.
This commit is contained in:
@@ -14,7 +14,7 @@ all: setup test ${BUILD_DIR}/main run
|
|||||||
setup:
|
setup:
|
||||||
mkdir -p ${BUILD_DIR}
|
mkdir -p ${BUILD_DIR}
|
||||||
mkdir -p ${OBJ}
|
mkdir -p ${OBJ}
|
||||||
ruby ../../scripts/create_makefile.rb --silent
|
ruby ../../scripts/create_makefile.rb
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf ${BUILD_DIR}
|
rm -rf ${BUILD_DIR}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
========================================================================= */
|
========================================================================= */
|
||||||
|
|
||||||
#include "unity.h"
|
#include "unity.h"
|
||||||
#include "mock_foo.h"
|
#include "Mockfoo.h"
|
||||||
|
|
||||||
void setUp(void)
|
void setUp(void)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -179,8 +179,8 @@ module RakefileHelpers
|
|||||||
|
|
||||||
def compile(file, extra_defines = [])
|
def compile(file, extra_defines = [])
|
||||||
tool = $unity_cfg[:tools][:test_compiler]
|
tool = $unity_cfg[:tools][:test_compiler]
|
||||||
ext = $unity_cfg[:extension][:object]
|
ext = $unity_cfg[:extension][:object] || '.o'
|
||||||
build_root = $proj[:project][:build_root]
|
build_root = $proj[:project][:build_root] || 'build/'
|
||||||
obj_file = build_root + File.basename(file, C_EXTENSION) + ext
|
obj_file = build_root + File.basename(file, C_EXTENSION) + ext
|
||||||
|
|
||||||
cmd_str = "#{tackit(tool[:executable])} #{
|
cmd_str = "#{tackit(tool[:executable])} #{
|
||||||
@@ -195,8 +195,8 @@ module RakefileHelpers
|
|||||||
|
|
||||||
def link_it(exe_name, obj_list)
|
def link_it(exe_name, obj_list)
|
||||||
tool = $unity_cfg[:tools][:test_linker]
|
tool = $unity_cfg[:tools][:test_linker]
|
||||||
ext = $unity_cfg[:extension][:executable]
|
ext = $unity_cfg[:extension][:executable] || ''
|
||||||
build_root = $proj[:project][:build_root]
|
build_root = $proj[:project][:build_root] || 'build/'
|
||||||
|
|
||||||
input_files = obj_list.uniq.map { |obj| build_root + obj }.join(' ')
|
input_files = obj_list.uniq.map { |obj| build_root + obj }.join(' ')
|
||||||
output_file = build_root + exe_name + ext
|
output_file = build_root + exe_name + ext
|
||||||
@@ -288,7 +288,7 @@ module RakefileHelpers
|
|||||||
# Execute unit test and generate results file
|
# Execute unit test and generate results file
|
||||||
simulator = build_simulator_fields
|
simulator = build_simulator_fields
|
||||||
build_root = $proj[:project][:build_root]
|
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?
|
cmd_str = if simulator.nil?
|
||||||
executable
|
executable
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ CMOCK_OBJ = File.join(OBJ_DIR, 'cmock.o')
|
|||||||
RUNNERS_DIR = File.join(TEST_BUILD_DIR, 'runners')
|
RUNNERS_DIR = File.join(TEST_BUILD_DIR, 'runners')
|
||||||
MOCKS_DIR = File.join(TEST_BUILD_DIR, 'mocks')
|
MOCKS_DIR = File.join(TEST_BUILD_DIR, 'mocks')
|
||||||
TEST_BIN_DIR = TEST_BUILD_DIR
|
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', '')
|
MOCK_SUFFIX = ENV.fetch('TEST_MOCK_SUFFIX', '')
|
||||||
TEST_MAKEFILE = ENV.fetch('TEST_MAKEFILE', File.join(TEST_BUILD_DIR, 'MakefileTestSupport'))
|
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}/
|
MOCK_MATCHER = /#{MOCK_PREFIX}[A-Za-z_][A-Za-z0-9_\-.]+#{MOCK_SUFFIX}/
|
||||||
|
|||||||
+23
-9
@@ -27,8 +27,8 @@ SYSTEM_TEST_SUPPORT_DIRS.each do |dir|
|
|||||||
CLOBBER.include(dir)
|
CLOBBER.include(dir)
|
||||||
end
|
end
|
||||||
|
|
||||||
$config_file = DEFAULT_CONFIG_FILE
|
$cmock_test_config_file = DEFAULT_CONFIG_FILE
|
||||||
$overlay_file = nil
|
$cmock_test_overlay_file = nil
|
||||||
|
|
||||||
task :prep_system_tests => SYSTEM_TEST_SUPPORT_DIRS
|
task :prep_system_tests => SYSTEM_TEST_SUPPORT_DIRS
|
||||||
task :default => [:test]
|
task :default => [:test]
|
||||||
@@ -37,12 +37,12 @@ task :cruise => :ci
|
|||||||
|
|
||||||
desc "Load configuration"
|
desc "Load configuration"
|
||||||
task :config, [:config_file, :cmock_overlay] do |t, args|
|
task :config, [:config_file, :cmock_overlay] do |t, args|
|
||||||
$config_file = args[:config_file]
|
$cmock_test_config_file = args[:config_file]
|
||||||
$overlay_file = args[:cmock_overlay]
|
$cmock_test_overlay_file = args[:cmock_overlay]
|
||||||
end
|
end
|
||||||
|
|
||||||
task :config_toolchains do
|
task :config_toolchains do
|
||||||
configure_toolchain($config_file, $overlay_file)
|
configure_toolchain($cmock_test_config_file, $cmock_test_overlay_file)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Still support testing everything with just 'test' but switch default to ceedling-like test:all
|
# 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"
|
desc "Run System Tests"
|
||||||
task :system => [:config_toolchains, :clobber, :prep_system_tests] do
|
task :system => [:config_toolchains, :clobber, :prep_system_tests] do
|
||||||
#get a list of all system tests, removing unsupported tests for this compiler
|
# Get a list of all system tests, removing unsupported tests for this toolchain
|
||||||
sys_unsupported = unsupported_tests.map {|a| 'system/test_interactions/'+a+'.yml'}
|
# 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
|
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
|
compile_tests_to_run = FileList[SYSTEST_COMPILE_MOCKABLES_PATH + '*.h'] - compile_unsupported
|
||||||
unless (sys_unsupported.empty? and compile_unsupported.empty?)
|
unless (sys_unsupported.empty? and compile_unsupported.empty?)
|
||||||
report "\nIgnoring these system tests..."
|
report "\nIgnoring these system tests..."
|
||||||
@@ -93,7 +107,7 @@ namespace :test do
|
|||||||
|
|
||||||
desc "Test cmock examples"
|
desc "Test cmock examples"
|
||||||
task :examples => [:config_toolchains, :prep_system_tests] do
|
task :examples => [:config_toolchains, :prep_system_tests] do
|
||||||
run_examples(true)
|
run_examples()
|
||||||
end
|
end
|
||||||
|
|
||||||
#individual system tests
|
#individual system tests
|
||||||
|
|||||||
+20
-8
@@ -147,7 +147,7 @@ module RakefileHelpers
|
|||||||
# Returns the unsupported test list, regardless of whether it came from
|
# Returns the unsupported test list, regardless of whether it came from
|
||||||
# a CMock overlay or a CMock-only target file.
|
# a CMock overlay or a CMock-only target file.
|
||||||
def unsupported_tests
|
def unsupported_tests
|
||||||
$cmock_cfg[:unsupported] || $unity_cfg[:unsupported] || []
|
($cmock_cfg[:unsupported] || []) | ($unity_cfg[:unsupported] || [])
|
||||||
end
|
end
|
||||||
|
|
||||||
# Resolve argument template tokens and produce a flat argument string.
|
# Resolve argument template tokens and produce a flat argument string.
|
||||||
@@ -229,6 +229,7 @@ module RakefileHelpers
|
|||||||
end
|
end
|
||||||
|
|
||||||
def execute(command_string, verbose=true, raise_on_failure=true)
|
def execute(command_string, verbose=true, raise_on_failure=true)
|
||||||
|
report(command_string) if verbose
|
||||||
output = `#{command_string}`.chomp
|
output = `#{command_string}`.chomp
|
||||||
report(output) if (verbose && !output.nil? && (output.length > 0))
|
report(output) if (verbose && !output.nil? && (output.length > 0))
|
||||||
if ($?.exitstatus != 0) and (raise_on_failure)
|
if ($?.exitstatus != 0) and (raise_on_failure)
|
||||||
@@ -521,7 +522,7 @@ module RakefileHelpers
|
|||||||
raise "C unit tests failed." if result =~ /FAILED/
|
raise "C unit tests failed." if result =~ /FAILED/
|
||||||
end
|
end
|
||||||
|
|
||||||
def run_examples(verbose=false, raise_on_failure=true)
|
def run_examples()
|
||||||
report "\n"
|
report "\n"
|
||||||
report "-----------------\n"
|
report "-----------------\n"
|
||||||
report "VALIDATE EXAMPLES\n"
|
report "VALIDATE EXAMPLES\n"
|
||||||
@@ -529,11 +530,20 @@ module RakefileHelpers
|
|||||||
total_tests = 0
|
total_tests = 0
|
||||||
total_failures = 0
|
total_failures = 0
|
||||||
total_ignored = 0
|
total_ignored = 0
|
||||||
[ "cd #{File.join("..", "examples", "make_example")} && make clean && make setup && make test",
|
puts "DEBUG DIS #{$cmock_test_config_file}"
|
||||||
"cd #{File.join("..", "examples", "temp_sensor")} && rake ci"
|
cfg_file = "#{($cmock_test_config_file =~ /[\\\/]/) ? '../' : ''}#{$cmock_test_config_file}"
|
||||||
].each do |cmd|
|
|
||||||
report "Testing '#{cmd}'"
|
# Determine which examples are valid for this platform
|
||||||
execute(cmd, verbose, false).each_line do |line|
|
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/
|
if line =~ /(\d+) TOTAL TESTS (\d+) TOTAL FAILURES (\d+) IGNORED/
|
||||||
total_tests += Regexp.last_match(1).to_i
|
total_tests += Regexp.last_match(1).to_i
|
||||||
total_failures += Regexp.last_match(2).to_i
|
total_failures += Regexp.last_match(2).to_i
|
||||||
@@ -541,10 +551,12 @@ module RakefileHelpers
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Report the results from the examples
|
||||||
result = "#{total_tests} Tests #{total_failures} Failures #{total_ignored} Ignored\n"
|
result = "#{total_tests} Tests #{total_failures} Failures #{total_ignored} Ignored\n"
|
||||||
result += total_failures > 0 ? "FAILED\n" : "OK\n"
|
result += total_failures > 0 ? "FAILED\n" : "OK\n"
|
||||||
save_test_results('examples', result)
|
save_test_results('examples', result)
|
||||||
raise "Examples failed." if total_failures > 0 && raise_on_failure
|
raise "Examples failed." if total_failures > 0
|
||||||
end
|
end
|
||||||
|
|
||||||
def fail_out(msg)
|
def fail_out(msg)
|
||||||
|
|||||||
Vendored
+1
-1
Submodule vendor/unity updated: 444fbda72a...bbf8f3728a
Reference in New Issue
Block a user