From bfdfe944b9bbb2f76243fbe03ac6d62d5630de97 Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Fri, 7 Apr 2017 22:22:38 -0400 Subject: [PATCH] Add examples to the automated testing in travis. Make err-on-fail optional on both examples (disabled during ci) --- .travis.yml | 2 ++ examples/make_example/Makefile | 4 ++-- examples/temp_sensor/gcc.yml | 9 +++++---- examples/temp_sensor/iar_v4.yml | 9 +++++---- examples/temp_sensor/iar_v5.yml | 9 +++++---- examples/temp_sensor/rakefile.rb | 12 +++++++++++- examples/temp_sensor/rakefile_helper.rb | 22 ++++++++++++---------- scripts/create_makefile.rb | 6 ++++-- scripts/test_summary.rb | 7 +++++-- test/rakefile_helper.rb | 4 ++-- 10 files changed, 53 insertions(+), 31 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9b7fd4c..e71d861 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,3 +19,5 @@ install: script: - cd test && rake ci + - cd examples && cd make_example && make clean && make setup && make test + - cd examples && cd temp_sensor && rake ci diff --git a/examples/make_example/Makefile b/examples/make_example/Makefile index 56385ae..8a2f403 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 + ruby ../../scripts/create_makefile.rb --silent clean: rm -rf ${BUILD_DIR} @@ -23,7 +23,7 @@ ${BUILD_DIR}/main: ${SRC_DIR}/main.c ${SRC_DIR}/foo.c ${CC} $< -o $@ run: - ./build/main + ./build/main || true test: setup diff --git a/examples/temp_sensor/gcc.yml b/examples/temp_sensor/gcc.yml index 081cfa0..f41bf07 100644 --- a/examples/temp_sensor/gcc.yml +++ b/examples/temp_sensor/gcc.yml @@ -9,10 +9,10 @@ compiler: prefix: '-I' items: - 'src/' - - '../src/' - - '../vendor/unity/src/' - - '../vendor/unity/examples/example_3/helper/' - - 'mocks/' + - '../../src/' + - '../../vendor/unity/src/' + - '../../vendor/unity/examples/example_3/helper/' + - './build/mocks/' - *unit_tests_path defines: prefix: '-D' @@ -39,5 +39,6 @@ linker: :plugins: [] :includes: - Types.h + :mock_path: ./build/mocks colour: true diff --git a/examples/temp_sensor/iar_v4.yml b/examples/temp_sensor/iar_v4.yml index 79f00b7..7621752 100644 --- a/examples/temp_sensor/iar_v4.yml +++ b/examples/temp_sensor/iar_v4.yml @@ -30,10 +30,10 @@ compiler: prefix: '-I' items: - 'src/' - - '../src/' - - '../vendor/unity/src/' - - '../vendor/unity/examples/example_3/helper/' - - 'mocks/' + - '../../src/' + - '../../vendor/unity/src/' + - '../../vendor/unity/examples/example_3/helper/' + - './build/mocks/' - [*tools_root, 'arm\inc\'] - *unit_tests_path defines: @@ -88,4 +88,5 @@ simulator: :plugins: [] :includes: - Types.h + :mock_path: ./build/mocks diff --git a/examples/temp_sensor/iar_v5.yml b/examples/temp_sensor/iar_v5.yml index a1fe3cb..0178649 100644 --- a/examples/temp_sensor/iar_v5.yml +++ b/examples/temp_sensor/iar_v5.yml @@ -29,10 +29,10 @@ compiler: prefix: '-I' items: - 'src/' - - '../src/' - - '../vendor/unity/src/' - - '../vendor/unity/examples/example_3/helper/' - - 'mocks/' + - '../../src/' + - '../../vendor/unity/src/' + - '../../vendor/unity/examples/example_3/helper/' + - './build/mocks/' - [*tools_root, 'arm\inc\'] - *unit_tests_path defines: @@ -77,4 +77,5 @@ simulator: :plugins: [] :includes: - Types.h + :mock_path: ./build/mocks diff --git a/examples/temp_sensor/rakefile.rb b/examples/temp_sensor/rakefile.rb index 0c6a7ca..c902828 100644 --- a/examples/temp_sensor/rakefile.rb +++ b/examples/temp_sensor/rakefile.rb @@ -7,6 +7,11 @@ require './rakefile_helper' include RakefileHelpers +REQUIRED_DIRS = [ './build', './build/mocks' ] +REQUIRED_DIRS.each do |v| + directory v +end + # Load default configuration, for now DEFAULT_CONFIG_FILE = 'gcc.yml' configure_toolchain(DEFAULT_CONFIG_FILE) @@ -22,7 +27,7 @@ end desc "Build and test Unity" task :all => [:clean, :unit, :summary] -task :default => [:clobber, :all] +task :default => REQUIRED_DIRS + [:clobber, :all] task :ci => [:default] task :cruise => [:default] @@ -30,3 +35,8 @@ desc "Load configuration" task :config, :config_file do |t, args| configure_toolchain(args[:config_file]) end + +desc "Return error on Failures" +task :strict do + $return_error_on_failures = true +end diff --git a/examples/temp_sensor/rakefile_helper.rb b/examples/temp_sensor/rakefile_helper.rb index 7874251..a442622 100644 --- a/examples/temp_sensor/rakefile_helper.rb +++ b/examples/temp_sensor/rakefile_helper.rb @@ -1,11 +1,13 @@ require 'yaml' require 'fileutils' -require '../vendor/unity/auto/unity_test_summary' -require '../vendor/unity/auto/generate_test_runner' -require '../vendor/unity/auto/colour_reporter' +require '../../vendor/unity/auto/unity_test_summary' +require '../../vendor/unity/auto/generate_test_runner' +require '../../vendor/unity/auto/colour_reporter' module RakefileHelpers + $return_error_on_failures = false + C_EXTENSION = '.c' def load_configuration(config_file) @@ -145,11 +147,11 @@ module RakefileHelpers return {:command => command, :pre_support => pre_support, :post_support => post_support} end - def execute(command_string, verbose=true) + def execute(command_string, verbose=true, ok_to_fail=false) report command_string output = `#{command_string}`.chomp report(output) if (verbose && !output.nil? && (output.length > 0)) - if $?.exitstatus != 0 + unless $?.exitstatus.zero? || ok_to_fail raise "Command failed. (Returned #{$?.exitstatus})" end return output @@ -157,13 +159,13 @@ module RakefileHelpers def report_summary summary = UnityTestSummary.new - summary.set_root_path(HERE) + summary.root = HERE results_glob = "#{$cfg['compiler']['build_path']}*.test*" results_glob.gsub!(/\\/, '/') results = Dir[results_glob] - summary.set_targets(results) + summary.targets = results report summary.run - raise "There were failures" if (summary.failures > 0) + raise "There were failures" if (summary.failures > 0) && $return_error_on_failures end def run_tests(test_files) @@ -188,7 +190,7 @@ module RakefileHelpers #create mocks if needed if (header =~ /Mock/) - require "../lib/cmock.rb" + require "../../lib/cmock.rb" @cmock ||= CMock.new($cfg_file) @cmock.setup_mocks([$cfg['compiler']['source_path']+header.gsub('Mock','')]) end @@ -231,7 +233,7 @@ module RakefileHelpers else cmd_str = "#{simulator[:command]} #{simulator[:pre_support]} #{executable} #{simulator[:post_support]}" end - output = execute(cmd_str) + output = execute(cmd_str, true, true) test_results = $cfg['compiler']['build_path'] + test_base if output.match(/OK$/m).nil? test_results += '.testfail' diff --git a/scripts/create_makefile.rb b/scripts/create_makefile.rb index e6dbdd3..3080aa5 100644 --- a/scripts/create_makefile.rb +++ b/scripts/create_makefile.rb @@ -27,6 +27,8 @@ end all_headers_to_mock = [] +suppress_error = !ARGV.nil? && !ARGV.empty? && (ARGV[0].upcase == "--SILENT") + File.open(TEST_MAKEFILE, "w") do |mkfile| # Define make variables @@ -103,7 +105,7 @@ File.open(TEST_MAKEFILE, "w") do |mkfile| end end raise "Module header '#{name}' not found to mock!" unless header_to_mock - headers_to_mock << header_to_mock + headers_to_mock << header_to_mock end all_headers_to_mock += headers_to_mock mock_objs = headers_to_mock.map do |hdr| @@ -149,7 +151,7 @@ File.open(TEST_MAKEFILE, "w") do |mkfile| # Create test summary task mkfile.puts "test_summary:" - mkfile.puts "\t@UNITY_DIR=${UNITY_DIR} ruby ${CMOCK_DIR}/scripts/test_summary.rb" + mkfile.puts "\t@UNITY_DIR=${UNITY_DIR} ruby ${CMOCK_DIR}/scripts/test_summary.rb #{suppress_error ? '--silent' : ''}" mkfile.puts "" mkfile.puts ".PHONY: test_summary" mkfile.puts "" diff --git a/scripts/test_summary.rb b/scripts/test_summary.rb index 6192263..60bf07f 100644 --- a/scripts/test_summary.rb +++ b/scripts/test_summary.rb @@ -1,3 +1,6 @@ + +suppress_error = !ARGV.nil? && !ARGV.empty? && (ARGV[0].upcase == "--SILENT") + require "#{ENV['UNITY_DIR']}/auto/unity_test_summary.rb" build_dir = ENV.fetch('BUILD_DIR', './build') @@ -5,7 +8,7 @@ test_build_dir = ENV.fetch('TEST_BUILD_DIR', File.join(build_dir, 'test')) results = Dir["#{test_build_dir}/*.result"] parser = UnityTestSummary.new -parser.set_targets(results) +parser.targets = results parser.run puts parser.report -exit(parser.failures) +exit(parser.failures) unless suppress_error diff --git a/test/rakefile_helper.rb b/test/rakefile_helper.rb index 583d1cc..b00ab20 100644 --- a/test/rakefile_helper.rb +++ b/test/rakefile_helper.rb @@ -162,11 +162,11 @@ module RakefileHelpers def report_summary summary = UnityTestSummary.new - summary.set_root_path(File.expand_path(File.dirname(__FILE__)) + '/') + summary.root = File.expand_path(File.dirname(__FILE__)) + '/' results_glob = "#{$cfg['compiler']['build_path']}*.test*" results_glob.gsub!(/\\/, '/') results = Dir[results_glob] - summary.set_targets(results) + summary.targets = results summary.run fail_out "FAIL: There were failures" if (summary.failures > 0) end