source: rtems/testsuites/rtems-test-check.py @ 183b0ae

5
Last change on this file since 183b0ae was 06ced25, checked in by Chris Johns <chrisj@…>, on 11/07/18 at 05:09:07

testsuite: Add python verison support to rtems-test-check.py

Closes #3579

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