@@ -8,11 +8,34 @@ def print_dict_sorted_by_values(grouping_dict: dict) -> None:
88 print (f"{ value } : { key } " )
99
1010
11+ def find_failed_line_index (command_output : list [str ]) -> int :
12+ index = len (command_output ) - 1
13+ while command_output [index ].startswith ("...skipped" ) or command_output [index ].startswith ("...removing" ):
14+ index -= 1
15+ if command_output [index ].startswith ("...failed" ):
16+ return index
17+
18+ assert not any (line .startswith ("...failed" ) for line in command_output )
19+ return - 1
20+
21+
22+ def process_one_loaded_log (command_output : list [str ], passed_outputs : list [str ], failed_outputs : list [str ]) -> None :
23+ while command_output [- 1 ] == "" :
24+ command_output .pop ()
25+ if command_output [0 ].startswith ("**passed**" ):
26+ passed_outputs .append (command_output )
27+ else :
28+ if find_failed_line_index (command_output ) >= 0 :
29+ failed_outputs .append (list (command_output ))
30+
31+ command_output .clear ()
32+
33+
1134def process_logs (log_file : str ) -> None :
1235 reading_init_lines = True
1336
1437 failed_outputs = []
15- passed_outputs = []
38+ passed_outputs = [] # TODO: There are also (failed-as-expected) results
1639 skipped_outputs = []
1740 command_output = []
1841
@@ -27,6 +50,7 @@ def process_logs(log_file: str) -> None:
2750
2851 # End of the output
2952 if line .startswith ("...updated " ) and line .rstrip ().endswith ("targets..." ):
53+ process_one_loaded_log (command_output , passed_outputs , failed_outputs )
3054 break
3155
3256 # Progress lines (e.g. ...on 200th target...)
@@ -48,16 +72,7 @@ def process_logs(log_file: str) -> None:
4872 command_output .append (line )
4973 continue
5074
51- if command_output [0 ].startswith ("**passed**" ):
52- passed_outputs .append (command_output )
53- else :
54- look_back = 1
55- while command_output [- look_back ].startswith ("...skipped" ):
56- look_back += 1
57- if command_output [- look_back ].startswith ("...failed" ):
58- failed_outputs .append (command_output )
59-
60- command_output = []
75+ process_one_loaded_log (command_output , passed_outputs , failed_outputs )
6176
6277 command_output .append (line )
6378
@@ -84,16 +99,13 @@ def process_logs(log_file: str) -> None:
8499
85100 grouping = collections .defaultdict (int )
86101 for output in failed_outputs :
87- look_back = 1
88- while output [- look_back ].startswith ("...skipped" ):
89- look_back += 1
90- assert output [- look_back ].startswith ("...failed" ), output [- look_back ]
91- look_back += 1
102+ error_line_index = find_failed_line_index (output ) - 1
103+ assert error_line_index >= 0
92104
93105 command = output [0 ].strip ().split (" " )[0 ]
94106
95107 # e.g. <3>WSL (4090138) ERROR: UtilAcceptVsock:251: accept4 failed 110
96- if output [- look_back ].startswith ("<3>WSL (" ) and output [- look_back ].endswith (") ERROR: UtilAcceptVsock:251: accept4 failed 110" ):
108+ if output [error_line_index ].startswith ("<3>WSL (" ) and output [error_line_index ].endswith (") ERROR: UtilAcceptVsock:251: accept4 failed 110" ):
97109 grouping [f"{ command } : <3>WSL ERROR: UtilAcceptVsock:251: accept4 failed 110" ] += 1
98110 continue
99111
@@ -107,19 +119,19 @@ def process_logs(log_file: str) -> None:
107119 break
108120 continue
109121
110- if output [- look_back ] == ("====== END OUTPUT ======" ):
122+ if output [error_line_index ] == ("====== END OUTPUT ======" ):
111123 for i , line in enumerate (output ):
112124 if line == "====== BEGIN OUTPUT ======" :
113125 break
114126
115127 if output [i + 1 ].startswith ("<3>WSL (" ) and output [i + 1 ].endswith (") ERROR: UtilAcceptVsock:251: accept4 failed 110" ):
116128 output [i + 1 ] = "<3>WSL (...) ERROR: UtilAcceptVsock:251: accept4 failed 110"
117- log_str = " " .join ((line for line in output [i + 1 :- look_back ] if line != "" ))
129+ log_str = " " .join ((line for line in output [i + 1 :error_line_index ] if line != "" ))
118130 grouping [f"{ command } : { log_str } " ] += 1
119- # grouping[f"{command}: {output[i:-look_back + 1]}"] += 1
131+ # grouping[f"{command}: {output[i:error_line_index + 1]}"] += 1
120132 continue
121133
122- grouping [f"{ command } : { output [- look_back ]} " ] += 1
134+ grouping [f"{ command } : { output [error_line_index ]} " ] += 1
123135
124136 print_dict_sorted_by_values (grouping )
125137
0 commit comments