Browse Source

mavsdk_tests: restart SITL after each test case

sbg
Julian Oes 5 years ago committed by Lorenz Meier
parent
commit
580ea06fb7
  1. 27
      test/mavsdk_tests/mavsdk_test_runner.py

27
test/mavsdk_tests/mavsdk_test_runner.py

@ -130,15 +130,27 @@ class GazeboRunner(Runner): @@ -130,15 +130,27 @@ class GazeboRunner(Runner):
class TestRunner(Runner):
def __init__(self, workspace_dir, log_dir, config):
def __init__(self, workspace_dir, log_dir, config, test):
super().__init__(log_dir)
self.env = {"PATH": os.environ['PATH']}
self.cmd = workspace_dir + \
"/build/px4_sitl_default/mavsdk_tests"
self.args = [config['test_filter']]
self.args = [test]
self.log_prefix = "test_runner"
def determine_tests(workspace_dir, filter):
cmd = workspace_dir + "/build/px4_sitl_default/mavsdk_tests"
args = ["--list-test-names-only", filter]
p = subprocess.Popen(
[cmd] + args,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
tests = str(p.stdout.read().decode("utf-8")).strip().split('\n')
return tests
def is_running(process_name):
for proc in psutil.process_iter(attrs=['name']):
if proc.info['name'] == process_name:
@ -186,6 +198,12 @@ def main(): @@ -186,6 +198,12 @@ def main():
print("Running test group for '{}' with filter '{}'"
.format(group['model'], group['test_filter']))
tests = determine_tests(os.getcwd(), group['test_filter'])
for test in tests:
print("Running test '{}'".format(test))
px4_runner = Px4Runner(
os.getcwd(), args.log_dir, args.speed_factor)
px4_runner.start(group)
@ -194,12 +212,13 @@ def main(): @@ -194,12 +212,13 @@ def main():
os.getcwd(), args.log_dir, args.speed_factor)
gazebo_runner.start(group)
test_runner = TestRunner(os.getcwd(), args.log_dir, group)
test_runner = TestRunner(os.getcwd(), args.log_dir, group, test)
test_runner.start(group)
returncode = test_runner.wait(group['timeout_min'])
was_success = (returncode == 0)
print("Test group: {}".format("Success" if was_success else "Fail"))
print("Test '{}': {}".
format(test, "Success" if was_success else "Fail"))
if not was_success:
overall_success = False

Loading…
Cancel
Save