autotest: add option to test enabling one feature at a time
This commit is contained in:
parent
3e8e846d1d
commit
3a76d248a0
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
Contains functions used to test the ArduPilot build_options.py structures
|
||||
@ -22,6 +22,7 @@ class TestBuildOptions(object):
|
||||
do_step_disable_none=False,
|
||||
do_step_disable_defaults=True,
|
||||
do_step_disable_in_turn=True,
|
||||
do_step_enable_in_turn=True,
|
||||
build_targets=None,
|
||||
board="DevEBoxH7v2",
|
||||
extra_hwdef=None):
|
||||
@ -32,6 +33,7 @@ class TestBuildOptions(object):
|
||||
self.do_step_disable_none = do_step_disable_none
|
||||
self.do_step_run_with_defaults = do_step_disable_defaults
|
||||
self.do_step_disable_in_turn = do_step_disable_in_turn
|
||||
self.do_step_enable_in_turn = do_step_enable_in_turn
|
||||
self.build_targets = build_targets
|
||||
if self.build_targets is None:
|
||||
self.build_targets = self.all_targets()
|
||||
@ -64,7 +66,7 @@ class TestBuildOptions(object):
|
||||
with open(filepath, "w") as f:
|
||||
f.write(content)
|
||||
|
||||
def get_defines(self, feature, options):
|
||||
def get_disable_defines(self, feature, options):
|
||||
'''returns a hash of (name, value) defines to turn feature off -
|
||||
recursively gets dependencies'''
|
||||
ret = {
|
||||
@ -89,8 +91,30 @@ class TestBuildOptions(object):
|
||||
break
|
||||
return ret
|
||||
|
||||
def test_feature(self, feature, options):
|
||||
defines = self.get_defines(feature, options)
|
||||
def update_get_enable_defines_for_feature(self, ret, feature, options):
|
||||
'''recursive function to turn on required feature and what it depends
|
||||
on'''
|
||||
ret[feature.define] = 1
|
||||
if feature.dependency is None:
|
||||
return
|
||||
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) for feature (%s)" %
|
||||
(depname, feature.label))
|
||||
self.update_get_enable_defines_for_feature(ret, dep, options)
|
||||
|
||||
def get_enable_defines(self, feature, options):
|
||||
'''returns a hash of (name, value) defines to turn all features *but* feature (and whatever it depends on) on'''
|
||||
ret = self.get_disable_all_defines()
|
||||
self.update_get_enable_defines_for_feature(ret, feature, options)
|
||||
return ret
|
||||
|
||||
def test_disable_feature(self, feature, options):
|
||||
defines = self.get_disable_defines(feature, options)
|
||||
|
||||
if len(defines.keys()) > 1:
|
||||
self.progress("Disabling %s disables (%s)" % (
|
||||
@ -99,6 +123,18 @@ class TestBuildOptions(object):
|
||||
|
||||
self.test_compile_with_defines(defines)
|
||||
|
||||
def test_enable_feature(self, feature, options):
|
||||
defines = self.get_enable_defines(feature, options)
|
||||
|
||||
enabled = list(filter(lambda x : bool(defines[x]), defines.keys()))
|
||||
|
||||
if len(enabled) > 1:
|
||||
self.progress("Enabling %s enables (%s)" % (
|
||||
feature.define,
|
||||
",".join(enabled)))
|
||||
|
||||
self.test_compile_with_defines(defines)
|
||||
|
||||
def board(self):
|
||||
'''returns board to build for'''
|
||||
return self._board
|
||||
@ -156,17 +192,29 @@ class TestBuildOptions(object):
|
||||
for feature in options:
|
||||
self.progress("Disabling feature %s(%s) (%u/%u)" %
|
||||
(feature.label, feature.define, count, len(options)))
|
||||
self.test_feature(feature, options)
|
||||
self.test_disable_feature(feature, options)
|
||||
count += 1
|
||||
self.disable_in_turn_check_sizes(feature, self.sizes_nothing_disabled)
|
||||
|
||||
def run_enable_in_turn(self):
|
||||
options = self.get_build_options_from_ardupilot_tree()
|
||||
if self.match_glob is not None:
|
||||
options = list(filter(lambda x : fnmatch.fnmatch(x.define, self.match_glob), options))
|
||||
count = 1
|
||||
for feature in options:
|
||||
self.progress("Enabling feature %s(%s) (%u/%u)" %
|
||||
(feature.label, feature.define, count, len(options)))
|
||||
self.test_enable_feature(feature, options)
|
||||
count += 1
|
||||
|
||||
def get_option_by_label(self, label, options):
|
||||
for x in options:
|
||||
if x.label == label:
|
||||
return x
|
||||
raise ValueError("No such option (%s)" % label)
|
||||
|
||||
def run_disable_all(self):
|
||||
def get_disable_all_defines(self):
|
||||
'''returns a hash of defines which turns all features off'''
|
||||
options = self.get_build_options_from_ardupilot_tree()
|
||||
defines = {}
|
||||
for feature in options:
|
||||
@ -174,6 +222,10 @@ class TestBuildOptions(object):
|
||||
if not fnmatch.fnmatch(feature.define, self.match_glob):
|
||||
continue
|
||||
defines[feature.define] = 0
|
||||
return defines
|
||||
|
||||
def run_disable_all(self):
|
||||
defines = self.get_disable_all_defines()
|
||||
self.test_compile_with_defines(defines)
|
||||
|
||||
def run_disable_none(self):
|
||||
@ -191,7 +243,7 @@ class TestBuildOptions(object):
|
||||
# self.progress("Checking deps consistency")
|
||||
options = self.get_build_options_from_ardupilot_tree()
|
||||
for feature in options:
|
||||
self.get_defines(feature, options)
|
||||
self.get_disable_defines(feature, options)
|
||||
|
||||
def run(self):
|
||||
self.check_deps_consistency()
|
||||
@ -207,6 +259,9 @@ class TestBuildOptions(object):
|
||||
if self.do_step_disable_in_turn:
|
||||
self.progress("Running disable-in-turn step")
|
||||
self.run_disable_in_turn()
|
||||
if self.do_step_enable_in_turn:
|
||||
self.progress("Running enable-in-turn step")
|
||||
self.run_enable_in_turn()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
@ -228,6 +283,9 @@ if __name__ == '__main__':
|
||||
parser.add_option("--no-disable-in-turn",
|
||||
action='store_true',
|
||||
help='Do not run the disable-in-turn step')
|
||||
parser.add_option("--no-enable-in-turn",
|
||||
action='store_true',
|
||||
help='Do not run the enable-in-turn step')
|
||||
parser.add_option("--build-targets",
|
||||
type='choice',
|
||||
choices=TestBuildOptions.all_targets(),
|
||||
@ -250,6 +308,7 @@ if __name__ == '__main__':
|
||||
do_step_disable_none=not opts.no_disable_none,
|
||||
do_step_disable_defaults=not opts.no_run_with_defaults,
|
||||
do_step_disable_in_turn=not opts.no_disable_in_turn,
|
||||
do_step_enable_in_turn=not opts.no_enable_in_turn,
|
||||
build_targets=opts.build_targets,
|
||||
board=opts.board,
|
||||
extra_hwdef=opts.extra_hwdef,
|
||||
|
Loading…
Reference in New Issue
Block a user