source: rtems-tools/wscript @ 7e5cdea

Last change on this file since 7e5cdea was 7e5cdea, checked in by Chris Johns <chrisj@…>, on Nov 23, 2018 at 4:02:52 AM

rtemstoolkit: Add unit testing for the python modules

  • Add support to run the unit tests for the rtemstoolkit python modules from waf. Enter './waf test' for the tests to be run on python2 and python3.
  • Update the importing of rtemstoolkit modules to the standard method which works on python2 and python3.
  • Update the README.
  • Property mode set to 100644
File size: 5.7 KB
Line 
1#
2# RTEMS Tools Project (http://www.rtems.org/)
3# Copyright 2014-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
31import os.path
32
33import wafwindows
34
35subdirs = ['rtemstoolkit',
36           'config',
37           'linkers',
38           'misc',
39           'tester',
40           'tools/gdb/python']
41
42def get_version(ctx):
43    from rtemstoolkit import version as rtemsversion
44    try:
45        version = rtemsversion.version()
46        revision = rtemsversion.revision()
47    except Exception as e:
48        ctx.fatal('invalid version file: %s' % (e))
49    release = '%s.%s' % (version, revision)
50    return version, release
51
52def recurse(ctx):
53    for sd in subdirs:
54        ctx.recurse(sd)
55
56def options(ctx):
57    ctx.add_option('--c-opts',
58                   default = '-O2',
59                   dest='c_opts',
60                   help = 'Set build options, default: -O2.')
61    ctx.add_option('--host',
62                   default = 'native',
63                   dest='host',
64                   help = 'Set host to build for, default: none.')
65    recurse(ctx)
66
67def init(ctx):
68    wafwindows.set_compilers()
69    try:
70        import waflib.Options
71        import waflib.ConfigSet
72        env = waflib.ConfigSet.ConfigSet()
73        env.load(waflib.Options.lockfile)
74        check_options(ctx, env.options['host'])
75        recurse(ctx)
76    except:
77        pass
78
79def shutdown(ctx):
80    pass
81
82def configure(ctx):
83    try:
84        ctx.load("doxygen", tooldir = 'waf-tools')
85    except:
86        pass
87    ctx.env.RTEMS_VERSION, ctx.env.RTEMS_RELEASE = get_version(ctx)
88    ctx.start_msg('Version')
89    ctx.end_msg('%s (%s)' % (ctx.env.RTEMS_RELEASE, ctx.env.RTEMS_VERSION))
90    ctx.env.C_OPTS = ctx.options.c_opts.split(',')
91    check_options(ctx, ctx.options.host)
92    #
93    # Common Python check.
94    #
95    ctx.load('python')
96    ctx.check_python_version((2,6,6))
97    #
98    # Find which versions of python are installed for testing.
99    #
100    ctx.find_program('python2', mandatory = False)
101    ctx.find_program('python3', mandatory = False)
102    #
103    # Installing the PYO,PYC seems broken on 1.8.19. The path is wrong.
104    #
105    ctx.env.PYO = 0
106    ctx.env.PYC = 0
107    recurse(ctx)
108
109def build(ctx):
110    if os.path.exists('VERSION'):
111        ctx.install_files('${PREFIX}/share/rtems/rtemstoolkit', ['VERSION'])
112    recurse(ctx)
113    if ctx.cmd == 'test':
114        rtemstoolkit_tests(ctx)
115
116def install(ctx):
117    recurse(ctx)
118
119def clean(ctx):
120    recurse(ctx)
121
122def rebuild(ctx):
123    import waflib.Options
124    waflib.Options.commands.extend(['clean', 'build'])
125
126def check_options(ctx, host):
127    if host in ['mingw32', 'x86_64-w64-mingw32']:
128        ctx.env.HOST = host
129        ctx.env.CC = '%s-gcc' % (host)
130        ctx.env.CXX = '%s-g++' % (host)
131        ctx.env.AR = '%s-ar' % (host)
132        ctx.env.PYTHON = 'python'
133    elif host is not 'native':
134        ctx.fatal('unknown host: %s' % (host));
135
136#
137# Custom commands
138#
139import waflib
140
141class test(waflib.Build.BuildContext):
142    fun = 'build'
143    cmd = 'test'
144
145class doxy(waflib.Build.BuildContext):
146    fun = 'build'
147    cmd = 'doxy'
148
149#
150# RTEMS Toolkit Tests.
151#
152# Run the tests from the top directory so they are run as python modules.
153#
154def rtemstoolkit_tests(ctx):
155    log = ctx.path.find_or_declare('tests.log')
156    ctx.logger = waflib.Logs.make_logger(log.abspath(), 'build')
157    failures = False
158    for py in ['2', '3']:
159        PY = 'PYTHON%s' % (py)
160        if PY in ctx.env:
161            from rtemstoolkit import all as toolkit_tests
162            from rtemstoolkit import args as toolkit_test_args
163            for tt in toolkit_tests:
164                test = 'rtemstoolkit.%s' % (tt)
165                ctx.start_msg('Test python%s %s' % (py, test))
166                cmd = '%s -m %s' % (ctx.env[PY][0], test)
167                if tt in toolkit_test_args:
168                    cmd += ' ' + ' '.join(toolkit_test_args[tt])
169                ctx.to_log('test command: ' + cmd)
170                try:
171                    (out, err) = ctx.cmd_and_log(cmd,
172                                                 output = waflib.Context.BOTH,
173                                                 quiet = waflib.Context.BOTH)
174                    ctx.to_log(out)
175                    ctx.to_log(err)
176                    ctx.end_msg('pass')
177                except waflib.Errors.WafError as e:
178                    failures = True
179                    ctx.to_log(e.stdout)
180                    ctx.to_log(e.stderr)
181                    ctx.end_msg('fail', color = 'RED')
182    if failures:
183        ctx.fatal('Test failures')
Note: See TracBrowser for help on using the repository browser.