source: rtems/testsuites/rtems-test-check.py @ bb3484c9

5
Last change on this file since bb3484c9 was 97a48209, checked in by Sebastian Huber <sebastian.huber@…>, on 04/27/18 at 04:18:41

tests: Move rtems-test-check.py

Remove shell script variant.

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