author | Craig Dowell <craigdo@ee.washington.edu> |
Wed, 26 Mar 2008 01:33:41 -0700 | |
changeset 2849 | fe96c0d98484 |
parent 2847 | f0aedbbb037b |
child 2855 | e1063ecd1585 |
permissions | -rw-r--r-- |
2846
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1 |
#! /usr/bin/env python |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
2 |
# regression.py adapted from python language regression scripts. |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
3 |
|
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
4 |
"""Regression test. |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
5 |
|
2849
fe96c0d98484
some tests and known traces
Craig Dowell <craigdo@ee.washington.edu>
parents:
2847
diff
changeset
|
6 |
This will find all modules whose name is "test-*" in the tests |
2846
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
7 |
directory, and run them. |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
8 |
|
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
9 |
Command line options: |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
10 |
|
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
11 |
-v: verbose -- run tests in verbose mode with output to stdout |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
12 |
-g: generate -- write the output file for a test instead of comparing it |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
13 |
|
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
14 |
If non-option arguments are present, they are names for tests to run. |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
15 |
If no test names are given, all tests are run. |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
16 |
|
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
17 |
""" |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
18 |
|
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
19 |
import sys |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
20 |
import os |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
21 |
import getopt |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
22 |
|
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
23 |
verbose = 0 |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
24 |
generate = 0 |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
25 |
|
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
26 |
def main(tests = None, testdir = None): |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
27 |
"""Execute regression tests. |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
28 |
|
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
29 |
Arguments: |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
30 |
tests -- a list of strings containing test names (optional) |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
31 |
testdir -- the directory in which to look for tests (optional) |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
32 |
""" |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
33 |
|
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
34 |
global verbose |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
35 |
global generate |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
36 |
|
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
37 |
try: |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
38 |
opts, args = getopt.getopt(sys.argv[1:], 'vg') |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
39 |
except getopt.error, msg: |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
40 |
print msg |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
41 |
print __doc__ |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
42 |
return 2 |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
43 |
|
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
44 |
for o, a in opts: |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
45 |
if o == '-v': verbose = 1 |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
46 |
if o == '-g': generate = 1 |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
47 |
|
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
48 |
bad = [] |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
49 |
|
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
50 |
if not testdir: |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
51 |
testdir = os.path.join(os.curdir, "tests") |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
52 |
|
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
53 |
if not os.path.exists(testdir): |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
54 |
print "Tests directory does not exist" |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
55 |
return 3 |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
56 |
|
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
57 |
if verbose: |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
58 |
print "tests directory: ", testdir |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
59 |
|
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
60 |
sys.path.append(testdir) |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
61 |
|
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
62 |
for i in range(len(args)): |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
63 |
if args[i][-3:] == '.py': |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
64 |
args[i] = args[i][:-3] |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
65 |
|
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
66 |
if not tests: |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
67 |
tests = args |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
68 |
|
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
69 |
if not tests: |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
70 |
tests = findtests(testdir) |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
71 |
|
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
72 |
for test in tests: |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
73 |
if verbose: |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
74 |
print "main(): running test", test |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
75 |
result = runtest(test) |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
76 |
if result == 0: |
2847
f0aedbbb037b
trace generation and comparison
Craig Dowell <craigdo@ee.washington.edu>
parents:
2846
diff
changeset
|
77 |
if generate: |
f0aedbbb037b
trace generation and comparison
Craig Dowell <craigdo@ee.washington.edu>
parents:
2846
diff
changeset
|
78 |
print "GENERATE ", test |
f0aedbbb037b
trace generation and comparison
Craig Dowell <craigdo@ee.washington.edu>
parents:
2846
diff
changeset
|
79 |
else: |
f0aedbbb037b
trace generation and comparison
Craig Dowell <craigdo@ee.washington.edu>
parents:
2846
diff
changeset
|
80 |
print "PASS ", test |
2846
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
81 |
else: |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
82 |
bad.append(test) |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
83 |
print "FAIL ", test |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
84 |
|
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
85 |
return len(bad) > 0 |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
86 |
|
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
87 |
def findtests(testdir): |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
88 |
"""Return a list of test modules in the test directory |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
89 |
|
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
90 |
Arguments: |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
91 |
testdir -- the directory to look in for tests |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
92 |
""" |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
93 |
if verbose: |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
94 |
print "findtests(", testdir, ")" |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
95 |
if verbose: |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
96 |
print "findtests(): look in ", testdir |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
97 |
|
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
98 |
names = os.listdir(testdir) |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
99 |
if verbose: |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
100 |
print "findtests(): found ", names |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
101 |
tests = [] |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
102 |
for name in names: |
2849
fe96c0d98484
some tests and known traces
Craig Dowell <craigdo@ee.washington.edu>
parents:
2847
diff
changeset
|
103 |
if name[:5] == "test-" and name[-3:] == ".py": |
2846
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
104 |
testname = name[:-3] |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
105 |
tests.append(testname) |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
106 |
tests.sort() |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
107 |
if verbose: |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
108 |
print "findtests(): found tests ", tests |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
109 |
return tests |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
110 |
|
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
111 |
def runtest(test): |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
112 |
"""Run a single test. |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
113 |
|
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
114 |
Arguments: |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
115 |
test -- the name of the test |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
116 |
""" |
2847
f0aedbbb037b
trace generation and comparison
Craig Dowell <craigdo@ee.washington.edu>
parents:
2846
diff
changeset
|
117 |
if os.path.exists("traces"): |
f0aedbbb037b
trace generation and comparison
Craig Dowell <craigdo@ee.washington.edu>
parents:
2846
diff
changeset
|
118 |
files = os.listdir("traces") |
f0aedbbb037b
trace generation and comparison
Craig Dowell <craigdo@ee.washington.edu>
parents:
2846
diff
changeset
|
119 |
for file in files: |
f0aedbbb037b
trace generation and comparison
Craig Dowell <craigdo@ee.washington.edu>
parents:
2846
diff
changeset
|
120 |
if file == '.' or file == '..': |
f0aedbbb037b
trace generation and comparison
Craig Dowell <craigdo@ee.washington.edu>
parents:
2846
diff
changeset
|
121 |
continue |
f0aedbbb037b
trace generation and comparison
Craig Dowell <craigdo@ee.washington.edu>
parents:
2846
diff
changeset
|
122 |
path = "traces" + os.sep + file |
f0aedbbb037b
trace generation and comparison
Craig Dowell <craigdo@ee.washington.edu>
parents:
2846
diff
changeset
|
123 |
os.remove(path) |
f0aedbbb037b
trace generation and comparison
Craig Dowell <craigdo@ee.washington.edu>
parents:
2846
diff
changeset
|
124 |
else: |
f0aedbbb037b
trace generation and comparison
Craig Dowell <craigdo@ee.washington.edu>
parents:
2846
diff
changeset
|
125 |
os.mkdir("traces") |
f0aedbbb037b
trace generation and comparison
Craig Dowell <craigdo@ee.washington.edu>
parents:
2846
diff
changeset
|
126 |
|
2846
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
127 |
if verbose: |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
128 |
print "runtest(): run ", test |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
129 |
mod = __import__(test, globals(), locals(), []) |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
130 |
return mod.run(verbose, generate) |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
131 |
|
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
132 |
if __name__ == '__main__': |
7689461231ac
start of regression tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
133 |
sys.exit(main()) |