FRDM K64F Metronome

Committer:
ram54288
Date:
Sun May 14 18:37:05 2017 +0000
Revision:
0:dbad57390bd1
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ram54288 0:dbad57390bd1 1 # ==========================================
ram54288 0:dbad57390bd1 2 # Unity Project - A Test Framework for C
ram54288 0:dbad57390bd1 3 # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
ram54288 0:dbad57390bd1 4 # [Released under MIT License. Please refer to license.txt for details]
ram54288 0:dbad57390bd1 5 # ==========================================
ram54288 0:dbad57390bd1 6
ram54288 0:dbad57390bd1 7 #!/usr/bin/ruby
ram54288 0:dbad57390bd1 8 #
ram54288 0:dbad57390bd1 9 # unity_test_summary.rb
ram54288 0:dbad57390bd1 10 #
ram54288 0:dbad57390bd1 11 require 'fileutils'
ram54288 0:dbad57390bd1 12 require 'set'
ram54288 0:dbad57390bd1 13
ram54288 0:dbad57390bd1 14 class UnityTestSummary
ram54288 0:dbad57390bd1 15 include FileUtils::Verbose
ram54288 0:dbad57390bd1 16
ram54288 0:dbad57390bd1 17 attr_reader :report, :total_tests, :failures, :ignored
ram54288 0:dbad57390bd1 18
ram54288 0:dbad57390bd1 19 def initialize(opts = {})
ram54288 0:dbad57390bd1 20 @report = ''
ram54288 0:dbad57390bd1 21 @total_tests = 0
ram54288 0:dbad57390bd1 22 @failures = 0
ram54288 0:dbad57390bd1 23 @ignored = 0
ram54288 0:dbad57390bd1 24
ram54288 0:dbad57390bd1 25
ram54288 0:dbad57390bd1 26 end
ram54288 0:dbad57390bd1 27
ram54288 0:dbad57390bd1 28 def run
ram54288 0:dbad57390bd1 29 # Clean up result file names
ram54288 0:dbad57390bd1 30 results = @targets.map {|target| target.gsub(/\\/,'/')}
ram54288 0:dbad57390bd1 31
ram54288 0:dbad57390bd1 32 # Dig through each result file, looking for details on pass/fail:
ram54288 0:dbad57390bd1 33 failure_output = []
ram54288 0:dbad57390bd1 34 ignore_output = []
ram54288 0:dbad57390bd1 35
ram54288 0:dbad57390bd1 36 results.each do |result_file|
ram54288 0:dbad57390bd1 37 lines = File.readlines(result_file).map { |line| line.chomp }
ram54288 0:dbad57390bd1 38 if lines.length == 0
ram54288 0:dbad57390bd1 39 raise "Empty test result file: #{result_file}"
ram54288 0:dbad57390bd1 40 else
ram54288 0:dbad57390bd1 41 output = get_details(result_file, lines)
ram54288 0:dbad57390bd1 42 failure_output << output[:failures] unless output[:failures].empty?
ram54288 0:dbad57390bd1 43 ignore_output << output[:ignores] unless output[:ignores].empty?
ram54288 0:dbad57390bd1 44 tests,failures,ignored = parse_test_summary(lines)
ram54288 0:dbad57390bd1 45 @total_tests += tests
ram54288 0:dbad57390bd1 46 @failures += failures
ram54288 0:dbad57390bd1 47 @ignored += ignored
ram54288 0:dbad57390bd1 48 end
ram54288 0:dbad57390bd1 49 end
ram54288 0:dbad57390bd1 50
ram54288 0:dbad57390bd1 51 if @ignored > 0
ram54288 0:dbad57390bd1 52 @report += "\n"
ram54288 0:dbad57390bd1 53 @report += "--------------------------\n"
ram54288 0:dbad57390bd1 54 @report += "UNITY IGNORED TEST SUMMARY\n"
ram54288 0:dbad57390bd1 55 @report += "--------------------------\n"
ram54288 0:dbad57390bd1 56 @report += ignore_output.flatten.join("\n")
ram54288 0:dbad57390bd1 57 end
ram54288 0:dbad57390bd1 58
ram54288 0:dbad57390bd1 59 if @failures > 0
ram54288 0:dbad57390bd1 60 @report += "\n"
ram54288 0:dbad57390bd1 61 @report += "--------------------------\n"
ram54288 0:dbad57390bd1 62 @report += "UNITY FAILED TEST SUMMARY\n"
ram54288 0:dbad57390bd1 63 @report += "--------------------------\n"
ram54288 0:dbad57390bd1 64 @report += failure_output.flatten.join("\n")
ram54288 0:dbad57390bd1 65 end
ram54288 0:dbad57390bd1 66
ram54288 0:dbad57390bd1 67 @report += "\n"
ram54288 0:dbad57390bd1 68 @report += "--------------------------\n"
ram54288 0:dbad57390bd1 69 @report += "OVERALL UNITY TEST SUMMARY\n"
ram54288 0:dbad57390bd1 70 @report += "--------------------------\n"
ram54288 0:dbad57390bd1 71 @report += "#{@total_tests} TOTAL TESTS #{@failures} TOTAL FAILURES #{@ignored} IGNORED\n"
ram54288 0:dbad57390bd1 72 @report += "\n"
ram54288 0:dbad57390bd1 73 end
ram54288 0:dbad57390bd1 74
ram54288 0:dbad57390bd1 75 def set_targets(target_array)
ram54288 0:dbad57390bd1 76 @targets = target_array
ram54288 0:dbad57390bd1 77 end
ram54288 0:dbad57390bd1 78
ram54288 0:dbad57390bd1 79 def set_root_path(path)
ram54288 0:dbad57390bd1 80 @root = path
ram54288 0:dbad57390bd1 81 end
ram54288 0:dbad57390bd1 82
ram54288 0:dbad57390bd1 83 def usage(err_msg=nil)
ram54288 0:dbad57390bd1 84 puts "\nERROR: "
ram54288 0:dbad57390bd1 85 puts err_msg if err_msg
ram54288 0:dbad57390bd1 86 puts "\nUsage: unity_test_summary.rb result_file_directory/ root_path/"
ram54288 0:dbad57390bd1 87 puts " result_file_directory - The location of your results files."
ram54288 0:dbad57390bd1 88 puts " Defaults to current directory if not specified."
ram54288 0:dbad57390bd1 89 puts " Should end in / if specified."
ram54288 0:dbad57390bd1 90 puts " root_path - Helpful for producing more verbose output if using relative paths."
ram54288 0:dbad57390bd1 91 exit 1
ram54288 0:dbad57390bd1 92 end
ram54288 0:dbad57390bd1 93
ram54288 0:dbad57390bd1 94 protected
ram54288 0:dbad57390bd1 95
ram54288 0:dbad57390bd1 96 def get_details(result_file, lines)
ram54288 0:dbad57390bd1 97 results = { :failures => [], :ignores => [], :successes => [] }
ram54288 0:dbad57390bd1 98 lines.each do |line|
ram54288 0:dbad57390bd1 99 src_file,src_line,test_name,status,msg = line.split(/:/)
ram54288 0:dbad57390bd1 100 line_out = ((@root && (@root != 0)) ? "#{@root}#{line}" : line ).gsub(/\//, "\\")
ram54288 0:dbad57390bd1 101 case(status)
ram54288 0:dbad57390bd1 102 when 'IGNORE' then results[:ignores] << line_out
ram54288 0:dbad57390bd1 103 when 'FAIL' then results[:failures] << line_out
ram54288 0:dbad57390bd1 104 when 'PASS' then results[:successes] << line_out
ram54288 0:dbad57390bd1 105 end
ram54288 0:dbad57390bd1 106 end
ram54288 0:dbad57390bd1 107 return results
ram54288 0:dbad57390bd1 108 end
ram54288 0:dbad57390bd1 109
ram54288 0:dbad57390bd1 110 def parse_test_summary(summary)
ram54288 0:dbad57390bd1 111 if summary.find { |v| v =~ /(\d+) Tests (\d+) Failures (\d+) Ignored/ }
ram54288 0:dbad57390bd1 112 [$1.to_i,$2.to_i,$3.to_i]
ram54288 0:dbad57390bd1 113 else
ram54288 0:dbad57390bd1 114 raise "Couldn't parse test results: #{summary}"
ram54288 0:dbad57390bd1 115 end
ram54288 0:dbad57390bd1 116 end
ram54288 0:dbad57390bd1 117
ram54288 0:dbad57390bd1 118 def here; File.expand_path(File.dirname(__FILE__)); end
ram54288 0:dbad57390bd1 119
ram54288 0:dbad57390bd1 120 end
ram54288 0:dbad57390bd1 121
ram54288 0:dbad57390bd1 122 if $0 == __FILE__
ram54288 0:dbad57390bd1 123
ram54288 0:dbad57390bd1 124 #parse out the command options
ram54288 0:dbad57390bd1 125 opts, args = ARGV.partition {|v| v =~ /^--\w+/}
ram54288 0:dbad57390bd1 126 opts.map! {|v| v[2..-1].to_sym }
ram54288 0:dbad57390bd1 127
ram54288 0:dbad57390bd1 128 #create an instance to work with
ram54288 0:dbad57390bd1 129 uts = UnityTestSummary.new(opts)
ram54288 0:dbad57390bd1 130
ram54288 0:dbad57390bd1 131 begin
ram54288 0:dbad57390bd1 132 #look in the specified or current directory for result files
ram54288 0:dbad57390bd1 133 args[0] ||= './'
ram54288 0:dbad57390bd1 134 targets = "#{ARGV[0].gsub(/\\/, '/')}**/*.test*"
ram54288 0:dbad57390bd1 135 results = Dir[targets]
ram54288 0:dbad57390bd1 136 raise "No *.testpass, *.testfail, or *.testresults files found in '#{targets}'" if results.empty?
ram54288 0:dbad57390bd1 137 uts.set_targets(results)
ram54288 0:dbad57390bd1 138
ram54288 0:dbad57390bd1 139 #set the root path
ram54288 0:dbad57390bd1 140 args[1] ||= Dir.pwd + '/'
ram54288 0:dbad57390bd1 141 uts.set_root_path(ARGV[1])
ram54288 0:dbad57390bd1 142
ram54288 0:dbad57390bd1 143 #run the summarizer
ram54288 0:dbad57390bd1 144 puts uts.run
ram54288 0:dbad57390bd1 145 rescue Exception => e
ram54288 0:dbad57390bd1 146 uts.usage e.message
ram54288 0:dbad57390bd1 147 end
ram54288 0:dbad57390bd1 148 end