Deleted Added
sdiff udiff text old ( 13002:b8d58d5f25a5 ) new ( 13003:3a164f2f8103 )
full compact
1#!/usr/bin/env python2
2#
3# Copyright 2018 Google, Inc.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are
7# met: redistributions of source code must retain the above copyright
8# notice, this list of conditions and the following disclaimer;

--- 16 unchanged lines hidden (view full) ---

25# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27#
28# Authors: Gabe Black
29
30from __future__ import print_function
31
32import argparse
33import functools
34import inspect
35import itertools
36import json
37import multiprocessing.pool
38import os
39import subprocess
40import sys
41
42script_path = os.path.abspath(inspect.getfile(inspect.currentframe()))
43script_dir = os.path.dirname(script_path)
44config_path = os.path.join(script_dir, 'config.py')
45
46systemc_rel_path = 'systemc'

--- 8 unchanged lines hidden (view full) ---

55
56
57
58class Test(object):
59 def __init__(self, target, suffix, build_dir, props):
60 self.target = target
61 self.suffix = suffix
62 self.build_dir = build_dir
63
64 for key, val in props.iteritems():
65 setattr(self, key, val)
66
67 def dir(self):
68 return os.path.join(self.build_dir, tests_rel_path, self.path)
69
70 def src_dir(self):
71 return os.path.join(script_dir, self.path)
72
73 def golden_dir(self):
74 return os.path.join(self.src_dir(), 'golden')

--- 62 unchanged lines hidden (view full) ---

137 def run_test(test):
138 cmd = []
139 if args.timeout:
140 cmd.extend(timeout_cmd)
141 cmd.extend([
142 test.full_path(),
143 '-red', test.m5out_dir(),
144 '--listener-mode=off',
145 config_path
146 ])
147 # Ensure the output directory exists.
148 if not os.path.exists(test.m5out_dir()):
149 os.makedirs(test.m5out_dir())
150 try:
151 subprocess.check_call(cmd)
152 except subprocess.CalledProcessError, error:

--- 7 unchanged lines hidden (view full) ---

160 if args.j == 1:
161 map(run_test, runnable)
162 else:
163 tp = multiprocessing.pool.ThreadPool(args.j)
164 map(lambda t: tp.apply_async(run_test, (t,)), runnable)
165 tp.close()
166 tp.join()
167
168class VerifyPhase(TestPhaseBase):
169 name = 'verify'
170 number = 3
171
172 def reset_status(self):
173 self._passed = []
174 self._failed = {}
175
176 def passed(self, test):
177 self._passed.append(test)
178
179 def failed(self, test, cause):
180 self._failed.setdefault(cause, []).append(test)
181
182 def print_status(self):
183 total_passed = len(self._passed)
184 total_failed = sum(map(len, self._failed.values()))
185 print()
186 print('Passed: {passed:4} - Failed: {failed:4}'.format(
187 passed=total_passed, failed=total_failed))
188
189 def write_result_file(self, path):
190 passed = map(lambda t: t.path, self._passed)
191 passed.sort()
192 failed = {
193 cause: map(lambda t: t.path, tests) for
194 cause, tests in self._failed.iteritems()
195 }
196 for tests in failed.values():
197 tests.sort()
198 results = { 'passed': passed, 'failed': failed }
199 with open(path, 'w') as rf:
200 json.dump(results, rf)
201
202 def print_results(self):
203 passed = map(lambda t: t.path, self._passed)
204 passed.sort()
205 failed = {
206 cause: map(lambda t: t.path, tests) for
207 cause, tests in self._failed.iteritems()
208 }
209 for tests in failed.values():
210 tests.sort()
211
212 print()
213 print('Passed:')
214 map(lambda t: print(' ', t), passed)
215
216 print()
217 print('Failed:')
218 categories = failed.items()
219 categories.sort()
220
221 def cat_str((cause, tests)):
222 heading = ' ' + cause.capitalize() + ':\n'
223 test_lines = [' ' + test + '\n'for test in tests]
224 return heading + ''.join(test_lines)
225 blocks = map(cat_str, categories)
226
227 print('\n'.join(blocks))
228
229 def run(self, tests):
230 parser = argparse.ArgumentParser()
231 result_opts = parser.add_mutually_exclusive_group()
232 result_opts.add_argument('--result-file', action='store_true',
233 help='Create a results.json file in the current directory.')
234 result_opts.add_argument('--result-file-at', metavar='PATH',
235 help='Create a results json file at the given path.')

--- 11 unchanged lines hidden (view full) ---

247 self.passed(test)
248 else:
249 self.failed(test, 'compile failed')
250
251 for test in runnable:
252 with open(test.returncode_file()) as rc:
253 returncode = int(rc.read())
254
255 if returncode == 0:
256 self.passed(test)
257 elif returncode == 124:
258 self.failed(test, 'time out')
259 else:
260 self.failed(test, 'abort')
261
262 if args.print_results:
263 self.print_results()
264
265 self.print_status()
266
267 result_path = None
268 if args.result_file:
269 result_path = os.path.join(os.getcwd(), 'results.json')

--- 89 unchanged lines hidden ---