-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
60 lines (41 loc) · 1.88 KB
/
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import glob
import subprocess
import os, sys
#Folder
# tests
# expected
# ook
alltests = glob.glob("tests/*.ook")
alltests.sort();
subprocess.call(["make", "clean"], cwd="./ook")
subprocess.call(["make"], cwd="./ook")
subprocess.call(["rm", "-f", "*.txt"], cwd="./results/")
subprocess.call(["rm", "-f", "*.asm"], cwd="./results/asm/")
subprocess.call(["rm", "-f", "*"], cwd="./results/exe/")
subprocess.call(["rm", "-f", "*.o"], cwd="./results/o/")
i = 0
tests_passed = 0;
while i < len(alltests):
result = alltests[i].replace("tests","results/asm").replace(".ook",".asm")
test = alltests[i]
i += 1
subprocess.call(["./ook/ook", test, "-o", result])
subprocess.call(["yasm", "-felf32", result, "-o", test.replace("tests","results/o").replace(".ook",".o")])
subprocess.call(["ld", "-melf_i386" ,"-o", test.replace("tests","results/exe").replace(".ook",""), test.replace("tests","results/o").replace(".ook",".o"), "-lrts"])
with open("./" + test.replace("tests","results").replace(".ook",".txt"), 'a+') as file:
subprocess.call(["./" + test.replace("tests","results/exe").replace(".ook","")], stdout = file)
my_file = open("./" + test.replace("tests","results").replace(".ook",".txt"), 'r')
david_file = open(test.replace("tests","./expected").replace(".ook",".out"), 'r')
david_output = my_file.read().strip(" \n\r\t")
my_output = david_file.read().strip(" \n\r\t")
my_file.close()
david_file.close()
if (david_output == my_output):
tests_passed += 1
else:
subprocess.call(["colordiff", test.replace("tests","./expected").replace(".ook",".out"), test.replace("tests","./results").replace(".ook",".txt")])
#subprocess.call(["diff", test.replace("tests","./expected").replace(".ook",".out"), test.replace("tests","./results").replace(".ook",".txt")])
#
#input() # para esperar
#ld -o examples/ex1 examples/ex1.o -lrts
print(str(tests_passed/len(alltests) * 100) + "% tests passed")