|
| 1 | +"""Parse verification outputs.""" |
| 2 | + |
| 3 | +import re |
| 4 | + |
| 5 | +def verification_parser(filename, threshold): |
| 6 | + with open(filename) as f: |
| 7 | + lines = f.readlines() |
| 8 | + |
| 9 | + first_match = True |
| 10 | + |
| 11 | + # extract lines from output |
| 12 | + for i, line in enumerate(lines): |
| 13 | + if line[:5] == '2 d e': |
| 14 | + if first_match: |
| 15 | + # skip the first match, since it doesn't contain output, |
| 16 | + # but set to false to catch next matches. |
| 17 | + first_match = False |
| 18 | + else: |
| 19 | + test_results = lines[i+2] |
| 20 | + |
| 21 | + # split test_results into a list with values for each number. |
| 22 | + # this uses spaces and the < > characters to separate the numbers. |
| 23 | + test_results = re.split('[ ><]',test_results) |
| 24 | + # ignore the Genmake, depend, make, and run checks, as well as |
| 25 | + # the "pass" or "fail" and test name at the end of the line |
| 26 | + test_results = test_results[4:-3] |
| 27 | + # convert to floats |
| 28 | + dp_similarity = [] |
| 29 | + for i, x in enumerate(test_results): |
| 30 | + try: |
| 31 | + dp_similarity.append(float(x)) |
| 32 | + except ValueError: |
| 33 | + pass |
| 34 | + |
| 35 | + assert all(elements > threshold for elements in dp_similarity) |
| 36 | + |
| 37 | +if __name__ == '__main__': |
| 38 | + |
| 39 | + import argparse |
| 40 | + |
| 41 | + parser = argparse.ArgumentParser(description='Check that verification simulation passed the test.') |
| 42 | + |
| 43 | + parser.add_argument('-filename', type=str, |
| 44 | + help='path to output file from the verification test') |
| 45 | + |
| 46 | + parser.add_argument('-threshold', type=int, default=15, |
| 47 | + help='number of decimal places of similarity required for test to pass') |
| 48 | + |
| 49 | + args = parser.parse_args() |
| 50 | + |
| 51 | + verification_parser(**vars(args)) |
0 commit comments