1 | # |
---|
2 | # RTEMS Tools Project (http://www.rtems.org/) |
---|
3 | # Copyright 2013, 2020 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 | from __future__ import print_function |
---|
32 | |
---|
33 | import copy |
---|
34 | import datetime |
---|
35 | import sys |
---|
36 | import threading |
---|
37 | |
---|
38 | from rtemstoolkit import error |
---|
39 | from rtemstoolkit import host |
---|
40 | from rtemstoolkit import log |
---|
41 | from rtemstoolkit import path |
---|
42 | from rtemstoolkit import stacktraces |
---|
43 | from rtemstoolkit import version |
---|
44 | |
---|
45 | import tester.rt.bsps |
---|
46 | import tester.rt.config |
---|
47 | import tester.rt.console |
---|
48 | import tester.rt.options |
---|
49 | import tester.rt.report |
---|
50 | |
---|
51 | class test(object): |
---|
52 | def __init__(self, index, total, report, executable, rtems_tools, bsp, bsp_config, opts): |
---|
53 | self.index = index |
---|
54 | self.total = total |
---|
55 | self.report = report |
---|
56 | self.bsp = bsp |
---|
57 | self.bsp_config = bsp_config |
---|
58 | self.opts = copy.copy(opts) |
---|
59 | self.opts.defaults['test_index'] = str(index) |
---|
60 | self.opts.defaults['test_total'] = str(total) |
---|
61 | self.opts.defaults['bsp'] = bsp |
---|
62 | self.opts.defaults['bsp_arch'] = '%{arch}' |
---|
63 | if not path.isfile(executable): |
---|
64 | raise error.general('cannot find executable: %s' % (executable)) |
---|
65 | self.opts.defaults['test_executable'] = executable |
---|
66 | if rtems_tools: |
---|
67 | rtems_tools_bin = path.join(self.opts.defaults.expand(rtems_tools), 'bin') |
---|
68 | if not path.isdir(rtems_tools_bin): |
---|
69 | raise error.general('cannot find RTEMS tools path: %s' % (rtems_tools_bin)) |
---|
70 | self.opts.defaults['rtems_tools'] = rtems_tools_bin |
---|
71 | self.config = tester.rt.config.file(index, total, self.report, self.bsp_config, self.opts, '') |
---|
72 | |
---|
73 | def run(self): |
---|
74 | if self.config: |
---|
75 | self.config.run() |
---|
76 | |
---|
77 | def kill(self): |
---|
78 | if self.config: |
---|
79 | self.config.kill() |
---|
80 | |
---|
81 | def find_executables(files): |
---|
82 | executables = [] |
---|
83 | for f in files: |
---|
84 | if not path.isfile(f): |
---|
85 | raise error.general('executable is not a file: %s' % (f)) |
---|
86 | executables += [f] |
---|
87 | return sorted(executables) |
---|
88 | |
---|
89 | def list_bsps(opts): |
---|
90 | path_ = opts.defaults.expand('%%{_configdir}/bsps/*.mc') |
---|
91 | bsps = path.collect_files(path_) |
---|
92 | log.notice(' BSP List:') |
---|
93 | for bsp in bsps: |
---|
94 | log.notice(' %s' % (path.basename(bsp[:-3]))) |
---|
95 | raise error.exit() |
---|
96 | |
---|
97 | def run(args): |
---|
98 | tests = [] |
---|
99 | stdtty = tester.rt.console.save() |
---|
100 | opts = None |
---|
101 | default_exefilter = '*.exe' |
---|
102 | try: |
---|
103 | optargs = { '--rtems-tools': 'The path to the RTEMS tools', |
---|
104 | '--rtems-bsp': 'The RTEMS BSP to run the test on', |
---|
105 | '--user-config': 'Path to your local user configuration INI file', |
---|
106 | '--list-bsps': 'List the supported BSPs', |
---|
107 | '--debug-trace': 'Debug trace based on specific flags', |
---|
108 | '--stacktrace': 'Dump a stack trace on a user termination (^C)' } |
---|
109 | opts = tester.rt.options.load(args, optargs = optargs) |
---|
110 | log.notice('RTEMS Testing - Run, %s' % (version.string())) |
---|
111 | if opts.find_arg('--list-bsps'): |
---|
112 | tester.rt.bsps.list(opts) |
---|
113 | opts.log_info() |
---|
114 | log.output('Host: ' + host.label(mode = 'all')) |
---|
115 | debug_trace = opts.find_arg('--debug-trace') |
---|
116 | if debug_trace: |
---|
117 | if len(debug_trace) != 1: |
---|
118 | debug_trace = 'output,' + debug_trace[1] |
---|
119 | else: |
---|
120 | raise error.general('no debug flags, can be: console,gdb,output') |
---|
121 | else: |
---|
122 | debug_trace = 'output' |
---|
123 | opts.defaults['debug_trace'] = debug_trace |
---|
124 | rtems_tools = opts.find_arg('--rtems-tools') |
---|
125 | if rtems_tools: |
---|
126 | if len(rtems_tools) != 2: |
---|
127 | raise error.general('invalid RTEMS tools option') |
---|
128 | rtems_tools = rtems_tools[1] |
---|
129 | else: |
---|
130 | rtems_tools = '%{_prefix}' |
---|
131 | bsp = opts.find_arg('--rtems-bsp') |
---|
132 | if bsp is None or len(bsp) != 2: |
---|
133 | raise error.general('RTEMS BSP not provided or an invalid option') |
---|
134 | bsp = tester.rt.config.load(bsp[1], opts) |
---|
135 | bsp_config = opts.defaults.expand(opts.defaults['tester']) |
---|
136 | executables = find_executables(opts.params()) |
---|
137 | if len(executables) != 1: |
---|
138 | raise error.general('one executable required, found %d' % (len(executables))) |
---|
139 | opts.defaults['test_disable_header'] = '1' |
---|
140 | reports = tester.rt.report.report(1) |
---|
141 | start_time = datetime.datetime.now() |
---|
142 | opts.defaults['exe_trace'] = debug_trace |
---|
143 | tst = test(1, 1, reports, executables[0], rtems_tools, bsp, bsp_config, opts) |
---|
144 | tst.run() |
---|
145 | end_time = datetime.datetime.now() |
---|
146 | total_time = 'Run time : %s' % (str(end_time - start_time)) |
---|
147 | log.notice(total_time) |
---|
148 | |
---|
149 | except error.general as gerr: |
---|
150 | print(gerr) |
---|
151 | sys.exit(1) |
---|
152 | except error.internal as ierr: |
---|
153 | print(ierr) |
---|
154 | sys.exit(1) |
---|
155 | except error.exit: |
---|
156 | sys.exit(2) |
---|
157 | except KeyboardInterrupt: |
---|
158 | if opts is not None and opts.find_arg('--stacktrace'): |
---|
159 | print('}} dumping:', threading.active_count()) |
---|
160 | for t in threading.enumerate(): |
---|
161 | print('}} ', t.name) |
---|
162 | print(stacktraces.trace()) |
---|
163 | log.notice('abort: user terminated') |
---|
164 | sys.exit(1) |
---|
165 | finally: |
---|
166 | tester.rt.console.restore(stdtty) |
---|
167 | sys.exit(0) |
---|
168 | |
---|
169 | if __name__ == "__main__": |
---|
170 | run() |
---|