source: rtems-tools/tester/rt/run.py @ e058db0

5
Last change on this file since e058db0 was e058db0, checked in by Chris Johns <chrisj@…>, on 11/07/18 at 03:55:20

python: Provide support to select a valid python version.

  • Update imports after wrapping the code.
  • Fix python3 issues.
  • Fix config path issues for in repo and install runs.

Closes #3537

  • Property mode set to 100644
File size: 6.5 KB
RevLine 
[c68beb8]1#
2# RTEMS Tools Project (http://www.rtems.org/)
3# Copyright 2013-2017 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
31from __future__ import print_function
32
33import copy
34import datetime
35import sys
36import threading
37
38from rtemstoolkit import error
39from rtemstoolkit import host
40from rtemstoolkit import log
41from rtemstoolkit import path
42from rtemstoolkit import stacktraces
43from rtemstoolkit import version
44
[e058db0]45import bsps
46import config
47import console
48import options
49import report
[c68beb8]50
51class 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 = 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
81def 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
89def 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
[e058db0]97def run(args, command_path = None):
[c68beb8]98    tests = []
99    stdtty = 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)' }
[e058db0]109        opts = options.load(args,
[c68beb8]110                            optargs = optargs,
111                            command_path = command_path)
[3bd8def]112        log.notice('RTEMS Testing - Run, %s' % (version.string()))
[c68beb8]113        if opts.find_arg('--list-bsps'):
114            bsps.list(opts)
115        opts.log_info()
116        log.output('Host: ' + host.label(mode = 'all'))
117        debug_trace = opts.find_arg('--debug-trace')
118        if debug_trace:
119            if len(debug_trace) != 1:
120                debug_trace = 'output,' + debug_trace[1]
121            else:
122                raise error.general('no debug flags, can be: console,gdb,output')
123        else:
124            debug_trace = 'output'
125        opts.defaults['debug_trace'] = debug_trace
126        rtems_tools = opts.find_arg('--rtems-tools')
127        if rtems_tools:
128            if len(rtems_tools) != 2:
129                raise error.general('invalid RTEMS tools option')
130            rtems_tools = rtems_tools[1]
131        else:
132            rtems_tools = '%{_prefix}'
133        bsp = opts.find_arg('--rtems-bsp')
134        if bsp is None or len(bsp) != 2:
135            raise error.general('RTEMS BSP not provided or an invalid option')
136        bsp = config.load(bsp[1], opts)
137        bsp_config = opts.defaults.expand(opts.defaults['tester'])
138        executables = find_executables(opts.params())
139        if len(executables) != 1:
140            raise error.general('one executable required, found %d' % (len(executables)))
[30218f5]141        opts.defaults['test_disable_header'] = '1'
142        reports = report.report(1)
[c68beb8]143        start_time = datetime.datetime.now()
144        opts.defaults['exe_trace'] = debug_trace
[30218f5]145        tst = test(1, 1, reports, executables[0], rtems_tools, bsp, bsp_config, opts)
[c68beb8]146        tst.run()
147        end_time = datetime.datetime.now()
148        total_time = 'Run time     : %s' % (str(end_time - start_time))
149        log.notice(total_time)
150
151    except error.general as gerr:
152        print(gerr)
153        sys.exit(1)
154    except error.internal as ierr:
155        print(ierr)
156        sys.exit(1)
157    except error.exit:
158        sys.exit(2)
159    except KeyboardInterrupt:
160        if opts is not None and opts.find_arg('--stacktrace'):
161            print('}} dumping:', threading.active_count())
162            for t in threading.enumerate():
163                print('}} ', t.name)
164            print(stacktraces.trace())
165        log.notice('abort: user terminated')
166        sys.exit(1)
167    finally:
168        console.restore(stdtty)
169    sys.exit(0)
170
171if __name__ == "__main__":
172    run()
Note: See TracBrowser for help on using the repository browser.