Example

Dependencies:   FXAS21002 FXOS8700Q

Committer:
maygup01
Date:
Tue Nov 19 09:49:38 2019 +0000
Revision:
0:11cc2b7889af
Example

Who changed what in which revision?

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