mirror of
https://git.rtems.org/rtems-tools/
synced 2025-05-12 13:05:14 +08:00
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:
parent
6fa09650b8
commit
7e5cdeaabe
27
README
27
README
@ -28,17 +28,32 @@ Building
|
||||
|
||||
To build and install:
|
||||
|
||||
$ ./waf configure --prefix=$HOME/development/rtems/4.11
|
||||
$ ./waf configure --prefix=$HOME/development/rtems/5
|
||||
$ ./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
|
||||
---
|
||||
|
||||
The Waf project can be found here:
|
||||
|
||||
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
|
||||
|
||||
|
@ -46,20 +46,12 @@ all = ['check',
|
||||
'textbox',
|
||||
'version']
|
||||
|
||||
from . import check
|
||||
from . import config
|
||||
from . import configuration
|
||||
from . import error
|
||||
from . import execute
|
||||
from . import git
|
||||
from . import host
|
||||
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
|
||||
args = {
|
||||
'config': ['--file', 'tester/rtems/version.cfg',
|
||||
'--jobs', 'half',
|
||||
'--no-clean'],
|
||||
'mailer': ['--smtp-host', '1.2.3.4',
|
||||
'--mail-to', 'foo@bar.none',
|
||||
'--mail-from', 'me@here.there']
|
||||
|
||||
}
|
||||
|
@ -36,24 +36,12 @@ from __future__ import print_function
|
||||
|
||||
import os
|
||||
|
||||
#
|
||||
# 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
|
||||
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
|
||||
from rtemstoolkit import error
|
||||
from rtemstoolkit import execute
|
||||
from rtemstoolkit import log
|
||||
from rtemstoolkit import options
|
||||
from rtemstoolkit import path
|
||||
from rtemstoolkit import version
|
||||
|
||||
def _check_none(_opts, macro, value, constraint):
|
||||
return True
|
||||
@ -163,12 +151,12 @@ def check_dir(label, path):
|
||||
return _check_dir(None, label, path, 'required', True)
|
||||
|
||||
|
||||
def run():
|
||||
def run(args):
|
||||
import sys
|
||||
try:
|
||||
_opts = options.command_line(argv = sys.argv)
|
||||
_opts = options.command_line(argv = args)
|
||||
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):
|
||||
print('Environment is ok')
|
||||
else:
|
||||
@ -188,4 +176,4 @@ def run():
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
run()
|
||||
run(['tester'])
|
||||
|
@ -44,24 +44,12 @@ import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
#
|
||||
# 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
|
||||
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
|
||||
from rtemstoolkit import error
|
||||
from rtemstoolkit import execute
|
||||
from rtemstoolkit import host
|
||||
from rtemstoolkit import log
|
||||
from rtemstoolkit import options
|
||||
from rtemstoolkit import path
|
||||
|
||||
def _check_bool(value):
|
||||
if value.isdigit():
|
||||
|
@ -35,14 +35,7 @@
|
||||
|
||||
import os
|
||||
|
||||
#
|
||||
# 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
|
||||
from rtemstoolkit import execute
|
||||
|
||||
def cpus():
|
||||
sysctl = '/usr/sbin/sysctl '
|
||||
|
@ -35,16 +35,8 @@
|
||||
|
||||
import os
|
||||
|
||||
#
|
||||
# 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 check
|
||||
from . import execute
|
||||
except (ValueError, SystemError):
|
||||
import check
|
||||
import execute
|
||||
from rtemstoolkit import check
|
||||
from rtemstoolkit import execute
|
||||
|
||||
def cpus():
|
||||
sysctl = '/sbin/sysctl '
|
||||
|
@ -31,20 +31,10 @@
|
||||
|
||||
import os
|
||||
|
||||
#
|
||||
# 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
|
||||
from . import execute
|
||||
from . import log
|
||||
from . import path
|
||||
except (ValueError, SystemError):
|
||||
import error
|
||||
import execute
|
||||
import log
|
||||
import path
|
||||
from rtemstoolkit import error
|
||||
from rtemstoolkit import execute
|
||||
from rtemstoolkit import log
|
||||
from rtemstoolkit import path
|
||||
|
||||
class repo:
|
||||
"""An object to manage a git repo."""
|
||||
@ -220,7 +210,7 @@ class repo:
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
import options
|
||||
from rtemstoolkit import options
|
||||
long_opts = {
|
||||
# key macro handler param defs init
|
||||
}
|
||||
|
@ -36,14 +36,7 @@ from __future__ import print_function
|
||||
|
||||
import os
|
||||
|
||||
#
|
||||
# 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
|
||||
from rtemstoolkit import error
|
||||
|
||||
is_windows = False
|
||||
platform = None
|
||||
@ -113,7 +106,6 @@ def label(mode = 'all'):
|
||||
|
||||
if __name__ == '__main__':
|
||||
import pprint
|
||||
pprint.pprint(platform())
|
||||
_load()
|
||||
print('Name : %s' % (name))
|
||||
if is_windows:
|
||||
|
@ -36,16 +36,8 @@
|
||||
import os
|
||||
import platform
|
||||
|
||||
#
|
||||
# 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
|
||||
from . import path
|
||||
except (ValueError, SystemError):
|
||||
import execute
|
||||
import path
|
||||
from rtemstoolkit import execute
|
||||
from rtemstoolkit import path
|
||||
|
||||
def cpus():
|
||||
processors = '/bin/grep processor /proc/cpuinfo'
|
||||
|
@ -38,14 +38,7 @@ import os
|
||||
import sys
|
||||
import threading
|
||||
|
||||
#
|
||||
# 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
|
||||
from rtemstoolkit import error
|
||||
|
||||
#
|
||||
# A global log.
|
||||
|
@ -40,18 +40,9 @@ import re
|
||||
import os
|
||||
import string
|
||||
|
||||
#
|
||||
# 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
|
||||
from . import log
|
||||
from . import path
|
||||
except (ValueError, SystemError):
|
||||
import error
|
||||
import log
|
||||
import path
|
||||
from rtemstoolkit import error
|
||||
from rtemstoolkit import log
|
||||
from rtemstoolkit import path
|
||||
|
||||
#
|
||||
# Macro tables
|
||||
|
@ -38,18 +38,9 @@ import os
|
||||
import smtplib
|
||||
import socket
|
||||
|
||||
#
|
||||
# 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
|
||||
from . import options
|
||||
from . import path
|
||||
except (ValueError, SystemError):
|
||||
import error
|
||||
import options
|
||||
import path
|
||||
from rtemstoolkit import error
|
||||
from rtemstoolkit import options
|
||||
from rtemstoolkit import path
|
||||
|
||||
_options = {
|
||||
'--mail' : 'Send email report or results.',
|
||||
@ -161,10 +152,19 @@ class mail:
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
from rtemstoolkit import macros
|
||||
optargs = {}
|
||||
rtdir = 'rtemstoolkit'
|
||||
defaults = '%s/defaults.mc' % (rtdir)
|
||||
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)
|
||||
print('From: %s' % (m.from_address()))
|
||||
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')
|
||||
|
@ -26,12 +26,8 @@
|
||||
|
||||
import os
|
||||
|
||||
try:
|
||||
from . import check
|
||||
from . import execute
|
||||
except (ValueError, SystemError):
|
||||
import check
|
||||
import execute
|
||||
from rtemstoolkit import check
|
||||
from rtemstoolkit import execute
|
||||
|
||||
def cpus():
|
||||
sysctl = '/sbin/sysctl '
|
||||
|
@ -42,28 +42,14 @@ import os
|
||||
import string
|
||||
import sys
|
||||
|
||||
#
|
||||
# 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
|
||||
from . import execute
|
||||
from . import git
|
||||
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
|
||||
from rtemstoolkit import error
|
||||
from rtemstoolkit import execute
|
||||
from rtemstoolkit import git
|
||||
from rtemstoolkit import host
|
||||
from rtemstoolkit import log
|
||||
from rtemstoolkit import macros
|
||||
from rtemstoolkit import path
|
||||
from rtemstoolkit import version
|
||||
|
||||
basepath = 'tb'
|
||||
|
||||
|
@ -41,16 +41,8 @@ import os
|
||||
import shutil
|
||||
import string
|
||||
|
||||
#
|
||||
# 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
|
||||
from . import log
|
||||
except (ValueError, SystemError):
|
||||
import error
|
||||
import log
|
||||
from rtemstoolkit import error
|
||||
from rtemstoolkit import log
|
||||
|
||||
windows = os.name == 'nt'
|
||||
|
||||
|
@ -71,7 +71,10 @@ def configuration_path(prog = None):
|
||||
2. Ok to directly call os.path.
|
||||
'''
|
||||
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:
|
||||
exec_name = prog
|
||||
exec_name = os.path.abspath(exec_name)
|
||||
|
@ -24,14 +24,9 @@
|
||||
|
||||
import os
|
||||
|
||||
try:
|
||||
from . import check
|
||||
from . import error
|
||||
from . import execute
|
||||
except (ValueError, SystemError):
|
||||
import check
|
||||
import error
|
||||
import execute
|
||||
from rtemstoolkit import check
|
||||
from rtemstoolkit import error
|
||||
from rtemstoolkit import execute
|
||||
|
||||
def cpus():
|
||||
psrinfo = '/sbin/psrinfo|wc -l'
|
||||
|
@ -39,19 +39,12 @@ from __future__ import print_function
|
||||
import copy
|
||||
import os
|
||||
|
||||
#
|
||||
# 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
|
||||
from rtemstoolkit import error
|
||||
|
||||
def line(cols, line = '-', marker = '|', indent = 0, linesep = os.linesep):
|
||||
s = ' ' * indent + marker
|
||||
for c in cols:
|
||||
s += line[0] * (c - 1) + marker
|
||||
s += line[0] * int((c - 1)) + marker
|
||||
return s + 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
|
||||
else:
|
||||
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
|
||||
|
||||
def even_columns(cols, width = 80):
|
||||
per_col = width / 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:
|
||||
columns[remainder] += 1
|
||||
else:
|
||||
|
@ -88,19 +88,10 @@ try:
|
||||
except ImportError:
|
||||
import ConfigParser as configparser
|
||||
|
||||
#
|
||||
# Support to handle importing when installed in a package and as a unit test.
|
||||
# If there is a better way to let us know.
|
||||
#
|
||||
try:
|
||||
from . import error
|
||||
from . import git
|
||||
from . import rtems
|
||||
except (ValueError, SystemError):
|
||||
import error
|
||||
import git
|
||||
import path
|
||||
import rtems
|
||||
from rtemstoolkit import error
|
||||
from rtemstoolkit import git
|
||||
from rtemstoolkit import path
|
||||
from rtemstoolkit import rtems
|
||||
|
||||
#
|
||||
# Default to an internal string.
|
||||
|
@ -34,16 +34,8 @@
|
||||
|
||||
import os
|
||||
|
||||
#
|
||||
# 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
|
||||
from . import execute
|
||||
except (ValueError, SystemError):
|
||||
import error
|
||||
import execute
|
||||
from rtemstoolkit import error
|
||||
from rtemstoolkit import execute
|
||||
|
||||
def cpus():
|
||||
if os.environ.has_key('NUMBER_OF_PROCESSORS'):
|
||||
|
54
wscript
54
wscript
@ -95,6 +95,11 @@ def configure(ctx):
|
||||
ctx.load('python')
|
||||
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.
|
||||
#
|
||||
ctx.env.PYO = 0
|
||||
@ -105,6 +110,8 @@ def build(ctx):
|
||||
if os.path.exists('VERSION'):
|
||||
ctx.install_files('${PREFIX}/share/rtems/rtemstoolkit', ['VERSION'])
|
||||
recurse(ctx)
|
||||
if ctx.cmd == 'test':
|
||||
rtemstoolkit_tests(ctx)
|
||||
|
||||
def install(ctx):
|
||||
recurse(ctx)
|
||||
@ -127,9 +134,50 @@ def check_options(ctx, host):
|
||||
ctx.fatal('unknown host: %s' % (host));
|
||||
|
||||
#
|
||||
# The doxy command.
|
||||
# Custom commands
|
||||
#
|
||||
from waflib import Build
|
||||
class doxy(Build.BuildContext):
|
||||
import waflib
|
||||
|
||||
class test(waflib.Build.BuildContext):
|
||||
fun = 'build'
|
||||
cmd = 'test'
|
||||
|
||||
class doxy(waflib.Build.BuildContext):
|
||||
fun = 'build'
|
||||
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')
|
||||
|
Loading…
x
Reference in New Issue
Block a user