This repository has been archived by the owner on Nov 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_test.py
46 lines (34 loc) · 1.33 KB
/
check_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""
This module checks that the homework's solution output is correct
Computer Systems Architecture Course
Assignment 1
March 2020
"""
import subprocess
import sys
def main():
if len(sys.argv) != 4:
print("Invalid number of arguments\nUsage: check_test.py testname output_filepath ref_filepath")
return
testname = sys.argv[1]
output_filename = sys.argv[2]
ref_filename = sys.argv[3]
# load the lines from the output file and sort them
with open(output_filename) as output_file:
output_lines = output_file.read()
output_lines = output_lines.split(")") # sometimes there is no new line between consumer outputs
output_lines = [line.strip() + ")" for line in output_lines if len(line.strip()) > 0]
output_lines.sort()
sorted_output_filename = output_filename + ".sorted"
# write to input file (tests/{test_name}.in)
with open(sorted_output_filename, 'w') as sorted_output_file:
for line in output_lines:
print(line, file=sorted_output_file)
command = subprocess.Popen(["diff", sorted_output_filename, ref_filename], stdout=subprocess.PIPE)
out, err = command.communicate()
if len(out) == 0:
print(f"Test {testname}" + ":\t\t" + "PASSED")
else:
print(f"Test {testname}" + ":\t\t" + "FAILED")
if __name__ == "__main__":
main()