summaryrefslogtreecommitdiff
path: root/wscript
diff options
context:
space:
mode:
authorChris Johns <chrisj@rtems.org>2018-11-23 15:02:52 +1100
committerChris Johns <chrisj@rtems.org>2018-11-23 15:02:52 +1100
commit7e5cdeaabeaa95b8533af626b99a43c93e5ecf6f (patch)
tree2ecd175bb744024567e6823353cd50b795604b35 /wscript
parent6fa09650b8a936782aa9352e5e23001360317b9d (diff)
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.
Diffstat (limited to 'wscript')
-rw-r--r--wscript54
1 files changed, 51 insertions, 3 deletions
diff --git a/wscript b/wscript
index adbe766..c2e55c7 100644
--- a/wscript
+++ b/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')