leo hendrickson / Mbed OS example-Ethernet-mbed-Cloud-connect
Committer:
leothedragon
Date:
Tue May 04 08:55:12 2021 +0000
Revision:
0:8f0bb79ddd48
nmn

Who changed what in which revision?

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