-
Notifications
You must be signed in to change notification settings - Fork 55
/
floatingpoint.py
102 lines (87 loc) · 2.39 KB
/
floatingpoint.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import os
import subprocess
import sys
# XXX Near duplicates in maketest.py, 02/06/24
def Main():
BuildVPLanet()
dir_list = CollectAllTests()
RemoveOldOutputFiles(dir_list)
print(" ", flush=True)
tot_fail = 0
tot_test = 0
tot_error = 0
for dir in dir_list:
tot_test += 1
sys.stdout.write(dir)
sys.stdout.write(": ")
sys.stdout.flush()
os.chdir(dir)
subdirs = dir.split("/")
test = subdirs[1]
outfile = test + ".floatingpoint"
cmd = "../../../bin/vplanet vpl.in"
with open(outfile, "w+") as f:
subprocess.run(cmd, shell=True, stdout=f, stderr=f)
f = open(outfile, "r")
try:
last_line = f.readlines()[-1]
except:
print("Error")
os.chdir("../../")
tot_error += 1
continue
# print(last_line)
f.close()
if last_line != "Simulation completed.\n":
tot_fail += 1
print("FAIL", flush=True)
else:
print("Pass", flush=True)
os.chdir("../../")
print("")
if tot_fail == 0 and tot_error == 0:
print("No floating point errors found!")
assert True
else:
print(
repr(tot_fail)
+ "/"
+ repr(tot_test)
+ " test(s) failed; "
+ repr(tot_error)
+ "/"
+ repr(tot_test)
+ " test(s) errored."
)
assert False
exit(0)
def BuildVPLanet():
sys.stdout.write("Building VPLanet...")
sys.stdout.flush()
os.chdir("../")
subprocess.check_output(["make", "debug"])
print("done.", flush=True)
os.chdir("tests")
def CollectAllTests():
top_list = sorted(next(os.walk("."))[1])
dir_list = []
for top in top_list:
subdirs = [
os.path.join(top, subdir) for subdir in sorted(next(os.walk(top))[1])
]
for subdir in subdirs:
if "pycache" not in subdir:
dir_list.append(subdir)
return dir_list
def RemoveOldOutputFiles(dir_list):
for dir in dir_list:
os.chdir(dir)
subdirs = dir.split("/")
test = subdirs[1]
outfile = test + ".floatingpoint"
# print (test,outfile)
if os.path.exists(outfile):
os.remove(outfile)
os.chdir("../../")
if __name__ == "__main__":
Main()