-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathfilter-test-logs
More file actions
executable file
·222 lines (195 loc) · 8.09 KB
/
filter-test-logs
File metadata and controls
executable file
·222 lines (195 loc) · 8.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#!/usr/bin/env python3
# Copyright (C) 2024 Apple Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import os
import argparse
import sys
import re
import time
# This prints the progress every interval_seconds to avoid that the step gets killed
# by buildbot because "command timed out: XXX seconds without output running YYY"
class KeepAliveStdoutProgress:
def __init__(self, interval_seconds=300, check_every_n_lines=100):
self.line_count = 0
self.last_progress_time = time.time()
self.interval_seconds = interval_seconds
self.check_every_n_lines = check_every_n_lines
def maybe_update_progress(self):
self.line_count += 1
# Only check time every N lines to avoid expensive system calls
if self.line_count % self.check_every_n_lines == 0:
current_time = time.time()
if current_time - self.last_progress_time >= self.interval_seconds:
print(f'filter-test-logs progress: {self.line_count} lines processed', flush=True)
self.last_progress_time = current_time
def parser():
parser = argparse.ArgumentParser(description='filter test output')
parser.add_argument(
'filter_type',
choices=['jsc', 'layout', 'scan-build', 'webdriver', 'test262', 'minibrowser', 'swift', 'api'],
help='Choose which test logs to filter'
)
parser.add_argument(
'--output',
help='output directory for unfiltered log',
default='logs.txt'
)
return parser.parse_args()
def filter_jsc_tests(log_file_name):
log_file = os.path.abspath(f'{log_file_name}')
keep_alive_stdout = KeepAliveStdoutProgress()
with open(log_file, 'w') as f:
print_all_lines = False
for line in sys.stdin:
f.write(line)
if print_all_lines:
print(line, end='')
elif line.startswith('** The following JSC') or line.startswith('Results'):
print_all_lines = True
print(line, end='')
else:
keep_alive_stdout.maybe_update_progress()
def filter_layout_tests(log_file_name):
log_file = os.path.abspath(f'{log_file_name}')
keep_alive_stdout = KeepAliveStdoutProgress()
with open(log_file, 'w') as f:
print_all_lines = False
for line in sys.stdin:
match = re.search(r'[\uD800-\uDFFF]', line)
if not match:
f.write(line)
if print_all_lines:
print(line, end='')
elif line.startswith('=> Results') or 'Exiting early' in line or 'leaks found' in line:
print_all_lines = True
print(line, end='')
else:
keep_alive_stdout.maybe_update_progress()
def filter_scan_build(log_file_name):
log_file = os.path.abspath(f'{log_file_name}')
keep_alive_stdout = KeepAliveStdoutProgress()
with open(log_file, 'w') as f:
print_all_lines = False
for line in sys.stdin:
f.write(line)
if line.startswith('=====') or print_all_lines:
print(line, end='')
# A success or failure is always preceeded by **
elif line.startswith('**'):
print_all_lines = True
print(line, end='')
elif ': error:' in line:
print(line, end='')
else:
keep_alive_stdout.maybe_update_progress()
def filter_webdriver_tests(log_file_name):
log_file = os.path.abspath(f'{log_file_name}')
keep_alive_stdout = KeepAliveStdoutProgress()
with open(log_file, 'w') as f:
print_all_lines = False
for line in sys.stdin:
f.write(line)
if print_all_lines:
print(line, end='')
elif 'tests ran as expected' in line:
print_all_lines = True
print(line, end='')
else:
keep_alive_stdout.maybe_update_progress()
def filter_test262(log_file_name):
log_file = os.path.abspath(f'{log_file_name}')
keep_alive_stdout = KeepAliveStdoutProgress()
with open(log_file, 'w') as f:
print_all_lines = False
for line in sys.stdin:
f.write(line)
if print_all_lines or line.startswith('! NEW FAIL'):
print(line, end='')
elif 'TESTS SUMMARY---' in line:
print_all_lines = True
print(line, end='')
else:
keep_alive_stdout.maybe_update_progress()
def filter_minibrowser_tests(log_file_name):
log_file = os.path.abspath(f'{log_file_name}')
keep_alive_stdout = KeepAliveStdoutProgress()
with open(log_file, 'w') as f:
print_all_lines = False
for line in sys.stdin:
f.write(line)
if print_all_lines:
print(line, end='')
elif 'Bundle passed tests on all this' in line:
print_all_lines = True
print(line, end='')
else:
keep_alive_stdout.maybe_update_progress()
def filter_swift(log_file_name):
log_file = os.path.abspath(f'{log_file_name}')
keep_alive_stdout = KeepAliveStdoutProgress()
with open(log_file, 'w') as f:
print_all_lines = False
for line in sys.stdin:
f.write(line)
if print_all_lines:
print(line, end='')
elif line.startswith('ERROR:') or line.startswith('FAILURE:') or '--- Build Script Analyzer ---' in line:
print_all_lines = True
print(line, end='')
elif 'error:' in line.lower():
print(line, end='')
else:
keep_alive_stdout.maybe_update_progress()
def filter_api_tests(log_file_name):
log_file = os.path.abspath(f'{log_file_name}')
keep_alive_stdout = KeepAliveStdoutProgress()
with open(log_file, 'w') as f:
print_all_lines = False
for line in sys.stdin:
f.write(line)
if print_all_lines:
print(line, end='')
elif re.match(r'.*Ran \d+ tests of \d+', line):
print_all_lines = True
print(line, end='')
else:
keep_alive_stdout.maybe_update_progress()
def main():
args = parser()
if args.filter_type == 'jsc':
filter_jsc_tests(args.output)
elif args.filter_type == 'layout':
filter_layout_tests(args.output)
elif args.filter_type == 'scan-build':
filter_scan_build(args.output)
elif args.filter_type == 'webdriver':
filter_webdriver_tests(args.output)
elif args.filter_type == 'test262':
filter_test262(args.output)
elif args.filter_type == 'minibrowser':
filter_minibrowser_tests(args.output)
elif args.filter_type == 'swift':
filter_swift(args.output)
elif args.filter_type == 'api':
filter_api_tests(args.output)
if __name__ == '__main__':
main()