32a33,34
> import collections
> import difflib
38a41
> import re
62a66
> self.props = {}
65c69
< setattr(self, key, val)
---
> self.set_prop(key, val)
66a71,74
> def set_prop(self, key, val):
> setattr(self, key, val)
> self.props[key] = val
>
144a153
> '--quiet',
167a177,225
> class Checker(object):
> def __init__(self, ref, test, tag):
> self.ref = ref
> self.test = test
> self.tag = tag
>
> def check(self):
> with open(self.text) as test_f, open(self.ref) as ref_f:
> return test_f.read() == ref_f.read()
>
> class LogChecker(Checker):
> def merge_filts(*filts):
> filts = map(lambda f: '(' + f + ')', filts)
> filts = '|'.join(filts)
> return re.compile(filts, flags=re.MULTILINE)
>
> ref_filt = merge_filts(
> r'^\nInfo: /OSCI/SystemC: Simulation stopped by user.\n',
> r'^SystemC Simulation\n'
> )
> test_filt = merge_filts(
> r'^Global frequency set at \d* ticks per second\n'
> )
>
> def __init__(self, ref, test, tag, out_dir):
> super(LogChecker, self).__init__(ref, test, tag)
> self.out_dir = out_dir
>
> def apply_filters(self, data, filts):
> re.sub(filt, '', data)
>
> def check(self):
> test_file = os.path.basename(self.test)
> ref_file = os.path.basename(self.ref)
> with open(self.test) as test_f, open(self.ref) as ref_f:
> test = re.sub(self.test_filt, '', test_f.read())
> ref = re.sub(self.ref_filt, '', ref_f.read())
> if test != ref:
> diff_file = '.'.join([ref_file, 'diff'])
> diff_path = os.path.join(self.out_dir, diff_file)
> with open(diff_path, 'w') as diff_f:
> for line in difflib.unified_diff(
> ref.splitlines(True), test.splitlines(True),
> fromfile=ref_file,
> tofile=test_file):
> diff_f.write(line)
> return False
> return True
>
179c237,238
< def failed(self, test, cause):
---
> def failed(self, test, cause, note=''):
> test.set_prop('note', note)
190,193c249,252
< passed = map(lambda t: t.path, self._passed)
< passed.sort()
< failed = {
< cause: map(lambda t: t.path, tests) for
---
> results = {
> 'passed': map(lambda t: t.props, self._passed),
> 'failed': {
> cause: map(lambda t: t.props, tests) for
194a254
> }
196,198d255
< for tests in failed.values():
< tests.sort()
< results = { 'passed': passed, 'failed': failed }
203,211d259
< passed = map(lambda t: t.path, self._passed)
< passed.sort()
< failed = {
< cause: map(lambda t: t.path, tests) for
< cause, tests in self._failed.iteritems()
< }
< for tests in failed.values():
< tests.sort()
<
214c262,263
< map(lambda t: print(' ', t), passed)
---
> for path in sorted(list([ t.path for t in self._passed ])):
> print(' ', path)
218,219d266
< categories = failed.items()
< categories.sort()
221,225c268,276
< def cat_str((cause, tests)):
< heading = ' ' + cause.capitalize() + ':\n'
< test_lines = [' ' + test + '\n'for test in tests]
< return heading + ''.join(test_lines)
< blocks = map(cat_str, categories)
---
> causes = []
> for cause, tests in sorted(self._failed.items()):
> block = ' ' + cause.capitalize() + ':\n'
> for test in sorted(tests, key=lambda t: t.path):
> block += ' ' + test.path
> if test.note:
> block += ' - ' + test.note
> block += '\n'
> causes.append(block)
227c278
< print('\n'.join(blocks))
---
> print('\n'.join(causes))
255,257c306
< if returncode == 0:
< self.passed(test)
< elif returncode == 124:
---
> if returncode == 124:
259c308,309
< else:
---
> continue
> elif returncode != 0:
260a311
> continue
261a313,336
> out_dir = test.m5out_dir()
>
> Diff = collections.namedtuple(
> 'Diff', 'ref, test, tag, ref_filter')
>
> diffs = []
>
> log_file = '.'.join([test.name, 'log'])
> log_path = os.path.join(test.golden_dir(), log_file)
> simout_path = os.path.join(out_dir, 'simout')
> if not os.path.exists(simout_path):
> self.failed(test, 'no log output')
> if os.path.exists(log_path):
> diffs.append(LogChecker(
> log_path, simout_path, log_file, out_dir))
>
> failed_diffs = filter(lambda d: not d.check(), diffs)
> if failed_diffs:
> tags = map(lambda d: d.tag, failed_diffs)
> self.failed(test, 'failed diffs', ' '.join(tags))
> continue
>
> self.passed(test)
>