mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-29 20:18:31 -04:00
waf: add support to run (unit) tests
We're currently using the tests standard error for reporting tests. We can add TAP later to integrate with other tools. Additionally, this patch simplifies the exclude patterns passed to collect_dirs_to_recurse.
This commit is contained in:
parent
d77b308f72
commit
8556b5dfb8
@ -1,6 +1,8 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
from waflib import Logs
|
||||
|
||||
SOURCE_EXTS = [
|
||||
'*.S',
|
||||
'*.c',
|
||||
@ -129,3 +131,59 @@ def vehicle_stlib(bld, **kw):
|
||||
defines=_get_legacy_defines(vehicle),
|
||||
idx=_get_next_idx(),
|
||||
)
|
||||
|
||||
def find_tests(bld, use=[]):
|
||||
features = ''
|
||||
if bld.cmd == 'check':
|
||||
features='test'
|
||||
|
||||
for f in bld.path.ant_glob(incl='*.cpp'):
|
||||
target = f.change_ext('.' + bld.env.BOARD)
|
||||
bld.program(
|
||||
features=features,
|
||||
target=target,
|
||||
source=[f],
|
||||
use=use,
|
||||
)
|
||||
|
||||
def test_summary(bld):
|
||||
from io import BytesIO
|
||||
import sys
|
||||
|
||||
if not hasattr(bld, 'utest_results'):
|
||||
Logs.info('check: no test run')
|
||||
return
|
||||
|
||||
fails = []
|
||||
|
||||
for filename, exit_code, out, err in bld.utest_results:
|
||||
Logs.pprint('GREEN' if exit_code == 0 else 'YELLOW',
|
||||
' %s' % filename,
|
||||
'returned %d' % exit_code)
|
||||
|
||||
if exit_code != 0:
|
||||
fails.append(filename)
|
||||
elif not bld.options.check_verbose:
|
||||
continue
|
||||
|
||||
if len(out):
|
||||
buf = BytesIO(out)
|
||||
for line in buf:
|
||||
print(" OUT: %s" % line.decode(), end='', file=sys.stderr)
|
||||
print()
|
||||
|
||||
if len(err):
|
||||
buf = BytesIO(err)
|
||||
for line in buf:
|
||||
print(" ERR: %s" % line.decode(), end='', file=sys.stderr)
|
||||
print()
|
||||
|
||||
if not fails:
|
||||
Logs.info('check: All %u tests passed!' % len(bld.utest_results))
|
||||
return
|
||||
|
||||
Logs.error('check: %u of %u tests failed' %
|
||||
(len(fails), len(bld.utest_results)))
|
||||
|
||||
for filename in fails:
|
||||
Logs.error(' %s' % filename)
|
||||
|
28
wscript
28
wscript
@ -6,6 +6,7 @@ import sys
|
||||
sys.path.insert(0, 'Tools/ardupilotwaf/')
|
||||
|
||||
import ardupilotwaf
|
||||
import waflib
|
||||
|
||||
# TODO: implement a command 'waf help' that shows the basic tasks a
|
||||
# developer might want to do: e.g. how to configure a board, compile a
|
||||
@ -134,16 +135,22 @@ BOARDS = {
|
||||
BOARDS_NAMES = sorted(list(BOARDS.keys()))
|
||||
|
||||
def options(opt):
|
||||
opt.load('compiler_cxx compiler_c')
|
||||
opt.load('compiler_cxx compiler_c waf_unit_test')
|
||||
opt.add_option('--board',
|
||||
action='store',
|
||||
choices=BOARDS_NAMES,
|
||||
default='sitl',
|
||||
help='Target board to build, choices are %s' % BOARDS_NAMES)
|
||||
|
||||
g = opt.add_option_group('Check options')
|
||||
g.add_option('--check-verbose',
|
||||
action='store_true',
|
||||
help='Output all test programs')
|
||||
|
||||
def configure(cfg):
|
||||
cfg.load('compiler_cxx compiler_c')
|
||||
cfg.load('clang_compilation_database')
|
||||
cfg.load('waf_unit_test')
|
||||
|
||||
cfg.msg('Setting board to', cfg.options.board)
|
||||
cfg.env.BOARD = cfg.options.board
|
||||
@ -198,11 +205,26 @@ def build(bld):
|
||||
vehicles.sort()
|
||||
|
||||
tools = collect_dirs_to_recurse(bld, 'Tools/*')
|
||||
examples = collect_dirs_to_recurse(bld, 'libraries/*/examples/*', excl='*/AP_HAL_*/* */SITL/*')
|
||||
examples = collect_dirs_to_recurse(bld,
|
||||
'libraries/*/examples/*',
|
||||
excl='libraries/AP_HAL_* libraries/SITL')
|
||||
|
||||
tests = collect_dirs_to_recurse(bld,
|
||||
'**/tests',
|
||||
excl='modules Tools libraries/AP_HAL_* libraries/SITL')
|
||||
board_tests = ['libraries/%s/**/tests' % l for l in bld.env.AP_LIBRARIES]
|
||||
tests.extend(collect_dirs_to_recurse(bld, board_tests))
|
||||
|
||||
hal_examples = []
|
||||
for l in bld.env.AP_LIBRARIES:
|
||||
hal_examples.extend(collect_dirs_to_recurse(bld, 'libraries/' + l + '/examples/*'))
|
||||
|
||||
for d in vehicles + tools + examples + hal_examples:
|
||||
for d in vehicles + tools + examples + hal_examples + tests:
|
||||
bld.recurse(d)
|
||||
|
||||
if bld.cmd == 'check':
|
||||
bld.add_post_fun(ardupilotwaf.test_summary)
|
||||
|
||||
class CheckContext(waflib.Build.BuildContext):
|
||||
'''executes tests after build'''
|
||||
cmd = 'check'
|
||||
|
Loading…
Reference in New Issue
Block a user