verify.py (13001:acf4fd41ba76) | verify.py (13002:b8d58d5f25a5) |
---|---|
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; --- 20 unchanged lines hidden (view full) --- 29 30from __future__ import print_function 31 32import argparse 33import functools 34import inspect 35import itertools 36import json | 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; --- 20 unchanged lines hidden (view full) --- 29 30from __future__ import print_function 31 32import argparse 33import functools 34import inspect 35import itertools 36import json |
37import logging | |
38import multiprocessing.pool 39import os 40import subprocess 41import sys 42 43script_path = os.path.abspath(inspect.getfile(inspect.currentframe())) 44script_dir = os.path.dirname(script_path) 45config_path = os.path.join(script_dir, 'config.py') 46 47systemc_rel_path = 'systemc' 48tests_rel_path = os.path.join(systemc_rel_path, 'tests') 49json_rel_path = os.path.join(tests_rel_path, 'tests.json') 50 51 52 | 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' 47tests_rel_path = os.path.join(systemc_rel_path, 'tests') 48json_rel_path = os.path.join(tests_rel_path, 'tests.json') 49 50 51 |
53logging.basicConfig(level=logging.INFO) 54 | |
55def scons(*args): 56 args = ['scons'] + list(args) 57 subprocess.check_call(args) 58 59 60 61class Test(object): 62 def __init__(self, target, suffix, build_dir, props): --- 17 unchanged lines hidden (view full) --- 80 return '.'.join([self.name, self.suffix]) 81 82 def full_path(self): 83 return os.path.join(self.dir(), self.bin()) 84 85 def m5out_dir(self): 86 return os.path.join(self.dir(), 'm5out.' + self.suffix) 87 | 52def scons(*args): 53 args = ['scons'] + list(args) 54 subprocess.check_call(args) 55 56 57 58class Test(object): 59 def __init__(self, target, suffix, build_dir, props): --- 17 unchanged lines hidden (view full) --- 77 return '.'.join([self.name, self.suffix]) 78 79 def full_path(self): 80 return os.path.join(self.dir(), self.bin()) 81 82 def m5out_dir(self): 83 return os.path.join(self.dir(), 'm5out.' + self.suffix) 84 |
85 def returncode_file(self): 86 return os.path.join(self.m5out_dir(), 'returncode') |
|
88 89 | 87 88 |
89 |
|
90test_phase_classes = {} 91 92class TestPhaseMeta(type): 93 def __init__(cls, name, bases, d): 94 if not d.pop('abstract', False): 95 test_phase_classes[d['name']] = cls 96 97 super(TestPhaseMeta, cls).__init__(name, bases, d) --- 41 unchanged lines hidden (view full) --- 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 ]) | 90test_phase_classes = {} 91 92class TestPhaseMeta(type): 93 def __init__(cls, name, bases, d): 94 if not d.pop('abstract', False): 95 test_phase_classes[d['name']] = cls 96 97 super(TestPhaseMeta, cls).__init__(name, bases, d) --- 41 unchanged lines hidden (view full) --- 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()) |
|
147 try: 148 subprocess.check_call(cmd) 149 except subprocess.CalledProcessError, error: 150 returncode = error.returncode 151 else: 152 returncode = 0 | 150 try: 151 subprocess.check_call(cmd) 152 except subprocess.CalledProcessError, error: 153 returncode = error.returncode 154 else: 155 returncode = 0 |
153 with open(os.path.join(test.m5out_dir(), 'returncode'), 'w') as rc: | 156 with open(test.returncode_file(), 'w') as rc: |
154 rc.write('%d\n' % returncode) 155 156 runnable = filter(lambda t: not t.compile_only, tests) 157 if args.j == 1: 158 map(run_test, runnable) 159 else: 160 tp = multiprocessing.pool.ThreadPool(args.j) 161 map(lambda t: tp.apply_async(run_test, (t,)), runnable) 162 tp.close() 163 tp.join() 164 165class VerifyPhase(TestPhaseBase): 166 name = 'verify' 167 number = 3 168 | 157 rc.write('%d\n' % returncode) 158 159 runnable = filter(lambda t: not t.compile_only, tests) 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 |
|
169 def run(self, tests): | 229 def run(self, tests): |
170 for test in tests: 171 if test.compile_only: 172 continue 173 logging.info("Would verify %s", test.m5out_dir()) | 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.') 236 parser.add_argument('--print-results', action='store_true', 237 help='Print a list of tests that passed or failed') 238 args = parser.parse_args(self.args) |
174 | 239 |
240 self.reset_status() |
|
175 | 241 |
242 runnable = filter(lambda t: not t.compile_only, tests) 243 compile_only = filter(lambda t: t.compile_only, tests) |
|
176 | 244 |
245 for test in compile_only: 246 if os.path.exists(test.full_path()): 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') 270 elif args.result_file_at: 271 result_path = args.result_file_at 272 273 if result_path: 274 self.write_result_file(result_path) 275 276 |
|
177parser = argparse.ArgumentParser(description='SystemC test utility') 178 179parser.add_argument('build_dir', metavar='BUILD_DIR', 180 help='The build directory (ie. build/ARM).') 181 182parser.add_argument('--update-json', action='store_true', 183 help='Update the json manifest of tests.') 184 --- 74 unchanged lines hidden --- | 277parser = argparse.ArgumentParser(description='SystemC test utility') 278 279parser.add_argument('build_dir', metavar='BUILD_DIR', 280 help='The build directory (ie. build/ARM).') 281 282parser.add_argument('--update-json', action='store_true', 283 help='Update the json manifest of tests.') 284 --- 74 unchanged lines hidden --- |