source: rtems-tools/wscript @ f632bd8

5
Last change on this file since f632bd8 was 7e5cdea, checked in by Chris Johns <chrisj@…>, on 11/23/18 at 04:02:52

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
RevLine 
[749ddf1]1#
2# RTEMS Tools Project (http://www.rtems.org/)
[c5286cd]3# Copyright 2014-2018 Chris Johns (chrisj@rtems.org)
[749ddf1]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
[efc4f09]31import os.path
32
[7148cae]33import wafwindows
34
[87e0e76]35subdirs = ['rtemstoolkit',
[5416cfa]36           'config',
[87e0e76]37           'linkers',
[1cd75c4]38           'misc',
[749ddf1]39           'tester',
40           'tools/gdb/python']
41
[efc4f09]42def get_version(ctx):
[3bd8def]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))
[8b49f73]49    release = '%s.%s' % (version, revision)
[3bd8def]50    return version, release
[efc4f09]51
[749ddf1]52def recurse(ctx):
53    for sd in subdirs:
54        ctx.recurse(sd)
55
56def options(ctx):
[87e0e76]57    ctx.add_option('--c-opts',
58                   default = '-O2',
59                   dest='c_opts',
60                   help = 'Set build options, default: -O2.')
[3badbb0]61    ctx.add_option('--host',
62                   default = 'native',
63                   dest='host',
64                   help = 'Set host to build for, default: none.')
[749ddf1]65    recurse(ctx)
66
[3badbb0]67def init(ctx):
[7148cae]68    wafwindows.set_compilers()
[3badbb0]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'])
[7148cae]75        recurse(ctx)
[3badbb0]76    except:
77        pass
78
[7148cae]79def shutdown(ctx):
80    pass
81
[749ddf1]82def configure(ctx):
[87e0e76]83    try:
84        ctx.load("doxygen", tooldir = 'waf-tools')
85    except:
86        pass
[efc4f09]87    ctx.env.RTEMS_VERSION, ctx.env.RTEMS_RELEASE = get_version(ctx)
[8b49f73]88    ctx.start_msg('Version')
89    ctx.end_msg('%s (%s)' % (ctx.env.RTEMS_RELEASE, ctx.env.RTEMS_VERSION))
[87e0e76]90    ctx.env.C_OPTS = ctx.options.c_opts.split(',')
[3badbb0]91    check_options(ctx, ctx.options.host)
[de1beea]92    #
93    # Common Python check.
94    #
95    ctx.load('python')
96    ctx.check_python_version((2,6,6))
97    #
[7e5cdea]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    #
[de1beea]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
[749ddf1]107    recurse(ctx)
108
109def build(ctx):
[efc4f09]110    if os.path.exists('VERSION'):
111        ctx.install_files('${PREFIX}/share/rtems/rtemstoolkit', ['VERSION'])
[749ddf1]112    recurse(ctx)
[7e5cdea]113    if ctx.cmd == 'test':
114        rtemstoolkit_tests(ctx)
[749ddf1]115
116def install(ctx):
117    recurse(ctx)
118
119def clean(ctx):
120    recurse(ctx)
[87e0e76]121
122def rebuild(ctx):
123    import waflib.Options
124    waflib.Options.commands.extend(['clean', 'build'])
125
[3badbb0]126def check_options(ctx, host):
[845054a]127    if host in ['mingw32', 'x86_64-w64-mingw32']:
[3badbb0]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
[87e0e76]136#
[7e5cdea]137# Custom commands
[87e0e76]138#
[7e5cdea]139import waflib
140
141class test(waflib.Build.BuildContext):
142    fun = 'build'
143    cmd = 'test'
144
145class doxy(waflib.Build.BuildContext):
[87e0e76]146    fun = 'build'
147    cmd = 'doxy'
[7e5cdea]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.