OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/python |
| 2 # Copyright (c) 2012 The Native Client Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 5 |
| 6 """Converts outputs from the old validator into a list of general errors. |
| 7 |
| 8 The outputs then would be compared for exact match with what the |
| 9 script run_ncval_tests.py outputs for the test. |
| 10 |
| 11 Works under assumption that the corresponding input files (*.hex) maintain a |
| 12 separation of instructions: one instruction per line in .hex file. We could get |
| 13 the same information from the validator, but, luckily, we do not have to do |
| 14 that. |
| 15 """ |
| 16 |
| 17 import re |
| 18 import sys |
| 19 |
| 20 import run_ncval_tests |
| 21 |
| 22 |
| 23 def WriteFile(filename, data): |
| 24 fh = open(filename, "w") |
| 25 try: |
| 26 fh.write(data) |
| 27 finally: |
| 28 fh.close() |
| 29 |
| 30 |
| 31 def Main(argv): |
| 32 argv = argv[1:] |
| 33 offset = None |
| 34 for arg in argv: |
| 35 assert(arg[-5:] == '.rval') |
| 36 |
| 37 # Parse the golden file 1st time, find bundle_crosses. |
| 38 bundle_crosses = [] |
| 39 for line in open(arg, 'r').readlines(): |
| 40 bundle_error_m = re.match( |
| 41 r'VALIDATOR: ERROR: ([0-9a-zA-Z]+): Bad basic block alignment', line) |
| 42 if bundle_error_m: |
| 43 bundle_crosses.append(int(bundle_error_m.group(1), 16)) |
| 44 |
| 45 # Find offsets for all instructions that cross a bundle. |
| 46 err_offsets = {} |
| 47 insts = run_ncval_tests.InstByteSequence() |
| 48 insts.Parse(arg[:-5] + '.hex') |
| 49 for bundle_offset in set(bundle_crosses): |
| 50 off = bundle_offset - 1 |
| 51 while off >= 0: |
| 52 if insts.HasOffset(off): |
| 53 err_offsets[off] = ['crosses boundary'] |
| 54 break |
| 55 off -= 1 |
| 56 |
| 57 # Parse the golden file 2nd time. Find other offsets that cause errors. An |
| 58 # error report takes 2 sequential lines. |
| 59 seen_offset = False |
| 60 for line in open(arg, 'r').readlines(): |
| 61 ln = line.rstrip() |
| 62 off_m = re.match(r'VALIDATOR: ([0-9a-z]+):', ln) |
| 63 if off_m: |
| 64 seen_offset = True |
| 65 prev_offset = offset |
| 66 offset = int(off_m.group(1), 16) |
| 67 continue |
| 68 val_error_m = re.match(r'VALIDATOR: ERROR:', ln) |
| 69 if val_error_m and seen_offset and prev_offset != offset: |
| 70 err_offsets.setdefault(offset, []).append('validation error') |
| 71 seen_offset = False |
| 72 |
| 73 # Output the error messages in offset order. |
| 74 golden_text = '' |
| 75 for off, msg_lst in sorted(err_offsets.iteritems()): |
| 76 for msg in msg_lst: |
| 77 golden_text += 'offset 0x%x: %s\n' % (off, msg) |
| 78 filename = arg[:-5] + '.val.ref' |
| 79 print 'writing file: %s' % filename |
| 80 WriteFile(filename, golden_text) |
| 81 |
| 82 |
| 83 if __name__ == '__main__': |
| 84 sys.exit(Main(sys.argv)) |
OLD | NEW |