FRDM K64F Metronome

Committer:
ram54288
Date:
Sun May 14 18:35:07 2017 +0000
Revision:
0:a2cb7295a1f7
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ram54288 0:a2cb7295a1f7 1 #============================================================
ram54288 0:a2cb7295a1f7 2 # Author: John Theofanopoulos
ram54288 0:a2cb7295a1f7 3 # A simple parser. Takes the output files generated during the build process and
ram54288 0:a2cb7295a1f7 4 # extracts information relating to the tests.
ram54288 0:a2cb7295a1f7 5 #
ram54288 0:a2cb7295a1f7 6 # Notes:
ram54288 0:a2cb7295a1f7 7 # To capture an output file under VS builds use the following:
ram54288 0:a2cb7295a1f7 8 # devenv [build instructions] > Output.txt & type Output.txt
ram54288 0:a2cb7295a1f7 9 #
ram54288 0:a2cb7295a1f7 10 # To capture an output file under GCC/Linux builds use the following:
ram54288 0:a2cb7295a1f7 11 # make | tee Output.txt
ram54288 0:a2cb7295a1f7 12 #
ram54288 0:a2cb7295a1f7 13 # To use this parser use the following command
ram54288 0:a2cb7295a1f7 14 # ruby parseOutput.rb [options] [file]
ram54288 0:a2cb7295a1f7 15 # options: -xml : produce a JUnit compatible XML file
ram54288 0:a2cb7295a1f7 16 # file : file to scan for results
ram54288 0:a2cb7295a1f7 17 #============================================================
ram54288 0:a2cb7295a1f7 18
ram54288 0:a2cb7295a1f7 19
ram54288 0:a2cb7295a1f7 20 class ParseOutput
ram54288 0:a2cb7295a1f7 21 # The following flag is set to true when a test is found or false otherwise.
ram54288 0:a2cb7295a1f7 22 @testFlag
ram54288 0:a2cb7295a1f7 23 @xmlOut
ram54288 0:a2cb7295a1f7 24 @arrayList
ram54288 0:a2cb7295a1f7 25 @totalTests
ram54288 0:a2cb7295a1f7 26 @classIndex
ram54288 0:a2cb7295a1f7 27
ram54288 0:a2cb7295a1f7 28 # Set the flag to indicate if there will be an XML output file or not
ram54288 0:a2cb7295a1f7 29 def setXmlOutput()
ram54288 0:a2cb7295a1f7 30 @xmlOut = true
ram54288 0:a2cb7295a1f7 31 end
ram54288 0:a2cb7295a1f7 32
ram54288 0:a2cb7295a1f7 33 # if write our output to XML
ram54288 0:a2cb7295a1f7 34 def writeXmlOuput()
ram54288 0:a2cb7295a1f7 35 output = File.open("report.xml", "w")
ram54288 0:a2cb7295a1f7 36 output << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
ram54288 0:a2cb7295a1f7 37 @arrayList.each do |item|
ram54288 0:a2cb7295a1f7 38 output << item << "\n"
ram54288 0:a2cb7295a1f7 39 end
ram54288 0:a2cb7295a1f7 40 output << "</testsuite>\n"
ram54288 0:a2cb7295a1f7 41 end
ram54288 0:a2cb7295a1f7 42
ram54288 0:a2cb7295a1f7 43 # This function will try and determine when the suite is changed. This is
ram54288 0:a2cb7295a1f7 44 # is the name that gets added to the classname parameter.
ram54288 0:a2cb7295a1f7 45 def testSuiteVerify(testSuiteName)
ram54288 0:a2cb7295a1f7 46 if @testFlag == false
ram54288 0:a2cb7295a1f7 47 @testFlag = true;
ram54288 0:a2cb7295a1f7 48 # Split the path name
ram54288 0:a2cb7295a1f7 49 testName = testSuiteName.split("/")
ram54288 0:a2cb7295a1f7 50 # Remove the extension
ram54288 0:a2cb7295a1f7 51 baseName = testName[testName.size - 1].split(".")
ram54288 0:a2cb7295a1f7 52 @testSuite = "test." + baseName[0]
ram54288 0:a2cb7295a1f7 53 printf "New Test: %s\n", @testSuite
ram54288 0:a2cb7295a1f7 54 end
ram54288 0:a2cb7295a1f7 55 end
ram54288 0:a2cb7295a1f7 56
ram54288 0:a2cb7295a1f7 57
ram54288 0:a2cb7295a1f7 58 # Test was flagged as having passed so format the output
ram54288 0:a2cb7295a1f7 59 def testPassed(array)
ram54288 0:a2cb7295a1f7 60 lastItem = array.length - 1
ram54288 0:a2cb7295a1f7 61 testName = array[lastItem - 1]
ram54288 0:a2cb7295a1f7 62 testSuiteVerify(array[@className])
ram54288 0:a2cb7295a1f7 63 printf "%-40s PASS\n", testName
ram54288 0:a2cb7295a1f7 64 if @xmlOut == true
ram54288 0:a2cb7295a1f7 65 @arrayList.push " <testcase classname=\"" + @testSuite + "\" name=\"" + testName + "\"/>"
ram54288 0:a2cb7295a1f7 66 end
ram54288 0:a2cb7295a1f7 67 end
ram54288 0:a2cb7295a1f7 68
ram54288 0:a2cb7295a1f7 69 # Test was flagged as being ingored so format the output
ram54288 0:a2cb7295a1f7 70 def testIgnored(array)
ram54288 0:a2cb7295a1f7 71 lastItem = array.length - 1
ram54288 0:a2cb7295a1f7 72 testName = array[lastItem - 2]
ram54288 0:a2cb7295a1f7 73 reason = array[lastItem].chomp
ram54288 0:a2cb7295a1f7 74 testSuiteVerify(array[@className])
ram54288 0:a2cb7295a1f7 75 printf "%-40s IGNORED\n", testName
ram54288 0:a2cb7295a1f7 76 if @xmlOut == true
ram54288 0:a2cb7295a1f7 77 @arrayList.push " <testcase classname=\"" + @testSuite + "\" name=\"" + testName + "\">"
ram54288 0:a2cb7295a1f7 78 @arrayList.push " <skipped type=\"TEST IGNORED\"> " + reason + " </skipped>"
ram54288 0:a2cb7295a1f7 79 @arrayList.push " </testcase>"
ram54288 0:a2cb7295a1f7 80 end
ram54288 0:a2cb7295a1f7 81 end
ram54288 0:a2cb7295a1f7 82
ram54288 0:a2cb7295a1f7 83 # Test was flagged as having failed so format the line
ram54288 0:a2cb7295a1f7 84 def testFailed(array)
ram54288 0:a2cb7295a1f7 85 lastItem = array.length - 1
ram54288 0:a2cb7295a1f7 86 testName = array[lastItem - 2]
ram54288 0:a2cb7295a1f7 87 reason = array[lastItem].chomp + " at line: " + array[lastItem - 3]
ram54288 0:a2cb7295a1f7 88 testSuiteVerify(array[@className])
ram54288 0:a2cb7295a1f7 89 printf "%-40s FAILED\n", testName
ram54288 0:a2cb7295a1f7 90 if @xmlOut == true
ram54288 0:a2cb7295a1f7 91 @arrayList.push " <testcase classname=\"" + @testSuite + "\" name=\"" + testName + "\">"
ram54288 0:a2cb7295a1f7 92 @arrayList.push " <failure type=\"ASSERT FAILED\"> " + reason + " </failure>"
ram54288 0:a2cb7295a1f7 93 @arrayList.push " </testcase>"
ram54288 0:a2cb7295a1f7 94 end
ram54288 0:a2cb7295a1f7 95 end
ram54288 0:a2cb7295a1f7 96
ram54288 0:a2cb7295a1f7 97
ram54288 0:a2cb7295a1f7 98 # Figure out what OS we are running on. For now we are assuming if it's not Windows it must
ram54288 0:a2cb7295a1f7 99 # be Unix based.
ram54288 0:a2cb7295a1f7 100 def detectOS()
ram54288 0:a2cb7295a1f7 101 myOS = RUBY_PLATFORM.split("-")
ram54288 0:a2cb7295a1f7 102 if myOS.size == 2
ram54288 0:a2cb7295a1f7 103 if myOS[1] == "mingw32"
ram54288 0:a2cb7295a1f7 104 @className = 1
ram54288 0:a2cb7295a1f7 105 else
ram54288 0:a2cb7295a1f7 106 @className = 0
ram54288 0:a2cb7295a1f7 107 end
ram54288 0:a2cb7295a1f7 108 else
ram54288 0:a2cb7295a1f7 109 @className = 0
ram54288 0:a2cb7295a1f7 110 end
ram54288 0:a2cb7295a1f7 111
ram54288 0:a2cb7295a1f7 112 end
ram54288 0:a2cb7295a1f7 113
ram54288 0:a2cb7295a1f7 114 # Main function used to parse the file that was captured.
ram54288 0:a2cb7295a1f7 115 def process(name)
ram54288 0:a2cb7295a1f7 116 @testFlag = false
ram54288 0:a2cb7295a1f7 117 @arrayList = Array.new
ram54288 0:a2cb7295a1f7 118
ram54288 0:a2cb7295a1f7 119 detectOS()
ram54288 0:a2cb7295a1f7 120
ram54288 0:a2cb7295a1f7 121 puts "Parsing file: " + name
ram54288 0:a2cb7295a1f7 122
ram54288 0:a2cb7295a1f7 123
ram54288 0:a2cb7295a1f7 124 testPass = 0
ram54288 0:a2cb7295a1f7 125 testFail = 0
ram54288 0:a2cb7295a1f7 126 testIgnore = 0
ram54288 0:a2cb7295a1f7 127 puts ""
ram54288 0:a2cb7295a1f7 128 puts "=================== RESULTS ====================="
ram54288 0:a2cb7295a1f7 129 puts ""
ram54288 0:a2cb7295a1f7 130 File.open(name).each do |line|
ram54288 0:a2cb7295a1f7 131 # Typical test lines look like this:
ram54288 0:a2cb7295a1f7 132 # <path>/<test_file>.c:36:test_tc1000_opsys:FAIL: Expected 1 Was 0
ram54288 0:a2cb7295a1f7 133 # <path>/<test_file>.c:112:test_tc5004_initCanChannel:IGNORE: Not Yet Implemented
ram54288 0:a2cb7295a1f7 134 # <path>/<test_file>.c:115:test_tc5100_initCanVoidPtrs:PASS
ram54288 0:a2cb7295a1f7 135 #
ram54288 0:a2cb7295a1f7 136 # where path is different on Unix vs Windows devices (Windows leads with a drive letter)
ram54288 0:a2cb7295a1f7 137 lineArray = line.split(":")
ram54288 0:a2cb7295a1f7 138 lineSize = lineArray.size
ram54288 0:a2cb7295a1f7 139 # If we were able to split the line then we can look to see if any of our target words
ram54288 0:a2cb7295a1f7 140 # were found. Case is important.
ram54288 0:a2cb7295a1f7 141 if lineSize >= 4
ram54288 0:a2cb7295a1f7 142 # Determine if this test passed
ram54288 0:a2cb7295a1f7 143 if line.include? ":PASS"
ram54288 0:a2cb7295a1f7 144 testPassed(lineArray)
ram54288 0:a2cb7295a1f7 145 testPass += 1
ram54288 0:a2cb7295a1f7 146 elsif line.include? ":FAIL:"
ram54288 0:a2cb7295a1f7 147 testFailed(lineArray)
ram54288 0:a2cb7295a1f7 148 testFail += 1
ram54288 0:a2cb7295a1f7 149 elsif line.include? ":IGNORE:"
ram54288 0:a2cb7295a1f7 150 testIgnored(lineArray)
ram54288 0:a2cb7295a1f7 151 testIgnore += 1
ram54288 0:a2cb7295a1f7 152 # If none of the keywords are found there are no more tests for this suite so clear
ram54288 0:a2cb7295a1f7 153 # the test flag
ram54288 0:a2cb7295a1f7 154 else
ram54288 0:a2cb7295a1f7 155 @testFlag = false
ram54288 0:a2cb7295a1f7 156 end
ram54288 0:a2cb7295a1f7 157 else
ram54288 0:a2cb7295a1f7 158 @testFlag = false
ram54288 0:a2cb7295a1f7 159 end
ram54288 0:a2cb7295a1f7 160 end
ram54288 0:a2cb7295a1f7 161 puts ""
ram54288 0:a2cb7295a1f7 162 puts "=================== SUMMARY ====================="
ram54288 0:a2cb7295a1f7 163 puts ""
ram54288 0:a2cb7295a1f7 164 puts "Tests Passed : " + testPass.to_s
ram54288 0:a2cb7295a1f7 165 puts "Tests Failed : " + testFail.to_s
ram54288 0:a2cb7295a1f7 166 puts "Tests Ignored : " + testIgnore.to_s
ram54288 0:a2cb7295a1f7 167 @totalTests = testPass + testFail + testIgnore
ram54288 0:a2cb7295a1f7 168 if @xmlOut == true
ram54288 0:a2cb7295a1f7 169 heading = "<testsuite tests=\"" + @totalTests.to_s + "\" failures=\"" + testFail.to_s + "\"" + " skips=\"" + testIgnore.to_s + "\">"
ram54288 0:a2cb7295a1f7 170 @arrayList.insert(0, heading)
ram54288 0:a2cb7295a1f7 171 writeXmlOuput()
ram54288 0:a2cb7295a1f7 172 end
ram54288 0:a2cb7295a1f7 173
ram54288 0:a2cb7295a1f7 174 # return result
ram54288 0:a2cb7295a1f7 175 end
ram54288 0:a2cb7295a1f7 176
ram54288 0:a2cb7295a1f7 177 end
ram54288 0:a2cb7295a1f7 178
ram54288 0:a2cb7295a1f7 179 # If the command line has no values in, used a default value of Output.txt
ram54288 0:a2cb7295a1f7 180 parseMyFile = ParseOutput.new
ram54288 0:a2cb7295a1f7 181
ram54288 0:a2cb7295a1f7 182 if ARGV.size >= 1
ram54288 0:a2cb7295a1f7 183 ARGV.each do |a|
ram54288 0:a2cb7295a1f7 184 if a == "-xml"
ram54288 0:a2cb7295a1f7 185 parseMyFile.setXmlOutput();
ram54288 0:a2cb7295a1f7 186 else
ram54288 0:a2cb7295a1f7 187 parseMyFile.process(a)
ram54288 0:a2cb7295a1f7 188 break
ram54288 0:a2cb7295a1f7 189 end
ram54288 0:a2cb7295a1f7 190 end
ram54288 0:a2cb7295a1f7 191 end