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

Last change on this file since 3bd8def was 3bd8def, checked in by Chris Johns <chrisj@…>, on Oct 3, 2018 at 1:38:09 AM

config: Consolidate the version information into a single configuration file

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