diff --git a/Tools/autotest/autotest.py b/Tools/autotest/autotest.py index 7c5c644bb3..f5b3974697 100755 --- a/Tools/autotest/autotest.py +++ b/Tools/autotest/autotest.py @@ -142,6 +142,38 @@ def build_examples(): return True +def build_unit_tests(): + """Build tests.""" + for target in ['linux']: + print("Running build.unit_tests for %s" % target) + try: + util.build_tests(target) + except Exception as e: + print("Failed build.unit_tests on board=%s" % target) + print(str(e)) + return False + + return True + +def run_unit_test(test): + print("Running (%s)" % test) + subprocess.check_call([test]) + + +def run_unit_tests(): + binary_dir = util.reltopdir(os.path.join('build', + 'linux', + 'tests', + )) + tests = glob.glob("%s/*" % binary_dir) + success = True + for test in tests: + try: + run_unit_test(test) + except Exception as e: + print("Exception running (%s): %s" % (test, e.message)) + success = False + return success def param_parse_filepath(): return util.reltopdir('Tools/autotest/param_metadata/param_parse.py') @@ -367,6 +399,12 @@ def run_step(step): if step == 'convertgpx': return convert_gpx() + if step == 'build.unit_tests': + return build_unit_tests() + + if step == 'run.unit_tests': + return run_unit_tests() + raise RuntimeError("Unknown step %s" % step) @@ -630,6 +668,9 @@ if __name__ == "__main__": 'build.Examples', 'build.Parameters', + 'build.unit_tests', + 'run.unit_tests', + 'build.ArduPlane', 'defaults.ArduPlane', 'fly.ArduPlane', diff --git a/Tools/autotest/pysim/util.py b/Tools/autotest/pysim/util.py index dedf83a7b6..6002a1374a 100644 --- a/Tools/autotest/pysim/util.py +++ b/Tools/autotest/pysim/util.py @@ -134,6 +134,17 @@ def build_examples(board, j=None, debug=False, clean=False): run_cmd(cmd_make, directory=topdir(), checkfail=True, show=True) return True +def build_tests(board, j=None, debug=False, clean=False): + # first configure + waf_configure(board, j=j, debug=debug) + + # then clean + if clean: + waf_clean() + + # then build + run_cmd([relwaf(), "tests"], directory=topdir(), checkfail=True, show=True) + return True # list of pexpect children to close on exit close_list = []