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

5
Last change on this file since aa5c462 was aa5c462, checked in by Chris Johns <chrisj@…>, on 11/28/18 at 09:32:46

testsuite: Parse TCFG path based on OS path separator.

  • Property mode set to 100755
File size: 5.4 KB
Line 
1#! /usr/bin/env python
2#
3# Copyright 2018 Chris Johns (chrisj@rtems.org)
4# All rights reserved.
5#
6# This file is part of the RTEMS Tools package in 'rtems-tools'.
7#
8# Redistribution and use in source and binary forms, with or without
9# modification, are permitted provided that the following conditions are met:
10#
11# 1. Redistributions of source code must retain the above copyright notice,
12# this list of conditions and the following disclaimer.
13#
14# 2. Redistributions in binary form must reproduce the above copyright notice,
15# this list of conditions and the following disclaimer in the documentation
16# and/or other materials provided with the distribution.
17#
18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28# POSSIBILITY OF SUCH DAMAGE.
29#
30#
31
32#
33# Python version the rtems-test-check script.
34#
35
36from __future__ import print_function
37
38import os
39import os.path
40import sys
41
42def eprint(*args, **kwargs):
43    print(*args, file=sys.stderr, **kwargs)
44
45#
46# Search the include paths for a file.
47#
48def find_testdata(paths, name):
49    for p in paths:
50        fn = os.path.join(p, name)
51        if os.path.exists(fn):
52            return fn
53    return None
54
55#
56# Arguments. Keep it simple.
57#
58sys_args = sys.argv[1:]
59if len(sys_args) < 4:
60    eprint('error: invalid command line')
61    print('INVALID-TEST-DATA')
62    sys.exit(2)
63
64verbose = False
65args = 0
66
67if sys_args[1] == '-v':
68    verbose = True
69    args = 1
70
71mode = sys_args[args + 1]
72bsp = sys_args[args + 2]
73includepaths = sys_args[args + 4].split(os.pathsep)
74testconfig = [find_testdata(includepaths, sys_args[args + 3])]
75tests = sys_args[args + 5:]
76
77if verbose:
78    eprint('cmd: %s' % (' '.join(sys_args)))
79
80#
81# Handle the modes.
82#
83if mode == 'exclude':
84    pass
85elif mode == 'flags':
86    if len(tests) != 1:
87        eprint('error: test count not 1 for mode: %s' % (mode))
88        print('INVALID-TEST-DATA')
89        sys.exit(1)
90else:
91    eprint('error: invalid mode: %s' % (mode))
92    print('INVALID-TEST-DATA')
93    sys.exit(1)
94
95#
96# Common RTEMS testsuite configuration. Load first.
97#
98rtems_testdata = find_testdata(includepaths, os.path.join('testdata', 'rtems.tcfg'))
99if rtems_testdata is not None:
100    testconfig.insert(0, rtems_testdata)
101
102states = ['exclude',
103          'expected-fail',
104          'user-input',
105          'indeterminate',
106          'benchmark']
107defines = { 'expected-fail' : '-DTEST_STATE_EXPECTED_FAIL=1',
108            'user-input'    : '-DTEST_STATE_USER_INPUT=1',
109            'indeterminate' : '-DTEST_STATE_INDETERMINATE=1',
110            'benchmark'     : '-DTEST_STATE_BENCHMARK=1' }
111output = []
112testdata = {}
113
114if verbose:
115    eprint('mode: %s' % (mode))
116    eprint('testconfig: %r' % (testconfig))
117    eprint('testconfig: %s' % (', '.join([x for x in testconfig if x is not None])))
118    eprint('includepaths: %s' % (includepaths))
119    eprint('bsp: %s' % (bsp))
120    eprint('tests: %s' % (', '.join(tests)))
121
122def clean(line):
123    line = line[0:-1]
124    b = line.find('#')
125    if b >= 0:
126        line = line[1:b]
127    return line.strip()
128
129#
130# Load the test data.
131#
132while len(testconfig):
133    tc = testconfig[0]
134    testconfig.remove(tc)
135    if tc is None:
136        continue
137    if verbose:
138        eprint('reading: %s' % (tc))
139    if not os.path.exists(tc):
140        if verbose:
141            eprint('%s: not found' % (tc))
142        continue
143    with open(tc) as f:
144        tdata = [clean(l) for l in f.readlines()]
145    lc = 0
146    for line in tdata:
147        lc += 1
148        ls = [s.strip() for s in line.split(':')]
149        if len(line) == 0:
150            continue
151        if verbose:
152            eprint('%4d: %s' % (lc, line))
153        if len(ls) != 2:
154            eprint('error: syntax error: %s:%d' % (tc, lc))
155            print('INVALID-TEST-DATA')
156            sys.exit(1)
157        state = ls[0]
158        test = ls[1]
159        if state == 'include':
160            td = find_testdata(includepaths, test)
161            if td is None:
162                eprint('error: include not found: %s:%d' % (tc, lc))
163                print('INVALID-TEST-DATA')
164            testconfig.insert(0, td)
165            if verbose:
166                eprint('include: %s' % (', '.join(testconfig)))
167        elif state in states:
168            if state not in testdata:
169                testdata[state] = [test]
170            else:
171                testdata[state] += [test]
172        else:
173            eprint('error: invalid test state: %s in %s:%d' % (state, tc, lc))
174            print('INVALID-TEST-DATA')
175            sys.exit(1)
176
177for test in tests:
178    if mode == 'exclude':
179        if 'exclude' not in testdata or test not in testdata['exclude']:
180            output += [test]
181    elif mode == 'flags':
182        for state in states:
183            if state != 'exclude' and state in testdata and test in testdata[state]:
184                output += [defines[state]]
185
186print(' '.join(sorted(set(output))))
187
188sys.exit(0)
Note: See TracBrowser for help on using the repository browser.