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
/
checker.py
72 lines (57 loc) · 1.84 KB
/
checker.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
61
62
63
64
65
66
67
68
69
70
71
72
import subprocess
import shutil
import os
import sys
sourceName = "tema1.asm"
if sys.platform.startswith('win32'):
objName = "tema1.obj"
execName = "tema1.exe"
sasmPath = "C:\\Program Files\\SASM"
nasmPath = sasmPath + "\\NASM\\nasm.exe"
linkerPath = sasmPath + "\\MinGW\\bin\\gcc.exe"
assemblyOptions = "-g -f win32 -o " + objName + " " + sourceName
useShell = False
ioFile = "includes\\io-windows.inc"
macroObj = "objects\\macro.obj"
else:
objName = "tema1.o"
execName = "tema1"
nasmPath = "nasm"
linkerPath = "gcc"
assemblyOptions = "-g -f elf32 -o " + objName + " " + sourceName
useShell = True
macroObj = "objects/macro.o"
ioFile = "includes/io-linux.inc"
shutil.copy(ioFile, "io.inc")
inputFileName = "input.inc"
linkingOptions = objName + " " + macroObj + " -g -o " + execName + " -m32"
numTests = 80
numPassed = 0
header = "======================= Tema 1 IOCLA ======================="
print("\n" + header + "\n")
return_code = subprocess.call(nasmPath + " " + assemblyOptions, shell=useShell)
if return_code != 0:
result = "failed"
else:
return_code = subprocess.call(linkerPath + " " + linkingOptions, shell=useShell)
if return_code != 0:
result = "failed"
for n in range(1, numTests + 1):
shutil.copy("inputs/input" + str(n) + ".txt", inputFileName)
proc = os.popen('.' + os.sep + 'tema1 < ' + inputFileName)
result = proc.read().strip()
proc.close()
expectedResult = open("outputs/output" + str(n) + ".txt").read().strip()
if expectedResult == result:
result = "passed"
numPassed += 1
else:
result = "failed"
start = "Test " + str(n)
print(start + "." * (len(header) - len(result) - len(start)) + result)
totalScore = "Result: " + str(numPassed) + "/" + str(numTests)
print("\n" + " " * (len(header) - len(totalScore)) + totalScore)
os.remove(objName)
os.remove(execName)
os.remove(inputFileName)
os.remove("io.inc")