mise à jour des tests

This commit is contained in:
Dimitri Lajou
2025-03-27 14:18:02 +01:00
parent 89abf8f85a
commit eef8242f11
142 changed files with 165 additions and 36 deletions

View File

@@ -20,14 +20,14 @@ def clangName():
clang = clangName()
def runTestNormalLevel(level):
print(f"Running test of level {level}")
stats[level] = (0,0,0,0)
for dirname, dirnames, filenames in os.walk(f'./tests/testlevel{level}'):
def runNormalTestSuit(testSuit):
print(f"Running test suit : {testSuit}")
stats[testSuit] = (0,0,0,0)
for dirname, dirnames, filenames in os.walk(testSuit):
for filename in filenames:
runNormalTest(level, dirname, filename)
runNormalTest(testSuit, dirname, filename)
def runNormalTest(i, dirname,filename):
def runNormalTest(testSuit, dirname,filename):
vslToLLVM = False
llvmToBin = False
executionCorrect = False
@@ -55,29 +55,29 @@ def runNormalTest(i, dirname,filename):
# Exe
if llvmToBin :
executionCorrect = True
try:
input = ""
if os.path.isfile(f"{basename}.test_in"):
p = subprocess.run(f"./{basename} < {basename}.test_in", shell=True, stdout=subprocess.PIPE, timeout=10)
else:
p = subprocess.run(f"./{basename}", shell=True, stdout=subprocess.PIPE, timeout=10)
input = f"< {basename}.test_in"
p = subprocess.run(f"./{basename} " + input, shell=True, stdout=subprocess.PIPE, timeout=5)
except subprocess.TimeoutExpired:
executionCorrect = basename == "./tests/testlevel4/level4diverge"
executionCorrect = "diverge" in basename
# Check return code
if os.path.isfile(f"{basename}.test_ret"):
with open(f"{basename}.test_ret", "r") as expected:
executionCorrect = int(expected.read()) == p.returncode
executionCorrect = executionCorrect and int(expected.read()) == p.returncode
# Check stdout
if os.path.isfile(f"{basename}.test_out"):
with open(f"{basename}.test_out", "rb") as expected:
executionCorrect = executionCorrect and expected.read() == p.stdout
print(f"{colorFromBool(vslToLLVM)}\t\tVSL to LLVM : {'OK' if vslToLLVM else 'Fail'}{Style.RESET_ALL}")
print(f"{colorFromBool(llvmToBin)}\t\tLLVM to Bin : {'OK' if llvmToBin else 'Fail'}{Style.RESET_ALL}")
print(f"{colorFromBool(executionCorrect)}\t\tCorrect Execution : {'OK' if executionCorrect else 'Fail'}{Style.RESET_ALL}")
x,y,z,t = stats[i]
x,y,z,t = stats[testSuit]
if vslToLLVM :
x += 1
if llvmToBin :
@@ -85,7 +85,7 @@ def runNormalTest(i, dirname,filename):
if executionCorrect :
z += 1
t += 1
stats[i] = (x,y,z,t)
stats[testSuit] = (x,y,z,t)
def colorFromBool(b):
if b:
@@ -104,7 +104,7 @@ def afficheStats(stat):
nbError = 0
nbErrorTests = 0
def runErrorTest(dirname,filename):
def runErrorTest(testSuit, dirname,filename):
path = os.path.join(dirname, filename)
basename, ext = os.path.splitext(path)
if ext != ".vsl":
@@ -112,37 +112,51 @@ def runErrorTest(dirname,filename):
print(f'\tRunning test {filename}')
global nbErrorTests
nbErrorTests = nbErrorTests + 1
hasError = False
p = subprocess.run(f"java -jar build/libs/TP2.jar < {path} 1>{basename}.ll", shell=True, stderr=subprocess.PIPE)
if p.returncode != 0 and p.stderr != b'':
print(f"\t\t{Fore.GREEN}Error : Yes{Style.RESET_ALL}")
global nbError
nbError = nbError + 1
return 1
hasError = True
else:
print(f"\t\t{Fore.RED}Error : No{Style.RESET_ALL}")
return 0
hasError = False
def runErrorLevelTests():
print(f"Running test of level error")
for dirname, dirnames, filenames in os.walk(f'./tests/testlevelerror'):
# print path to all filenames.
x,t = stats[testSuit]
if hasError :
x += 1
t += 1
stats[testSuit] = (x,t)
def runErrorLevelTests(testSuit):
print(f"Running test suit : {testSuit}")
stats[testSuit] = (0,0)
for dirname, dirnames, filenames in os.walk(testSuit):
for filename in filenames:
runErrorTest( dirname, filename)
runErrorTest(testSuit, dirname, filename)
def runTests(testDirname):
for i in range(1,5):
runTestNormalLevel(i)
runErrorLevelTests()
def runTests(testDirName):
folderContent = [os.path.join(testDirName, d) for d in os.listdir(testDirName)]
testSuits = [d for d in folderContent if os.path.isdir(d)]
testSuits.sort()
for suit in testSuits:
if "error" in suit or "Error" in suit:
runErrorLevelTests(suit)
else:
runNormalTestSuit(suit)
for suit in testSuits:
print(f'Résumé du test {suit}')
if "error" in suit or "Error" in suit:
nbError, nbErrorTests = stats[suit]
print(f'{colorFromBool(nbError==nbErrorTests)}\t Nombre d\'erreurs : {nbError} / {nbErrorTests}{Style.RESET_ALL}')
else:
afficheStats(stats[suit])
for i in range(1,5):
print(f'Résumé du level {i}')
afficheStats(stats[i])
print(f'Résumé du level error')
print(f'{colorFromBool(nbError==nbErrorTests)}\t Nombre d\'erreurs : {nbError} / {nbErrorTests}{Style.RESET_ALL}')

View File

@@ -1 +1 @@
FUNC INT main() RETURN 0 + 1 + 2
FUNC INT main() RETURN 0 + 1

View File

@@ -0,0 +1 @@
15

1
tests/fragment0/add0.vsl Normal file
View File

@@ -0,0 +1 @@
FUNC INT main() RETURN 7 + 8

View File

@@ -0,0 +1 @@
50

1
tests/fragment0/add1.vsl Normal file
View File

@@ -0,0 +1 @@
FUNC INT main() RETURN 7 + 8 + 5 + 10+10+ 10

View File

@@ -0,0 +1 @@
42

View File

@@ -0,0 +1 @@
FUNC INT main() RETURN 42

View File

@@ -0,0 +1 @@
4

1
tests/fragment0/div0.vsl Normal file
View File

@@ -0,0 +1 @@
FUNC INT main() RETURN 20/5

View File

@@ -0,0 +1 @@
2

1
tests/fragment0/div1.vsl Normal file
View File

@@ -0,0 +1 @@
FUNC INT main() RETURN 12 / 3 / 2

1
tests/fragment0/mod.vsl Normal file
View File

@@ -0,0 +1 @@
FUNC INT main() RETURN 21 % 5

View File

@@ -0,0 +1 @@
20

View File

@@ -0,0 +1 @@
FUNC INT main() RETURN 4*5

View File

@@ -0,0 +1 @@
40

View File

@@ -0,0 +1 @@
FUNC INT main() RETURN 4*5*2

View File

@@ -0,0 +1 @@
120

View File

@@ -0,0 +1 @@
FUNC INT main() RETURN 4 * (6 + 4) * 3

View File

@@ -0,0 +1 @@
37

View File

@@ -0,0 +1 @@
FUNC INT main() RETURN 4 + 6 * 5 + 3

View File

@@ -0,0 +1 @@
8

View File

@@ -0,0 +1 @@
FUNC INT main() RETURN 1 + 2 * (4 + 5 % 3 + 2) - 3 - 16 / 8 - 4

View File

@@ -0,0 +1 @@
3

1
tests/fragment0/sub0.vsl Normal file
View File

@@ -0,0 +1 @@
FUNC INT main() RETURN 8-5

View File

@@ -0,0 +1 @@
85

1
tests/fragment0/sub1.vsl Normal file
View File

@@ -0,0 +1 @@
FUNC INT main() RETURN 100 + (10 - 20 - 5)

View File

@@ -0,0 +1,5 @@
FUNC INT main() {
INT x
x := 1
RETURN x
}

View File

@@ -0,0 +1,6 @@
FUNC INT main() {
INT x, y
x := 1
y := x
RETURN y
}

View File

@@ -0,0 +1 @@
2

4
tests/fragment1/decl.vsl Normal file
View File

@@ -0,0 +1,4 @@
FUNC INT main() {
INT x
RETURN 2
}

View File

@@ -0,0 +1 @@
1

View File

@@ -0,0 +1 @@
1

View File

@@ -0,0 +1 @@
1

View File

@@ -5,3 +5,4 @@
5+1 = 6
5* (5+7) = 60
5* 5+7 = 32
-2 = -2

View File

@@ -6,5 +6,6 @@ FUNC VOID main() {
PRINT 5,"+",1," = ", 5+1 ,"\n"
PRINT 5,"* (",5,"+",7,") = ", 5*(5+7) ,"\n"
PRINT 5,"* ",5,"+",7," = ", 5 * 5 + 7 ,"\n"
PRINT "-2 = ", -2
}

View File

@@ -0,0 +1,3 @@
2
7

View File

@@ -0,0 +1 @@
x vaut 2 et y vaut 7

View File

@@ -0,0 +1,5 @@
FUNC VOID main() {
INT x,y
READ x, y
PRINT "x vaut ",x," et y vaut ",y
}

View File

@@ -0,0 +1 @@
84

View File

@@ -0,0 +1,10 @@
FUNC INT main() {
INT x, y x :=
42 y:=0
WHILE x DO {
x := x - 1
y := y + 2
} DONE
RETURN y
}

Some files were not shown because too many files have changed in this diff Show More