-
Notifications
You must be signed in to change notification settings - Fork 55
/
valgrind.py
78 lines (65 loc) · 1.93 KB
/
valgrind.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
import os
import subprocess
import sys
# XXX Near duplicates in maketest.py, 02/06/24
def Main():
BuildVPLanet()
dir_list = CollectAllTests()
tot_fail = 0
tot_test = 0
logfile = open("memcheck.log","w")
logfile.write("The following directories were NOT memcheck clean:\n")
for dir in dir_list:
tot_test += 1
sys.stdout.write(dir)
sys.stdout.flush()
os.chdir(dir)
subdirs = dir.split("/")
test = subdirs[1]
outfile = test + ".valgrind"
cmd = "/usr/bin/valgrind --track-origins=yes ../../../bin/vplanet vpl.in"
with open(outfile, "w+") as f:
subprocess.run(cmd, shell=True, stdout=f, stderr=f)
f = open(outfile, "r")
last_line = f.readlines()[-1]
# print(last_line)
f.close()
words = last_line.split()
n_errors = int(words[3])
if n_errors > 0:
tot_fail += 1
print(": FAIL",flush=True)
logfile.write(dir+'\n')
else:
print(": pass",flush=True)
os.chdir("../../")
logfile.close()
print("Done! ")
if tot_fail == 0:
print("VPLanet is mem-check-clean!")
assert True
else:
print(repr(tot_fail) + "/" + repr(tot_test) + " test(s) failed.")
assert False
exit(0)
def BuildVPLanet():
sys.stdout.write("Building VPLanet...")
sys.stdout.flush()
os.chdir("../")
subprocess.check_output(["make", "opt"])
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)
print(" ", flush=True)
return dir_list
if __name__ == "__main__":
Main()