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.
This commit is contained in:
Chris Johns 2018-11-23 15:02:52 +11:00
parent 6fa09650b8
commit 7e5cdeaabe
21 changed files with 155 additions and 233 deletions

27
README
View File

@ -28,17 +28,32 @@ Building
To build and install: To build and install:
$ ./waf configure --prefix=$HOME/development/rtems/4.11 $ ./waf configure --prefix=$HOME/development/rtems/5
$ ./waf build install $ ./waf build install
Testing
-------
To the run the tests build then enter:
$ ./waf test
Python
------
The RTEMS Tools supports python3 and python2. The commands look for python3,
then python2 and finally python and use the first it finds.
You can forced a specific version for testing by setting the environment
variable 'RTEMS_PYTHON_OVERRIDE' to the python you want to use. For example:
$ export RTEMS_PYTHON_OVERRIDE=python2
will use python2.
Waf Waf
--- ---
The Waf project can be found here: The Waf project can be found here:
http://code.google.com/p/waf/ http://code.google.com/p/waf/
Simple instructions on How to set up Waf is here:
http://www.rtems.org/ftp/pub/rtems/people/chrisj/rtl/rtems-linker/waf.html

View File

@ -46,20 +46,12 @@ all = ['check',
'textbox', 'textbox',
'version'] 'version']
from . import check args = {
from . import config 'config': ['--file', 'tester/rtems/version.cfg',
from . import configuration '--jobs', 'half',
from . import error '--no-clean'],
from . import execute 'mailer': ['--smtp-host', '1.2.3.4',
from . import git '--mail-to', 'foo@bar.none',
from . import host '--mail-from', 'me@here.there']
from . import log
from . import macros }
from . import mailer
from . import options
from . import path
from . import reraise
from . import rtems
from . import stacktraces
from . import textbox
from . import version

View File

@ -36,24 +36,12 @@ from __future__ import print_function
import os import os
# from rtemstoolkit import error
# Support to handle use in a package and as a unit test. from rtemstoolkit import execute
# If there is a better way to let us know. from rtemstoolkit import log
# from rtemstoolkit import options
try: from rtemstoolkit import path
from . import error from rtemstoolkit import version
from . import execute
from . import log
from . import options
from . import path
from . import version
except (ValueError, SystemError):
import error
import execute
import log
import options
import path
import version
def _check_none(_opts, macro, value, constraint): def _check_none(_opts, macro, value, constraint):
return True return True
@ -163,12 +151,12 @@ def check_dir(label, path):
return _check_dir(None, label, path, 'required', True) return _check_dir(None, label, path, 'required', True)
def run(): def run(args):
import sys import sys
try: try:
_opts = options.command_line(argv = sys.argv) _opts = options.command_line(argv = args)
options.load(_opts) options.load(_opts)
log.notice('RTEMS Source Builder - Check, v%s' % (version.string())) log.notice('RTEMS Toolkit - Check, v%s' % (version.string()))
if host_setup(_opts): if host_setup(_opts):
print('Environment is ok') print('Environment is ok')
else: else:
@ -188,4 +176,4 @@ def run():
if __name__ == '__main__': if __name__ == '__main__':
run() run(['tester'])

View File

@ -44,24 +44,12 @@ import os
import re import re
import sys import sys
# from rtemstoolkit import error
# Support to handle use in a package and as a unit test. from rtemstoolkit import execute
# If there is a better way to let us know. from rtemstoolkit import host
# from rtemstoolkit import log
try: from rtemstoolkit import options
from . import error from rtemstoolkit import path
from . import execute
from . import host
from . import log
from . import options
from . import path
except (ValueError, SystemError):
import error
import execute
import host
import log
import options
import path
def _check_bool(value): def _check_bool(value):
if value.isdigit(): if value.isdigit():

View File

@ -35,14 +35,7 @@
import os import os
# from rtemstoolkit import execute
# Support to handle use in a package and as a unit test.
# If there is a better way to let us know.
#
try:
from . import execute
except (ValueError, SystemError):
import execute
def cpus(): def cpus():
sysctl = '/usr/sbin/sysctl ' sysctl = '/usr/sbin/sysctl '

View File

@ -35,16 +35,8 @@
import os import os
# from rtemstoolkit import check
# Support to handle use in a package and as a unit test. from rtemstoolkit import execute
# If there is a better way to let us know.
#
try:
from . import check
from . import execute
except (ValueError, SystemError):
import check
import execute
def cpus(): def cpus():
sysctl = '/sbin/sysctl ' sysctl = '/sbin/sysctl '

View File

@ -31,20 +31,10 @@
import os import os
# from rtemstoolkit import error
# Support to handle use in a package and as a unit test. from rtemstoolkit import execute
# If there is a better way to let us know. from rtemstoolkit import log
# from rtemstoolkit import path
try:
from . import error
from . import execute
from . import log
from . import path
except (ValueError, SystemError):
import error
import execute
import log
import path
class repo: class repo:
"""An object to manage a git repo.""" """An object to manage a git repo."""
@ -220,7 +210,7 @@ class repo:
if __name__ == '__main__': if __name__ == '__main__':
import sys import sys
import options from rtemstoolkit import options
long_opts = { long_opts = {
# key macro handler param defs init # key macro handler param defs init
} }

View File

@ -36,14 +36,7 @@ from __future__ import print_function
import os import os
# from rtemstoolkit import error
# Support to handle use in a package and as a unit test.
# If there is a better way to let us know.
#
try:
from . import error
except (ValueError, SystemError):
import error
is_windows = False is_windows = False
platform = None platform = None
@ -113,7 +106,6 @@ def label(mode = 'all'):
if __name__ == '__main__': if __name__ == '__main__':
import pprint import pprint
pprint.pprint(platform())
_load() _load()
print('Name : %s' % (name)) print('Name : %s' % (name))
if is_windows: if is_windows:

View File

@ -36,16 +36,8 @@
import os import os
import platform import platform
# from rtemstoolkit import execute
# Support to handle use in a package and as a unit test. from rtemstoolkit import path
# If there is a better way to let us know.
#
try:
from . import execute
from . import path
except (ValueError, SystemError):
import execute
import path
def cpus(): def cpus():
processors = '/bin/grep processor /proc/cpuinfo' processors = '/bin/grep processor /proc/cpuinfo'

View File

@ -38,14 +38,7 @@ import os
import sys import sys
import threading import threading
# from rtemstoolkit import error
# Support to handle use in a package and as a unit test.
# If there is a better way to let us know.
#
try:
from . import error
except (ValueError, SystemError):
import error
# #
# A global log. # A global log.

View File

@ -40,18 +40,9 @@ import re
import os import os
import string import string
# from rtemstoolkit import error
# Support to handle use in a package and as a unit test. from rtemstoolkit import log
# If there is a better way to let us know. from rtemstoolkit import path
#
try:
from . import error
from . import log
from . import path
except (ValueError, SystemError):
import error
import log
import path
# #
# Macro tables # Macro tables

View File

@ -38,18 +38,9 @@ import os
import smtplib import smtplib
import socket import socket
# from rtemstoolkit import error
# Support to handle use in a package and as a unit test. from rtemstoolkit import options
# If there is a better way to let us know. from rtemstoolkit import path
#
try:
from . import error
from . import options
from . import path
except (ValueError, SystemError):
import error
import options
import path
_options = { _options = {
'--mail' : 'Send email report or results.', '--mail' : 'Send email report or results.',
@ -161,10 +152,19 @@ class mail:
if __name__ == '__main__': if __name__ == '__main__':
import sys import sys
from rtemstoolkit import macros
optargs = {} optargs = {}
rtdir = 'rtemstoolkit'
defaults = '%s/defaults.mc' % (rtdir)
append_options(optargs) append_options(optargs)
opts = options.load(sys.argv, optargs = optargs, defaults = 'defaults.mc') opts = options.command_line(base_path = '.',
argv = sys.argv,
optargs = optargs,
defaults = macros.macros(name = defaults, rtdir = rtdir),
command_path = '.')
options.load(opts)
m = mail(opts) m = mail(opts)
print('From: %s' % (m.from_address())) print('From: %s' % (m.from_address()))
print('SMTP Host: %s' % (m.smtp_host())) print('SMTP Host: %s' % (m.smtp_host()))
m.send(m.from_address(), 'Test mailer.py', 'This is a test') if '--mail' in sys.argv:
m.send(m.from_address(), 'Test mailer.py', 'This is a test')

View File

@ -26,12 +26,8 @@
import os import os
try: from rtemstoolkit import check
from . import check from rtemstoolkit import execute
from . import execute
except (ValueError, SystemError):
import check
import execute
def cpus(): def cpus():
sysctl = '/sbin/sysctl ' sysctl = '/sbin/sysctl '

View File

@ -42,28 +42,14 @@ import os
import string import string
import sys import sys
# from rtemstoolkit import error
# Support to handle use in a package and as a unit test. from rtemstoolkit import execute
# If there is a better way to let us know. from rtemstoolkit import git
# from rtemstoolkit import host
try: from rtemstoolkit import log
from . import error from rtemstoolkit import macros
from . import execute from rtemstoolkit import path
from . import git from rtemstoolkit import version
from . import host
from . import log
from . import macros
from . import path
from . import version
except (ValueError, SystemError):
import error
import execute
import git
import host
import log
import macros
import path
import version
basepath = 'tb' basepath = 'tb'

View File

@ -41,16 +41,8 @@ import os
import shutil import shutil
import string import string
# from rtemstoolkit import error
# Support to handle use in a package and as a unit test. from rtemstoolkit import log
# If there is a better way to let us know.
#
try:
from . import error
from . import log
except (ValueError, SystemError):
import error
import log
windows = os.name == 'nt' windows = os.name == 'nt'

View File

@ -71,7 +71,10 @@ def configuration_path(prog = None):
2. Ok to directly call os.path. 2. Ok to directly call os.path.
''' '''
if prog is None: if prog is None:
exec_name = sys.argv[1] if len(sys.argv) == 1:
exec_name = sys.argv[0]
else:
exec_name = sys.argv[1]
else: else:
exec_name = prog exec_name = prog
exec_name = os.path.abspath(exec_name) exec_name = os.path.abspath(exec_name)

View File

@ -24,14 +24,9 @@
import os import os
try: from rtemstoolkit import check
from . import check from rtemstoolkit import error
from . import error from rtemstoolkit import execute
from . import execute
except (ValueError, SystemError):
import check
import error
import execute
def cpus(): def cpus():
psrinfo = '/sbin/psrinfo|wc -l' psrinfo = '/sbin/psrinfo|wc -l'

View File

@ -39,19 +39,12 @@ from __future__ import print_function
import copy import copy
import os import os
# from rtemstoolkit import error
# Support to handle use in a package and as a unit test.
# If there is a better way to let us know.
#
try:
from . import error
except (ValueError, SystemError):
import error
def line(cols, line = '-', marker = '|', indent = 0, linesep = os.linesep): def line(cols, line = '-', marker = '|', indent = 0, linesep = os.linesep):
s = ' ' * indent + marker s = ' ' * indent + marker
for c in cols: for c in cols:
s += line[0] * (c - 1) + marker s += line[0] * int((c - 1)) + marker
return s + linesep return s + linesep
def row(cols, data, indent = 0, marker = '|', linesep = os.linesep): def row(cols, data, indent = 0, marker = '|', linesep = os.linesep):
@ -64,13 +57,13 @@ def row(cols, data, indent = 0, marker = '|', linesep = os.linesep):
m = marker m = marker
else: else:
m = '|' m = '|'
s += '%-*s%s' % (cols[c] - 1, str(data[c]), m) s += '%-*s%s' % (int(cols[c] - 1), str(data[c]), m)
return s + linesep return s + linesep
def even_columns(cols, width = 80): def even_columns(cols, width = 80):
per_col = width / cols per_col = width / cols
columns = [per_col for c in range(0, cols)] columns = [per_col for c in range(0, cols)]
for remainder in range(0, width - (per_col * cols)): for remainder in range(0, int(width - (per_col * cols))):
if remainder % 2 == 0: if remainder % 2 == 0:
columns[remainder] += 1 columns[remainder] += 1
else: else:

View File

@ -88,19 +88,10 @@ try:
except ImportError: except ImportError:
import ConfigParser as configparser import ConfigParser as configparser
# from rtemstoolkit import error
# Support to handle importing when installed in a package and as a unit test. from rtemstoolkit import git
# If there is a better way to let us know. from rtemstoolkit import path
# from rtemstoolkit import rtems
try:
from . import error
from . import git
from . import rtems
except (ValueError, SystemError):
import error
import git
import path
import rtems
# #
# Default to an internal string. # Default to an internal string.

View File

@ -34,16 +34,8 @@
import os import os
# from rtemstoolkit import error
# Support to handle use in a package and as a unit test. from rtemstoolkit import execute
# If there is a better way to let us know.
#
try:
from . import error
from . import execute
except (ValueError, SystemError):
import error
import execute
def cpus(): def cpus():
if os.environ.has_key('NUMBER_OF_PROCESSORS'): if os.environ.has_key('NUMBER_OF_PROCESSORS'):

54
wscript
View File

@ -95,6 +95,11 @@ def configure(ctx):
ctx.load('python') ctx.load('python')
ctx.check_python_version((2,6,6)) ctx.check_python_version((2,6,6))
# #
# Find which versions of python are installed for testing.
#
ctx.find_program('python2', mandatory = False)
ctx.find_program('python3', mandatory = False)
#
# Installing the PYO,PYC seems broken on 1.8.19. The path is wrong. # Installing the PYO,PYC seems broken on 1.8.19. The path is wrong.
# #
ctx.env.PYO = 0 ctx.env.PYO = 0
@ -105,6 +110,8 @@ def build(ctx):
if os.path.exists('VERSION'): if os.path.exists('VERSION'):
ctx.install_files('${PREFIX}/share/rtems/rtemstoolkit', ['VERSION']) ctx.install_files('${PREFIX}/share/rtems/rtemstoolkit', ['VERSION'])
recurse(ctx) recurse(ctx)
if ctx.cmd == 'test':
rtemstoolkit_tests(ctx)
def install(ctx): def install(ctx):
recurse(ctx) recurse(ctx)
@ -127,9 +134,50 @@ def check_options(ctx, host):
ctx.fatal('unknown host: %s' % (host)); ctx.fatal('unknown host: %s' % (host));
# #
# The doxy command. # Custom commands
# #
from waflib import Build import waflib
class doxy(Build.BuildContext):
class test(waflib.Build.BuildContext):
fun = 'build'
cmd = 'test'
class doxy(waflib.Build.BuildContext):
fun = 'build' fun = 'build'
cmd = 'doxy' cmd = 'doxy'
#
# RTEMS Toolkit Tests.
#
# Run the tests from the top directory so they are run as python modules.
#
def rtemstoolkit_tests(ctx):
log = ctx.path.find_or_declare('tests.log')
ctx.logger = waflib.Logs.make_logger(log.abspath(), 'build')
failures = False
for py in ['2', '3']:
PY = 'PYTHON%s' % (py)
if PY in ctx.env:
from rtemstoolkit import all as toolkit_tests
from rtemstoolkit import args as toolkit_test_args
for tt in toolkit_tests:
test = 'rtemstoolkit.%s' % (tt)
ctx.start_msg('Test python%s %s' % (py, test))
cmd = '%s -m %s' % (ctx.env[PY][0], test)
if tt in toolkit_test_args:
cmd += ' ' + ' '.join(toolkit_test_args[tt])
ctx.to_log('test command: ' + cmd)
try:
(out, err) = ctx.cmd_and_log(cmd,
output = waflib.Context.BOTH,
quiet = waflib.Context.BOTH)
ctx.to_log(out)
ctx.to_log(err)
ctx.end_msg('pass')
except waflib.Errors.WafError as e:
failures = True
ctx.to_log(e.stdout)
ctx.to_log(e.stderr)
ctx.end_msg('fail', color = 'RED')
if failures:
ctx.fatal('Test failures')