-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathrunner.py
executable file
·130 lines (111 loc) · 4.27 KB
/
runner.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env python
import os
import sys
testroot = ""
class Profile:
def __init__(self,name):
self.name = name
#get the tags from the file
class Test:
def __init__(self,name):
self.name = name
def directory(self):
return os.join("tests",name)
def execute(self, profile, build, action):
myscript = """
source %(testroot)s/loadTest %(build)s %(profile)s %(testname)s;
%(action)s;
""" % {
"profile" : profile.name,
"build" : build,
"action" : action,
"testname" : self.name,
"testroot" : testroot,
}
bash_pipe = os.popen("bash", "w", len(myscript))
print >>bash_pipe, myscript
def nameFromTestDir(dirname):
return os.path.relpath(dirname,os.path.join(testroot, "tests"))
def main():
global testroot
testroot = os.path.dirname(os.path.realpath(__file__))
print testroot
import sys
import argparse
ap = argparse.ArgumentParser(description="Run all the tests for the Cardioid framework.")
ap.add_argument("--profile", "-p",
help="Runtime profile to use for the tests.",
type=str,
default="seq",
)
ap.add_argument("--build", "-b",
help="What build of the code we should use.",
type=str,
default="osx",
)
ap.add_argument("--action", "-a",
help="What action should be performed on the tests",
type=str,
default="run"
)
#ap.add_argument("--runtime", "-r",
# help="Keep the total running time near the time specified.",
# type=str,
# default="10m",
# )
#ap.add_argument("--tags", "-t",
# help="Only run tests that match (all) the following tags.",
# action="append",
# default=[],
# )
#ap.add_argument("--update-runtimes", "-u",
# help="Update the running times for all the tests we run",
# type=str,
# default=""
# )
ap.add_argument("tests", nargs=argparse.REMAINDER,
help="list of all the manually specified tests we want to run",
)
options = ap.parse_args()
#create the profile
profile = Profile(options.profile)
manualTests = []
for name in options.tests:
manualTests.append(Test(name))
#scan the directory for candidate tests
if manualTests:
runnableTests = manualTests
else:
runnableTests = []
allsubdirs = [x[0] for x in os.walk(os.path.join(testroot, "tests"))]
for subdir in allsubdirs:
definitionFilename=os.path.join(subdir,"definition")
if os.path.isfile(definitionFilename):
#scan the test looking for tags.
#if the tags match add it to the list of tests.
runnableTests.append(Test(nameFromTestDir(subdir)))
#sort the runnableTests by runtime.
if options.action == "run":
if len(runnableTests):
print "1.."+str(len(runnableTests))
testCounter=1
for test in runnableTests:
resultFile = os.path.join(testroot, "scratch", options.build, profile.name, test.name, "result")
if os.path.isfile(resultFile):
os.remove(resultFile)
test.execute(profile, options.build, options.action)
if not os.path.isfile(resultFile):
print "not ok %d %s" % (testCounter, test.name)
print "# missing result file %s" % resultFile
elif os.stat(resultFile).st_size != 0:
print "not ok %d %s" % (testCounter, test.name)
for line in open(resultFile, "r"):
print "# "+line.rstrip()
else:
print "ok %d %s" % (testCounter, test.name)
testCounter += 1
else:
for test in runnableTests:
test.execute(profile, options.build, options.action)
if __name__=='__main__':
main()