Changeset 7e5cdea in rtems-tools for wscript


Ignore:
Timestamp:
Nov 23, 2018, 4:02:52 AM (11 months ago)
Author:
Chris Johns <chrisj@…>
Branches:
e9f48e9face6c4dea62712d73b35412c0fe10332
Children:
f632bd8
Parents:
6fa0965
Message:

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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • wscript

    r6fa0965 r7e5cdea  
    9696    ctx.check_python_version((2,6,6))
    9797    #
     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    #
    98103    # Installing the PYO,PYC seems broken on 1.8.19. The path is wrong.
    99104    #
     
    106111        ctx.install_files('${PREFIX}/share/rtems/rtemstoolkit', ['VERSION'])
    107112    recurse(ctx)
     113    if ctx.cmd == 'test':
     114        rtemstoolkit_tests(ctx)
    108115
    109116def install(ctx):
     
    128135
    129136#
    130 # The doxy command.
     137# Custom commands
    131138#
    132 from waflib import Build
    133 class doxy(Build.BuildContext):
     139import waflib
     140
     141class test(waflib.Build.BuildContext):
     142    fun = 'build'
     143    cmd = 'test'
     144
     145class doxy(waflib.Build.BuildContext):
    134146    fun = 'build'
    135147    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 TracChangeset for help on using the changeset viewer.