[258bda3] | 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 | |
---|
[18f63c0] | 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 | |
---|
[258bda3] | 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 | |
---|
[18f63c0] | 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:] |
---|
[258bda3] | 48 | |
---|
[3d803af] | 49 | if verbose: |
---|
| 50 | eprint('cmd: %s' % (' '.join(sys.argv))) |
---|
| 51 | |
---|
[258bda3] | 52 | # |
---|
| 53 | # Handle the modes. |
---|
| 54 | # |
---|
| 55 | if mode == 'exclude': |
---|
| 56 | pass |
---|
| 57 | elif 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) |
---|
| 62 | else: |
---|
| 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 | # |
---|
[18f63c0] | 70 | rtems_testdata = find_testdata(includepaths, os.path.join('testdata', 'rtems.tcfg')) |
---|
| 71 | if rtems_testdata is not None: |
---|
[258bda3] | 72 | testconfig.insert(0, rtems_testdata) |
---|
| 73 | |
---|
| 74 | states = ['exclude', |
---|
| 75 | 'expected-fail', |
---|
| 76 | 'user-input', |
---|
| 77 | 'indeterminate', |
---|
| 78 | 'benchmark'] |
---|
| 79 | defines = { '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' } |
---|
| 83 | output = [] |
---|
| 84 | testdata = {} |
---|
| 85 | |
---|
[18f63c0] | 86 | if verbose: |
---|
| 87 | eprint('mode: %s' % (mode)) |
---|
[3d803af] | 88 | eprint('testconfig: %r' % (testconfig)) |
---|
| 89 | eprint('testconfig: %s' % (', '.join([x for x in testconfig if x is not None]))) |
---|
[18f63c0] | 90 | eprint('includepaths: %s' % (includepaths)) |
---|
| 91 | eprint('bsp: %s' % (bsp)) |
---|
| 92 | eprint('tests: %s' % (', '.join(tests))) |
---|
| 93 | |
---|
[258bda3] | 94 | def 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 | # |
---|
[18f63c0] | 104 | while len(testconfig): |
---|
| 105 | tc = testconfig[0] |
---|
| 106 | testconfig.remove(tc) |
---|
[3d803af] | 107 | if tc is None: |
---|
| 108 | continue |
---|
[18f63c0] | 109 | if verbose: |
---|
| 110 | eprint('reading: %s' % (tc)) |
---|
| 111 | if not os.path.exists(tc): |
---|
| 112 | if verbose: |
---|
| 113 | eprint('%s: not found' % (tc)) |
---|
[258bda3] | 114 | continue |
---|
[18f63c0] | 115 | with open(tc) as f: |
---|
[258bda3] | 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 |
---|
[18f63c0] | 123 | if verbose: |
---|
| 124 | eprint('%4d: %s' % (lc, line)) |
---|
[258bda3] | 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': |
---|
[18f63c0] | 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))) |
---|
[258bda3] | 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 | |
---|
| 149 | for 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 | |
---|
| 158 | print(' '.join(sorted(set(output)))) |
---|
| 159 | |
---|
| 160 | sys.exit(0) |
---|