|
19 | 19 | #
|
20 | 20 | # ----------------------------------------------------------------------------
|
21 | 21 |
|
22 |
| -import subprocess |
23 | 22 | import os
|
| 23 | +import subprocess |
24 | 24 | import sys
|
25 |
| -import time |
26 | 25 |
|
27 | 26 |
|
28 | 27 | def main():
|
29 |
| - verbose = False |
30 |
| - num_iterations = 4 |
31 |
| - |
32 |
| - write_obj_file = False |
33 |
| - next_arg_is_output = False |
34 |
| - compare_time = True |
35 |
| - output_file = None |
36 |
| - |
37 |
| - for arg in sys.argv: |
38 |
| - if next_arg_is_output: |
39 |
| - output_file = arg |
40 |
| - next_arg_is_output = False |
41 |
| - elif arg == '-c': |
42 |
| - write_obj_file = True |
43 |
| - elif arg == '-disable-incremental-llvm-codegen': |
44 |
| - compare_time = False |
45 |
| - elif arg == '-o': |
46 |
| - next_arg_is_output = True |
47 |
| - |
48 |
| - if not write_obj_file or output_file is None: |
49 |
| - return |
50 |
| - |
51 |
| - new_args = sys.argv[1:] |
52 |
| - subprocess.check_call(new_args) |
| 28 | + verbose = False |
| 29 | + num_iterations = 4 |
| 30 | + |
| 31 | + write_obj_file = False |
| 32 | + next_arg_is_output = False |
| 33 | + compare_time = True |
| 34 | + output_file = None |
| 35 | + |
| 36 | + for arg in sys.argv: |
| 37 | + if next_arg_is_output: |
| 38 | + output_file = arg |
| 39 | + next_arg_is_output = False |
| 40 | + elif arg == '-c': |
| 41 | + write_obj_file = True |
| 42 | + elif arg == '-disable-incremental-llvm-codegen': |
| 43 | + compare_time = False |
| 44 | + elif arg == '-o': |
| 45 | + next_arg_is_output = True |
| 46 | + |
| 47 | + if not write_obj_file or output_file is None: |
| 48 | + return |
| 49 | + |
| 50 | + new_args = sys.argv[1:] |
| 51 | + subprocess.check_call(new_args) |
53 | 52 |
|
54 |
| - if verbose: |
55 |
| - print "Reference compilation of " + output_file + ":" |
| 53 | + if verbose: |
| 54 | + print "Reference compilation of " + output_file + ":" |
56 | 55 |
|
57 |
| - reference_md5 = subprocess.check_output(["md5", "-q", output_file]) |
58 |
| - reference_time = os.path.getmtime(output_file) |
| 56 | + reference_md5 = subprocess.check_output(["md5", "-q", output_file]) |
| 57 | + reference_time = os.path.getmtime(output_file) |
59 | 58 |
|
60 |
| - if verbose: |
61 |
| - print " time = {}".format(reference_time) |
62 |
| - print " md5 = " + reference_md5 |
| 59 | + if verbose: |
| 60 | + print " time = {}".format(reference_time) |
| 61 | + print " md5 = " + reference_md5 |
63 | 62 |
|
64 |
| - subprocess.check_call(["cp", output_file, output_file + ".ref.o"]) |
| 63 | + subprocess.check_call(["cp", output_file, output_file + ".ref.o"]) |
65 | 64 |
|
66 |
| - for iteration in range(0, num_iterations): |
| 65 | + for iteration in range(0, num_iterations): |
67 | 66 |
|
68 |
| - if verbose: |
69 |
| - print "Iteration {}:".format(iteration) |
| 67 | + if verbose: |
| 68 | + print "Iteration {}:".format(iteration) |
70 | 69 |
|
71 |
| - subprocess.check_call(new_args) |
| 70 | + subprocess.check_call(new_args) |
72 | 71 |
|
73 |
| - second_md5 = subprocess.check_output(["md5", "-q", output_file]) |
74 |
| - second_time = os.path.getmtime(output_file) |
| 72 | + second_md5 = subprocess.check_output(["md5", "-q", output_file]) |
| 73 | + second_time = os.path.getmtime(output_file) |
75 | 74 |
|
76 |
| - if verbose: |
77 |
| - print " time = {}".format(second_time) |
78 |
| - print " md5 = " + second_md5 |
| 75 | + if verbose: |
| 76 | + print " time = {}".format(second_time) |
| 77 | + print " md5 = " + second_md5 |
79 | 78 |
|
80 |
| - # This is the most important check: is the output file exactly the same. |
81 |
| - if reference_md5 != second_md5: |
82 |
| - sys.exit("non-determinism when generating: " + output_file) |
| 79 | + # This is the most important check: is the output file exactly the |
| 80 | + # same. |
| 81 | + if reference_md5 != second_md5: |
| 82 | + sys.exit("non-determinism when generating: " + output_file) |
83 | 83 |
|
84 |
| - # This is the bonus check: does the compiler not re-write the output file. |
85 |
| - # (For compilations < 1sec this check may succeed even if the file was |
86 |
| - # overwritten). |
87 |
| - if compare_time and reference_time != second_time: |
88 |
| - sys.exit("file re-written: " + output_file) |
| 84 | + # This is the bonus check: does the compiler not re-write the output |
| 85 | + # file. (For compilations < 1sec this check may succeed even if the |
| 86 | + # file was overwritten). |
| 87 | + if compare_time and reference_time != second_time: |
| 88 | + sys.exit("file re-written: " + output_file) |
89 | 89 |
|
90 | 90 |
|
91 | 91 | main()
|
92 |
| - |
0 commit comments