mirror of https://github.com/ArduPilot/ardupilot
autotest: add test_build_options to test each entry in build_options.py
This commit is contained in:
parent
b449e45ed6
commit
29b8b12538
|
@ -96,7 +96,7 @@ def relwaf():
|
|||
return "./modules/waf/waf-light"
|
||||
|
||||
|
||||
def waf_configure(board, j=None, debug=False, math_check_indexes=False, coverage=False, ekf_single=False, postype_single=False, sitl_32bit=False, extra_args=[]):
|
||||
def waf_configure(board, j=None, debug=False, math_check_indexes=False, coverage=False, ekf_single=False, postype_single=False, sitl_32bit=False, extra_args=[], extra_hwdef=None):
|
||||
cmd_configure = [relwaf(), "configure", "--board", board]
|
||||
if debug:
|
||||
cmd_configure.append('--debug')
|
||||
|
@ -110,6 +110,8 @@ def waf_configure(board, j=None, debug=False, math_check_indexes=False, coverage
|
|||
cmd_configure.append('--postype-single')
|
||||
if sitl_32bit:
|
||||
cmd_configure.append('--sitl-32bit')
|
||||
if extra_hwdef is not None:
|
||||
cmd_configure.extend(['--extra-hwdef', extra_hwdef])
|
||||
if j is not None:
|
||||
cmd_configure.extend(['-j', str(j)])
|
||||
pieces = [shlex.split(x) for x in extra_args]
|
||||
|
@ -122,6 +124,12 @@ def waf_clean():
|
|||
run_cmd([relwaf(), "clean"], directory=topdir(), checkfail=True)
|
||||
|
||||
|
||||
def waf_build(target=None):
|
||||
cmd = [relwaf(), "build"]
|
||||
if target is not None:
|
||||
cmd.append(target)
|
||||
run_cmd(cmd, directory=topdir(), checkfail=True)
|
||||
|
||||
def build_SITL(build_target, j=None, debug=False, board='sitl', clean=True, configure=True, math_check_indexes=False, coverage=False,
|
||||
ekf_single=False, postype_single=False, sitl_32bit=False, extra_configure_args=[]):
|
||||
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Contains functions used to test the ArduPilot build_options.py structures
|
||||
|
||||
AP_FLAKE8_CLEAN
|
||||
"""
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
|
||||
import os
|
||||
|
||||
from pysim import util
|
||||
|
||||
|
||||
# swiped from app.py:
|
||||
def get_build_options_from_ardupilot_tree():
|
||||
'''return a list of build options'''
|
||||
import importlib.util
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
"build_options.py",
|
||||
os.path.join(os.path.dirname(os.path.realpath(__file__)),
|
||||
'..', 'scripts', 'build_options.py'))
|
||||
mod = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(mod)
|
||||
return mod.BUILD_OPTIONS
|
||||
|
||||
|
||||
def write_defines_to_file(defines, filepath):
|
||||
content = "\n".join(["define %s %s" % (a, b) for (a, b) in defines.items()])
|
||||
with open(filepath, "w") as f:
|
||||
f.write(content)
|
||||
|
||||
|
||||
def get_defines(feature, options):
|
||||
'''returns a hash of (name, value) defines to turn feature off -
|
||||
recursively gets dependencies'''
|
||||
ret = {
|
||||
feature.define: 0,
|
||||
}
|
||||
if feature.dependency is None:
|
||||
return ret
|
||||
for depname in feature.dependency.split(','):
|
||||
dep = None
|
||||
for f in options:
|
||||
if f.label == depname:
|
||||
dep = f
|
||||
if dep is None:
|
||||
raise ValueError("Invalid dep (%s)" % dep)
|
||||
ret.update(get_defines(dep, options))
|
||||
return ret
|
||||
|
||||
|
||||
def test_feature(feature, options):
|
||||
defines = get_defines(feature, options)
|
||||
extra_hwdef_filepath = "/tmp/extra.hwdef"
|
||||
write_defines_to_file(defines, extra_hwdef_filepath)
|
||||
util.waf_configure(
|
||||
"CubeOrange",
|
||||
extra_hwdef=extra_hwdef_filepath,
|
||||
)
|
||||
for t in 'copter', 'plane', 'rover', 'antennatracker', 'sub', 'blimp':
|
||||
try:
|
||||
util.waf_build(t)
|
||||
except Exception:
|
||||
print("Failed to build (%s) with (%s) disabled" %
|
||||
(t, feature.label))
|
||||
raise
|
||||
|
||||
|
||||
def run():
|
||||
options = get_build_options_from_ardupilot_tree()
|
||||
count = 1
|
||||
for feature in options:
|
||||
print("##### Disabling feature %s(%s) (%u/%u)" %
|
||||
(feature.label, feature.define, count, len(options)))
|
||||
test_feature(feature, options)
|
||||
count += 1
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
run()
|
Loading…
Reference in New Issue