Tools: Autotest.py: Allow autotest subtests completion

This commit is contained in:
Pierre Kancir 2020-07-30 16:59:28 +02:00 committed by Peter Barker
parent 4535e749e1
commit 1fa6138ca1
1 changed files with 50 additions and 3 deletions

View File

@ -609,17 +609,37 @@ def run_tests(steps):
return passed return passed
def list_subtests(*args, **kwargs):
for vehicle in sorted(['Sub', 'Copter', 'Plane', 'Tracker', 'Rover', 'QuadPlane', 'BalanceBot', 'Helicopter']): vehicle_list = ['Sub', 'Copter', 'Plane', 'Tracker', 'Rover', 'QuadPlane', 'BalanceBot', 'Helicopter']
def list_subtests():
"""Print the list of tests and tests description for each vehicle."""
for vehicle in sorted(vehicle_list):
tester_class = tester_class_map["test.%s" % vehicle] tester_class = tester_class_map["test.%s" % vehicle]
tester = tester_class("/bin/true", None) tester = tester_class("/bin/true", None)
subtests = tester.tests() subtests = tester.tests()
print("%s:" % vehicle) print("%s:" % vehicle)
for subtest in sorted(subtests, key=lambda x : x[0]): for subtest in sorted(subtests, key=lambda x: x[0]):
(name, description, function) = subtest (name, description, function) = subtest
print(" %s: %s" % (name, description)) print(" %s: %s" % (name, description))
print("") print("")
def list_subtests_for_vehicle(vehicle_type):
"""Print the list of tests for a vehicle."""
# Check that we aren't in a sub test
if "Test" in vehicle_type:
vehicle_type = re.findall('[A-Z][a-z0-9]*', vehicle_type)[0]
if vehicle_type in vehicle_list:
tester_class = tester_class_map["test.%s" % vehicle_type]
tester = tester_class("/bin/true", None)
subtests = tester.tests()
for subtest in sorted(subtests, key=lambda x: x[0]):
(name, _, _) = subtest
print("%s " % name, end='')
print("") # needed to clear the trailing %
if __name__ == "__main__": if __name__ == "__main__":
''' main program ''' ''' main program '''
os.environ['PYTHONUNBUFFERED'] = '1' os.environ['PYTHONUNBUFFERED'] = '1'
@ -744,6 +764,21 @@ if __name__ == "__main__":
help="force a specific AHRS type (e.g. 10 for SITL-ekf") help="force a specific AHRS type (e.g. 10 for SITL-ekf")
parser.add_option_group(group_sim) parser.add_option_group(group_sim)
group_completion = optparse.OptionGroup(parser, "Completion helpers")
group_completion.add_option("--list-vehicles",
action='store_true',
default=False,
help='list available vehicles')
group_completion.add_option("--list-vehicles-test",
action='store_true',
default=False,
help='list available vehicle tester')
group_completion.add_option("--list-subtests-for-vehicle",
type='string',
default="",
help='list available subtests for a vehicle e.g Copter')
parser.add_option_group(group_completion)
opts, args = parser.parse_args() opts, args = parser.parse_args()
steps = [ steps = [
@ -842,6 +877,18 @@ if __name__ == "__main__":
list_subtests() list_subtests()
sys.exit(0) sys.exit(0)
if opts.list_subtests_for_vehicle:
list_subtests_for_vehicle(opts.list_subtests_for_vehicle)
sys.exit(0)
if opts.list_vehicles_test:
print(' '.join(__bin_names.keys()))
sys.exit(0)
if opts.list_vehicles:
print(' '.join(vehicle_list))
sys.exit(0)
util.mkdir_p(buildlogs_dirpath()) util.mkdir_p(buildlogs_dirpath())
lckfile = buildlogs_path('autotest.lck') lckfile = buildlogs_path('autotest.lck')