source: rtems/tools/build/rtems-test-check-py @ 4fd25c4

5
Last change on this file since 4fd25c4 was 18f63c0, checked in by Chris Johns <chrisj@…>, on 04/15/17 at 23:51:57

testsuite: Fix rtems-test-check not excluding tests.

The include file handling was broken.

Add a test configuration data README.

Closes #2981.

  • Property mode set to 100755
File size: 3.9 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
49#
50# Handle the modes.
51#
52if mode == 'exclude':
53    pass
54elif 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)
59else:
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#
67rtems_testdata = find_testdata(includepaths, os.path.join('testdata', 'rtems.tcfg'))
68if rtems_testdata is not None:
69    testconfig.insert(0, rtems_testdata)
70
71states = ['exclude',
72          'expected-fail',
73          'user-input',
74          'indeterminate',
75          'benchmark']
76defines = { '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' }
80output = []
81testdata = {}
82
83if 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
90def 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#
100while 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
143for 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
152print(' '.join(sorted(set(output))))
153
154sys.exit(0)
Note: See TracBrowser for help on using the repository browser.