Changeset 7e5cdea in rtems-tools


Ignore:
Timestamp:
Nov 23, 2018, 4:02:52 AM (5 months ago)
Author:
Chris Johns <chrisj@…>
Branches:
master
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.
Files:
21 edited

Legend:

Unmodified
Added
Removed
  • README

    r6fa0965 r7e5cdea  
    2929To build and install:
    3030
    31  $ ./waf configure --prefix=$HOME/development/rtems/4.11
     31 $ ./waf configure --prefix=$HOME/development/rtems/5
    3232 $ ./waf build install
     33
     34Testing
     35-------
     36
     37To the run the tests build then enter:
     38
     39 $ ./waf test
     40
     41Python
     42------
     43
     44The RTEMS Tools supports python3 and python2. The commands look for python3,
     45then python2 and finally python and use the first it finds.
     46
     47You can forced a specific version for testing by setting the environment
     48variable 'RTEMS_PYTHON_OVERRIDE' to the python you want to use. For example:
     49
     50 $ export RTEMS_PYTHON_OVERRIDE=python2
     51
     52will use python2.
    3353
    3454Waf
     
    3858
    3959 http://code.google.com/p/waf/
    40 
    41 Simple instructions on How to set up Waf is here:
    42 
    43  http://www.rtems.org/ftp/pub/rtems/people/chrisj/rtl/rtems-linker/waf.html
    44 
  • rtemstoolkit/__init__.py

    r6fa0965 r7e5cdea  
    4747       'version']
    4848
    49 from . import check
    50 from . import config
    51 from . import configuration
    52 from . import error
    53 from . import execute
    54 from . import git
    55 from . import host
    56 from . import log
    57 from . import macros
    58 from . import mailer
    59 from . import options
    60 from . import path
    61 from . import reraise
    62 from . import rtems
    63 from . import stacktraces
    64 from . import textbox
    65 from . import version
     49args = {
     50    'config': ['--file', 'tester/rtems/version.cfg',
     51               '--jobs', 'half',
     52               '--no-clean'],
     53    'mailer': ['--smtp-host', '1.2.3.4',
     54               '--mail-to',   'foo@bar.none',
     55               '--mail-from', 'me@here.there']
     56
     57}
  • rtemstoolkit/check.py

    r6fa0965 r7e5cdea  
    3737import os
    3838
    39 #
    40 # Support to handle use in a package and as a unit test.
    41 # If there is a better way to let us know.
    42 #
    43 try:
    44     from . import error
    45     from . import execute
    46     from . import log
    47     from . import options
    48     from . import path
    49     from . import version
    50 except (ValueError, SystemError):
    51     import error
    52     import execute
    53     import log
    54     import options
    55     import path
    56     import version
     39from rtemstoolkit import error
     40from rtemstoolkit import execute
     41from rtemstoolkit import log
     42from rtemstoolkit import options
     43from rtemstoolkit import path
     44from rtemstoolkit import version
    5745
    5846def _check_none(_opts, macro, value, constraint):
     
    164152
    165153
    166 def run():
     154def run(args):
    167155    import sys
    168156    try:
    169         _opts = options.command_line(argv = sys.argv)
     157        _opts = options.command_line(argv = args)
    170158        options.load(_opts)
    171         log.notice('RTEMS Source Builder - Check, v%s' % (version.string()))
     159        log.notice('RTEMS Toolkit - Check, v%s' % (version.string()))
    172160        if host_setup(_opts):
    173161            print('Environment is ok')
     
    189177
    190178if __name__ == '__main__':
    191     run()
     179    run(['tester'])
  • rtemstoolkit/config.py

    r6fa0965 r7e5cdea  
    4545import sys
    4646
    47 #
    48 # Support to handle use in a package and as a unit test.
    49 # If there is a better way to let us know.
    50 #
    51 try:
    52     from . import error
    53     from . import execute
    54     from . import host
    55     from . import log
    56     from . import options
    57     from . import path
    58 except (ValueError, SystemError):
    59     import error
    60     import execute
    61     import host
    62     import log
    63     import options
    64     import path
     47from rtemstoolkit import error
     48from rtemstoolkit import execute
     49from rtemstoolkit import host
     50from rtemstoolkit import log
     51from rtemstoolkit import options
     52from rtemstoolkit import path
    6553
    6654def _check_bool(value):
  • rtemstoolkit/darwin.py

    r6fa0965 r7e5cdea  
    3636import os
    3737
    38 #
    39 # Support to handle use in a package and as a unit test.
    40 # If there is a better way to let us know.
    41 #
    42 try:
    43     from . import execute
    44 except (ValueError, SystemError):
    45     import execute
     38from rtemstoolkit import execute
    4639
    4740def cpus():
  • rtemstoolkit/freebsd.py

    r6fa0965 r7e5cdea  
    3636import os
    3737
    38 #
    39 # Support to handle use in a package and as a unit test.
    40 # If there is a better way to let us know.
    41 #
    42 try:
    43     from . import check
    44     from . import execute
    45 except (ValueError, SystemError):
    46     import check
    47     import execute
     38from rtemstoolkit import check
     39from rtemstoolkit import execute
    4840
    4941def cpus():
  • rtemstoolkit/git.py

    r6fa0965 r7e5cdea  
    3232import os
    3333
    34 #
    35 # Support to handle use in a package and as a unit test.
    36 # If there is a better way to let us know.
    37 #
    38 try:
    39     from . import error
    40     from . import execute
    41     from . import log
    42     from . import path
    43 except (ValueError, SystemError):
    44     import error
    45     import execute
    46     import log
    47     import path
     34from rtemstoolkit import error
     35from rtemstoolkit import execute
     36from rtemstoolkit import log
     37from rtemstoolkit import path
    4838
    4939class repo:
     
    221211if __name__ == '__main__':
    222212    import sys
    223     import options
     213    from rtemstoolkit import options
    224214    long_opts = {
    225215       # key              macro        handler   param  defs   init
  • rtemstoolkit/host.py

    r6fa0965 r7e5cdea  
    3737import os
    3838
    39 #
    40 # Support to handle use in a package and as a unit test.
    41 # If there is a better way to let us know.
    42 #
    43 try:
    44     from . import error
    45 except (ValueError, SystemError):
    46     import error
     39from rtemstoolkit import error
    4740
    4841is_windows = False
     
    114107if __name__ == '__main__':
    115108    import pprint
    116     pprint.pprint(platform())
    117109    _load()
    118110    print('Name      : %s' % (name))
  • rtemstoolkit/linux.py

    r6fa0965 r7e5cdea  
    3737import platform
    3838
    39 #
    40 # Support to handle use in a package and as a unit test.
    41 # If there is a better way to let us know.
    42 #
    43 try:
    44     from . import execute
    45     from . import path
    46 except (ValueError, SystemError):
    47     import execute
    48     import path
     39from rtemstoolkit import execute
     40from rtemstoolkit import path
    4941
    5042def cpus():
  • rtemstoolkit/log.py

    r6fa0965 r7e5cdea  
    3939import threading
    4040
    41 #
    42 # Support to handle use in a package and as a unit test.
    43 # If there is a better way to let us know.
    44 #
    45 try:
    46     from . import error
    47 except (ValueError, SystemError):
    48     import error
     41from rtemstoolkit import error
    4942
    5043#
  • rtemstoolkit/macros.py

    r6fa0965 r7e5cdea  
    4141import string
    4242
    43 #
    44 # Support to handle use in a package and as a unit test.
    45 # If there is a better way to let us know.
    46 #
    47 try:
    48     from . import error
    49     from . import log
    50     from . import path
    51 except (ValueError, SystemError):
    52     import error
    53     import log
    54     import path
     43from rtemstoolkit import error
     44from rtemstoolkit import log
     45from rtemstoolkit import path
    5546
    5647#
  • rtemstoolkit/mailer.py

    r6fa0965 r7e5cdea  
    3939import socket
    4040
    41 #
    42 # Support to handle use in a package and as a unit test.
    43 # If there is a better way to let us know.
    44 #
    45 try:
    46     from . import error
    47     from . import options
    48     from . import path
    49 except (ValueError, SystemError):
    50     import error
    51     import options
    52     import path
     41from rtemstoolkit import error
     42from rtemstoolkit import options
     43from rtemstoolkit import path
    5344
    5445_options = {
     
    162153if __name__ == '__main__':
    163154    import sys
     155    from rtemstoolkit import macros
    164156    optargs = {}
     157    rtdir = 'rtemstoolkit'
     158    defaults = '%s/defaults.mc' % (rtdir)
    165159    append_options(optargs)
    166     opts = options.load(sys.argv, optargs = optargs, defaults = 'defaults.mc')
     160    opts = options.command_line(base_path = '.',
     161                                argv = sys.argv,
     162                                optargs = optargs,
     163                                defaults = macros.macros(name = defaults, rtdir = rtdir),
     164                                command_path = '.')
     165    options.load(opts)
    167166    m = mail(opts)
    168167    print('From: %s' % (m.from_address()))
    169168    print('SMTP Host: %s' % (m.smtp_host()))
    170     m.send(m.from_address(), 'Test mailer.py', 'This is a test')
     169    if '--mail' in sys.argv:
     170        m.send(m.from_address(), 'Test mailer.py', 'This is a test')
  • rtemstoolkit/netbsd.py

    r6fa0965 r7e5cdea  
    2727import os
    2828
    29 try:
    30     from . import check
    31     from . import execute
    32 except (ValueError, SystemError):
    33     import check
    34     import execute
     29from rtemstoolkit import check
     30from rtemstoolkit import execute
    3531
    3632def cpus():
  • rtemstoolkit/options.py

    r6fa0965 r7e5cdea  
    4343import sys
    4444
    45 #
    46 # Support to handle use in a package and as a unit test.
    47 # If there is a better way to let us know.
    48 #
    49 try:
    50     from . import error
    51     from . import execute
    52     from . import git
    53     from . import host
    54     from . import log
    55     from . import macros
    56     from . import path
    57     from . import version
    58 except (ValueError, SystemError):
    59     import error
    60     import execute
    61     import git
    62     import host
    63     import log
    64     import macros
    65     import path
    66     import version
     45from rtemstoolkit import error
     46from rtemstoolkit import execute
     47from rtemstoolkit import git
     48from rtemstoolkit import host
     49from rtemstoolkit import log
     50from rtemstoolkit import macros
     51from rtemstoolkit import path
     52from rtemstoolkit import version
    6753
    6854basepath = 'tb'
  • rtemstoolkit/path.py

    r6fa0965 r7e5cdea  
    4242import string
    4343
    44 #
    45 # Support to handle use in a package and as a unit test.
    46 # If there is a better way to let us know.
    47 #
    48 try:
    49     from . import error
    50     from . import log
    51 except (ValueError, SystemError):
    52     import error
    53     import log
     44from rtemstoolkit import error
     45from rtemstoolkit import log
    5446
    5547windows = os.name == 'nt'
  • rtemstoolkit/rtems.py

    r6fa0965 r7e5cdea  
    7272    '''
    7373    if prog is None:
    74         exec_name = sys.argv[1]
     74        if len(sys.argv) == 1:
     75            exec_name = sys.argv[0]
     76        else:
     77            exec_name = sys.argv[1]
    7578    else:
    7679        exec_name = prog
  • rtemstoolkit/solaris.py

    r6fa0965 r7e5cdea  
    2525import os
    2626
    27 try:
    28     from . import check
    29     from . import error
    30     from . import execute
    31 except (ValueError, SystemError):
    32     import check
    33     import error
    34     import execute
     27from rtemstoolkit import check
     28from rtemstoolkit import error
     29from rtemstoolkit import execute
    3530
    3631def cpus():
  • rtemstoolkit/textbox.py

    r6fa0965 r7e5cdea  
    4040import os
    4141
    42 #
    43 # Support to handle use in a package and as a unit test.
    44 # If there is a better way to let us know.
    45 #
    46 try:
    47     from . import error
    48 except (ValueError, SystemError):
    49     import error
     42from rtemstoolkit import error
    5043
    5144def line(cols, line = '-', marker = '|', indent = 0, linesep = os.linesep):
    5245    s = ' ' * indent + marker
    5346    for c in cols:
    54         s += line[0] * (c - 1) + marker
     47        s += line[0] * int((c - 1)) + marker
    5548    return s + linesep
    5649
     
    6558        else:
    6659            m = '|'
    67         s += '%-*s%s' % (cols[c] - 1, str(data[c]), m)
     60        s += '%-*s%s' % (int(cols[c] - 1), str(data[c]), m)
    6861    return s + linesep
    6962
     
    7164    per_col = width / cols
    7265    columns = [per_col for c in range(0, cols)]
    73     for remainder in range(0, width - (per_col * cols)):
     66    for remainder in range(0, int(width - (per_col * cols))):
    7467        if remainder % 2 == 0:
    7568            columns[remainder] += 1
  • rtemstoolkit/version.py

    r6fa0965 r7e5cdea  
    8989    import ConfigParser as configparser
    9090
    91 #
    92 # Support to handle importing when installed in a package and as a unit test.
    93 # If there is a better way to let us know.
    94 #
    95 try:
    96     from . import error
    97     from . import git
    98     from . import rtems
    99 except (ValueError, SystemError):
    100     import error
    101     import git
    102     import path
    103     import rtems
     91from rtemstoolkit import error
     92from rtemstoolkit import git
     93from rtemstoolkit import path
     94from rtemstoolkit import rtems
    10495
    10596#
  • rtemstoolkit/windows.py

    r6fa0965 r7e5cdea  
    3535import os
    3636
    37 #
    38 # Support to handle use in a package and as a unit test.
    39 # If there is a better way to let us know.
    40 #
    41 try:
    42     from . import error
    43     from . import execute
    44 except (ValueError, SystemError):
    45     import error
    46     import execute
     37from rtemstoolkit import error
     38from rtemstoolkit import execute
    4739
    4840def cpus():
  • 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.