-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrunalltest.py
executable file
·79 lines (58 loc) · 1.44 KB
/
runalltest.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
#!/usr/bin/python
'''
Runs all tests found in the tests folder.
'''
import runtest, sys, time
from os import walk
from threading import Thread
from Queue import Queue
num_threads = 4
testdir = "tests/"
if len(sys.argv) < 2:
print """
USAGE: runalltests.py <path_to_executable> [testdir]
"""
exit(1)
if len(sys.argv) > 2:
testdir = sys.argv[2];
q = Queue()
for (dirpath, dirnames, filenames) in walk(testdir):
for test in filenames:
if test != ".gitignore":
q.put(test)
if q.empty():
print "No tests found! Please run mktests.py"
exit(1)
print "Found", q.qsize(), "tests."
distances = [0] * (q.qsize())
times = [0] * (q.qsize())
errors = list()
def Work():
while not q.empty():
test = q.get()
#print "Running test:", test
try:
t = int(test)
distance, time = runtest.runtest(sys.argv[1], testdir+str(t))
distances[t] = distance
times[t] = time
except Exception as ex:
errors.append(test + ": " + str(ex))
print str(ex)
q.task_done()
for _ in range(num_threads):
t = Thread(target=Work)
t.daemon = True
t.start()
while not q.empty():
time.sleep(1) # yield
print "Queue size: ", q.qsize()
#for i in range(len(times)):
# print str(i)+","+str(distances[i])+","+str(times[i])
if len(errors) > 0:
print "Errors occured on the following tests: "
for err in errors:
print err
print
print "Average distance: ", sum(distances) / len(distances)
print "Average time: ", sum(times) / len(times)