aboutsummaryrefslogtreecommitdiffstats
path: root/tests/make_catalog.py
diff options
context:
space:
mode:
authorBjoern B. Brandenburg <bbb@cs.unc.edu>2010-02-20 21:48:29 -0500
committerBjoern B. Brandenburg <bbb@cs.unc.edu>2010-02-20 21:48:29 -0500
commitf3d21c128e5b40acd1f15e3ddcd7fd54ca3a9bed (patch)
treedf9d7ed4b1948e04437d046b5ed2f85949993edb /tests/make_catalog.py
parent8a1912c177e978574250cf80f8a50edf7424b158 (diff)
Introduce test framework for LITMUS^RT.
This is the beginning of the LITMUS^RT testsuite. The main design goals are flexibility and ease of test writing. To create a new test, simply write a test case in any C file in the tests/ subdirectory. The buildsystem will find the test and hook it up with the testrunner. Have a look at tests/fdso.c and include/tests.h to get an idea for what tests look like. Tests can be executed with the 'runtests' tool. Each testcase is executed in a separate process in order to ensure that tests do not influence each other.
Diffstat (limited to 'tests/make_catalog.py')
-rwxr-xr-xtests/make_catalog.py95
1 files changed, 95 insertions, 0 deletions
diff --git a/tests/make_catalog.py b/tests/make_catalog.py
new file mode 100755
index 0000000..75b6aca
--- /dev/null
+++ b/tests/make_catalog.py
@@ -0,0 +1,95 @@
1#!/usr/bin/env python
2
3import re
4import sys
5
6class TestCase(object):
7 def __init__(self, function, plugins, desc):
8 self.function = function
9 self.plugins = plugins
10 self.desc = desc
11
12 def __str__(self):
13 return 'TESTCASE(%s, %s, "%s")' % \
14 (self.function, " | ".join(self.plugins), self.desc)
15
16
17class Finder(object):
18 def __init__(self):
19 self.found = []
20 self.regex = re.compile(
21 "TESTCASE\\("
22 "\\s*([a-zA-z_0-9]+)\\s*," # function name
23 "\\s*([- |a-zA-z_0-9]+)\\s*," # plugins
24 "\\s*\"([^\"]*)\"\\s*" # description
25 "\\)"
26 , re.MULTILINE)
27
28 def search_file(self, fname):
29 f = open(fname, "r")
30 src = ''.join(f)
31 f.close()
32 matches = self.regex.findall(src)
33 del src
34
35 for m in matches:
36 name = m[0]
37 plugins = m[1].split('|')
38 desc = m[2]
39 plugins = [p.strip() for p in plugins]
40 self.found.append(TestCase(name, plugins, desc))
41
42
43def search_files(args=sys.argv[1:]):
44 f = Finder()
45 for fname in args:
46 try:
47 f.search_file(fname)
48 except IOError, msg:
49 sys.stderr.write("%s: %s\n" % (fname, msg))
50 sys.exit(1)
51 return f.found
52
53
54def create_tc_tables(out=sys.stdout):
55 def _(o):
56 out.write("%s\n" % str(o))
57
58 tests = search_files()
59
60 plugins = set()
61 for tc in tests:
62 for p in tc.plugins:
63 plugins.add(p)
64
65 plugins.discard('ALL')
66
67 _('#include "tests.h"')
68
69 for tc in tests:
70 _('void test_%s(void);' % tc.function)
71
72 _('struct testcase test_catalog[] = {')
73 for tc in tests:
74 _('\t{test_%s, "%s"},' % (tc.function, tc.desc))
75 _('};')
76
77 for p in plugins:
78 count = 0
79 _('int %s_TESTS[] = {' % p)
80 for (i, tc) in enumerate(tests):
81 if p in tc.plugins or 'ALL' in tc.plugins:
82 _('\t%d,' % i)
83 count += 1
84 _('};')
85 _('#define NUM_%s_TESTS %d' % (p, count))
86
87 _('struct testsuite testsuite[] = {')
88 for p in plugins:
89 _('\t{"%s", %s_TESTS, NUM_%s_TESTS},' % (p.replace('_', '-'), p, p))
90 _('};')
91 _('#define NUM_PLUGINS %s' % len(plugins))
92
93if __name__ == '__main__':
94 create_tc_tables()
95