1 from __future__
import print_function
6 """Simple script that scans all of the test suite results text fed in
7 through stdin and summarises the total number of failures, test
8 points, and test cases."""
10 # Function to parse numbers
11 def number_from_string(str_value
):
12 if str_value
.find("x") != -1:
13 return int(str_value
.replace("0x", "").replace("x", ""), 16);
17 def running_name_valid(name
):
18 if (name
!= "") and (name
.find(" ") == -1) and ((name
.find("/") != -1) or re
.match(r
'^(.*).c$', name
)):
24 if sys
.version_info
[0]<3:
25 safe_stdin
= sys
.stdin
27 safe_stdin
= io
.TextIOWrapper(sys
.stdin
.buffer, encoding
="latin-1")
28 lines
= safe_stdin
.readlines()
32 if (re
.search(r
'^--- Summary:', line
)):
41 # Create lines not present in simulation log
43 print("- Added by compact-results script: %s\n" % sys
.argv
[1])
44 m
= re
.match(r
'^(.*).out', outname
)
47 print("--- Running: %s\n" % outname
)
48 print("--- Summary: 1/0/0: 1 failed of 0 tests in 0 cases.\n")
50 # Init the running totals
51 failures
= 0 if summary_found
else 1
64 # --- Running: gen/ucz80/longor/longor
65 m
= re
.match(r
'^--- Running: (.*)$', line
)
67 #take the name only if not a whitespace, this happens if simulator stops when calling to print the name (stack overflow)
68 stripped_name
= m
.group(1).strip()
69 if running_name_valid(stripped_name
):
72 # In case the test program crashes before the "--- Running" message
73 m
= re
.match(r
'^[0-9]+ words read from (.*).ihx', line
)
77 safe_name
= name
if name
!= "" else outname
79 # Get base name from name
81 m
= re
.match(r
'([^/]*)/([^/]*)/([^/]*)/(.*)$', base
)
85 # '--- Summary: f/t/c: ...', where f = # failures, t = # test points,
87 if (re
.search(r
'^--- Summary:', line
)):
89 if line
.count(':') == 1:
90 (summary
, data
) = re
.split(r
':', line
)
92 (summary
, data
, rest
) = re
.split(r
':', line
)
94 (nfailures
, ntests
, ncases
) = re
.split(r
'/', data
)
95 tests
= tests
+ number_from_string(ntests
)
96 cases
= cases
+ number_from_string(ncases
)
98 print("Bad summary line:", line
)
100 failures
= failures
+ number_from_string(nfailures
)
101 if (number_from_string(nfailures
)):
102 print("Failure: %s" % safe_name
)
104 # '--- Simulator: b/t: ...', where b = # bytes, t = # ticks
105 if (re
.search(r
'^--- Simulator:', line
)):
107 (simulator
, data
, rest
) = re
.split(r
':', line
)
108 (nbytes
, nticks
) = re
.split(r
'/', data
)
110 print("Bad simulator line:", line
)
112 bytes
= bytes
+ float(nbytes
)
113 ticks
= ticks
+ float(nticks
)
115 # Stop at 0x000228: (106) Invalid instruction 0x00fd
116 if (re
.search(r
'Invalid instruction', line
) or re
.search(r
'unknown instruction', line
)):
118 print("Invalid instruction: %s" % safe_name
)
120 # Stop at 0xXXXXXX: (103) Stack overflow
121 if (re
.search(r
'Stack overflow', line
)):
123 print("Stack overflow: %s" % safe_name
)
126 print("%-35.35s" % sys
.argv
[1], end
=' ')
129 print("%d invalid instructions," % invalid
, end
=' ')
130 print("(f: %2.0f, t:%4.0f, c: %4.0f, b: %7.0f, T: %9.0f)" % (failures
, tests
, cases
, bytes
, ticks
))