1 | #! /usr/bin/env python |
---|
2 | # |
---|
3 | # Copyright 2017 Chris Johns <chrisj@rtems.org> |
---|
4 | # All rights reserved |
---|
5 | # |
---|
6 | |
---|
7 | # |
---|
8 | # Python version the rtems-test-check script. |
---|
9 | # |
---|
10 | |
---|
11 | from __future__ import print_function |
---|
12 | import os.path |
---|
13 | import sys |
---|
14 | |
---|
15 | def eprint(*args, **kwargs): |
---|
16 | print(*args, file=sys.stderr, **kwargs) |
---|
17 | |
---|
18 | # |
---|
19 | # Search the include paths for a file. |
---|
20 | # |
---|
21 | def find_testdata(paths, name): |
---|
22 | for p in paths: |
---|
23 | fn = os.path.join(p, name) |
---|
24 | if os.path.exists(fn): |
---|
25 | return fn |
---|
26 | return None |
---|
27 | |
---|
28 | # |
---|
29 | # Arguments. Keep it simple. |
---|
30 | # |
---|
31 | if len(sys.argv) < 4: |
---|
32 | eprint('error: invalid command line') |
---|
33 | print('INVALID-TEST-DATA') |
---|
34 | sys.exit(2) |
---|
35 | |
---|
36 | verbose = False |
---|
37 | args = 0 |
---|
38 | |
---|
39 | if sys.argv[1] == '-v': |
---|
40 | verbose = True |
---|
41 | args = 1 |
---|
42 | |
---|
43 | mode = sys.argv[args + 1] |
---|
44 | bsp = sys.argv[args + 2] |
---|
45 | includepaths = sys.argv[args + 4].split(':') |
---|
46 | testconfig = [find_testdata(includepaths, sys.argv[args + 3])] |
---|
47 | tests = sys.argv[args + 5:] |
---|
48 | |
---|
49 | # |
---|
50 | # Handle the modes. |
---|
51 | # |
---|
52 | if mode == 'exclude': |
---|
53 | pass |
---|
54 | elif mode == 'flags': |
---|
55 | if len(tests) != 1: |
---|
56 | eprint('error: test count not 1 for mode: %s' % (mode)) |
---|
57 | print('INVALID-TEST-DATA') |
---|
58 | sys.exit(1) |
---|
59 | else: |
---|
60 | eprint('error: invalid mode: %s' % (mode)) |
---|
61 | print('INVALID-TEST-DATA') |
---|
62 | sys.exit(1) |
---|
63 | |
---|
64 | # |
---|
65 | # Common RTEMS testsuite configuration. Load first. |
---|
66 | # |
---|
67 | rtems_testdata = find_testdata(includepaths, os.path.join('testdata', 'rtems.tcfg')) |
---|
68 | if rtems_testdata is not None: |
---|
69 | testconfig.insert(0, rtems_testdata) |
---|
70 | |
---|
71 | states = ['exclude', |
---|
72 | 'expected-fail', |
---|
73 | 'user-input', |
---|
74 | 'indeterminate', |
---|
75 | 'benchmark'] |
---|
76 | defines = { 'expected-fail' : '-DTEST_STATE_EXPECTED_FAIL=1', |
---|
77 | 'user-input' : '-DTEST_STATE_USER_INPUT=1', |
---|
78 | 'indeterminate' : '-DTEST_STATE_INDETERMINATE=1', |
---|
79 | 'benchmark' : '-DTEST_STATE_BENCHMARK=1' } |
---|
80 | output = [] |
---|
81 | testdata = {} |
---|
82 | |
---|
83 | if verbose: |
---|
84 | eprint('mode: %s' % (mode)) |
---|
85 | eprint('testconfig: %s' % (', '.join(testconfig))) |
---|
86 | eprint('includepaths: %s' % (includepaths)) |
---|
87 | eprint('bsp: %s' % (bsp)) |
---|
88 | eprint('tests: %s' % (', '.join(tests))) |
---|
89 | |
---|
90 | def clean(line): |
---|
91 | line = line[0:-1] |
---|
92 | b = line.find('#') |
---|
93 | if b >= 0: |
---|
94 | line = line[1:b] |
---|
95 | return line.strip() |
---|
96 | |
---|
97 | # |
---|
98 | # Load the test data. |
---|
99 | # |
---|
100 | while len(testconfig): |
---|
101 | tc = testconfig[0] |
---|
102 | testconfig.remove(tc) |
---|
103 | if verbose: |
---|
104 | eprint('reading: %s' % (tc)) |
---|
105 | if not os.path.exists(tc): |
---|
106 | if verbose: |
---|
107 | eprint('%s: not found' % (tc)) |
---|
108 | continue |
---|
109 | with open(tc) as f: |
---|
110 | tdata = [clean(l) for l in f.readlines()] |
---|
111 | lc = 0 |
---|
112 | for line in tdata: |
---|
113 | lc += 1 |
---|
114 | ls = [s.strip() for s in line.split(':')] |
---|
115 | if len(line) == 0: |
---|
116 | continue |
---|
117 | if verbose: |
---|
118 | eprint('%4d: %s' % (lc, line)) |
---|
119 | if len(ls) != 2: |
---|
120 | eprint('error: syntax error: %s:%d' % (tc, lc)) |
---|
121 | print('INVALID-TEST-DATA') |
---|
122 | sys.exit(1) |
---|
123 | state = ls[0] |
---|
124 | test = ls[1] |
---|
125 | if state == 'include': |
---|
126 | td = find_testdata(includepaths, test) |
---|
127 | if td is None: |
---|
128 | eprint('error: include not found: %s:%d' % (tc, lc)) |
---|
129 | print('INVALID-TEST-DATA') |
---|
130 | testconfig.insert(0, td) |
---|
131 | if verbose: |
---|
132 | eprint('include: %s' % (', '.join(testconfig))) |
---|
133 | elif state in states: |
---|
134 | if state not in testdata: |
---|
135 | testdata[state] = [test] |
---|
136 | else: |
---|
137 | testdata[state] += [test] |
---|
138 | else: |
---|
139 | eprint('error: invalid test state: %s in %s:%d' % (state, tc, lc)) |
---|
140 | print('INVALID-TEST-DATA') |
---|
141 | sys.exit(1) |
---|
142 | |
---|
143 | for test in tests: |
---|
144 | if mode == 'exclude': |
---|
145 | if 'exclude' not in testdata or test not in testdata['exclude']: |
---|
146 | output += [test] |
---|
147 | elif mode == 'flags': |
---|
148 | for state in states: |
---|
149 | if state != 'exclude' and state in testdata and test in testdata[state]: |
---|
150 | output += [defines[state]] |
---|
151 | |
---|
152 | print(' '.join(sorted(set(output)))) |
---|
153 | |
---|
154 | sys.exit(0) |
---|