verify.py (13240:1c15c6d15766) verify.py (13242:b4d52d9afc7f)
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;

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

209 return tagged_filt('Error', num)
210
211def warning_filt(num):
212 return tagged_filt('Warning', num)
213
214def info_filt(num):
215 return tagged_filt('Info', num)
216
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;

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

209 return tagged_filt('Error', num)
210
211def warning_filt(num):
212 return tagged_filt('Warning', num)
213
214def info_filt(num):
215 return tagged_filt('Info', num)
216
217class LogChecker(Checker):
217class DiffingChecker(Checker):
218 def __init__(self, ref, test, tag, out_dir):
219 super(DiffingChecker, self).__init__(ref, test, tag)
220 self.out_dir = out_dir
221
222 def diffing_check(self, ref_lines, test_lines):
223 test_file = os.path.basename(self.test)
224 ref_file = os.path.basename(self.ref)
225
226 diff_file = '.'.join([ref_file, 'diff'])
227 diff_path = os.path.join(self.out_dir, diff_file)
228 if test_lines != ref_lines:
229 with open(diff_path, 'w') as diff_f:
230 for line in difflib.unified_diff(
231 ref_lines, test_lines,
232 fromfile=ref_file,
233 tofile=test_file):
234 diff_f.write(line)
235 return False
236 else:
237 if os.path.exists(diff_path):
238 os.unlink(diff_path)
239 return True
240
241class LogChecker(DiffingChecker):
218 def merge_filts(*filts):
219 filts = map(lambda f: '(' + f + ')', filts)
220 filts = '|'.join(filts)
221 return re.compile(filts, flags=re.MULTILINE)
222
223 # The reporting mechanism will print the actual filename when running in
224 # gem5, and the "golden" output will say "<removed by verify.py>". We want
225 # to strip out both versions to make comparing the output sensible.

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

241 r'^Global frequency set at \d* ticks per second\n',
242 r'^info: Entering event queue @ \d*\. Starting simulation\.\.\.\n',
243 r'warn: [^(]+\([^)]*\)( \[with [^]]*\])? not implemented\.\n',
244 r'warn: Ignoring request to set stack size\.\n',
245 info_filt(804),
246 in_file_filt,
247 )
248
242 def merge_filts(*filts):
243 filts = map(lambda f: '(' + f + ')', filts)
244 filts = '|'.join(filts)
245 return re.compile(filts, flags=re.MULTILINE)
246
247 # The reporting mechanism will print the actual filename when running in
248 # gem5, and the "golden" output will say "<removed by verify.py>". We want
249 # to strip out both versions to make comparing the output sensible.

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

265 r'^Global frequency set at \d* ticks per second\n',
266 r'^info: Entering event queue @ \d*\. Starting simulation\.\.\.\n',
267 r'warn: [^(]+\([^)]*\)( \[with [^]]*\])? not implemented\.\n',
268 r'warn: Ignoring request to set stack size\.\n',
269 info_filt(804),
270 in_file_filt,
271 )
272
249 def __init__(self, ref, test, tag, out_dir):
250 super(LogChecker, self).__init__(ref, test, tag)
251 self.out_dir = out_dir
252
253 def apply_filters(self, data, filts):
254 re.sub(filt, '', data)
255
256 def check(self):
273 def apply_filters(self, data, filts):
274 re.sub(filt, '', data)
275
276 def check(self):
257 test_file = os.path.basename(self.test)
258 ref_file = os.path.basename(self.ref)
259 with open(self.test) as test_f, open(self.ref) as ref_f:
260 test = re.sub(self.test_filt, '', test_f.read())
261 ref = re.sub(self.ref_filt, '', ref_f.read())
277 with open(self.test) as test_f, open(self.ref) as ref_f:
278 test = re.sub(self.test_filt, '', test_f.read())
279 ref = re.sub(self.ref_filt, '', ref_f.read())
262 diff_file = '.'.join([ref_file, 'diff'])
263 diff_path = os.path.join(self.out_dir, diff_file)
264 if test != ref:
265 with open(diff_path, 'w') as diff_f:
266 for line in difflib.unified_diff(
267 ref.splitlines(True), test.splitlines(True),
268 fromfile=ref_file,
269 tofile=test_file):
270 diff_f.write(line)
271 return False
272 else:
273 if os.path.exists(diff_path):
274 os.unlink(diff_path)
275 return True
280 return self.diffing_check(ref.splitlines(True),
281 test.splitlines(True))
276
282
283class VcdChecker(DiffingChecker):
284 def check(self):
285 with open (self.test) as test_f, open(self.ref) as ref_f:
286 ref = ref_f.read().splitlines(True)
287 test = test_f.read().splitlines(True)
288 # Strip off the first seven lines of the test output which are
289 # date and version information.
290 test = test[7:]
291
292 return self.diffing_check(ref, test)
293
277class GoldenDir(object):
278 def __init__(self, path, platform):
279 self.path = path
280 self.platform = platform
281
282 contents = os.listdir(path)
283 suffix = '.' + platform
284 suffixed = filter(lambda c: c.endswith(suffix), contents)

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

442 diffs.append(LogChecker(log_path, simout_path,
443 log_file, out_dir))
444
445 for name in gd.unused():
446 test_path = os.path.join(out_dir, name)
447 ref_path = gd.entry(name)
448 if not os.path.exists(test_path):
449 missing.append(name)
294class GoldenDir(object):
295 def __init__(self, path, platform):
296 self.path = path
297 self.platform = platform
298
299 contents = os.listdir(path)
300 suffix = '.' + platform
301 suffixed = filter(lambda c: c.endswith(suffix), contents)

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

459 diffs.append(LogChecker(log_path, simout_path,
460 log_file, out_dir))
461
462 for name in gd.unused():
463 test_path = os.path.join(out_dir, name)
464 ref_path = gd.entry(name)
465 if not os.path.exists(test_path):
466 missing.append(name)
467 elif name.endswith('.vcd'):
468 diffs.append(VcdChecker(ref_path, test_path,
469 name, out_dir))
450 else:
451 diffs.append(Checker(ref_path, test_path, name))
452
453 if missing:
454 self.failed(test, 'missing output', ' '.join(missing))
455 continue
456
457 failed_diffs = filter(lambda d: not d.check(), diffs)

--- 112 unchanged lines hidden ---
470 else:
471 diffs.append(Checker(ref_path, test_path, name))
472
473 if missing:
474 self.failed(test, 'missing output', ' '.join(missing))
475 continue
476
477 failed_diffs = filter(lambda d: not d.check(), diffs)

--- 112 unchanged lines hidden ---