mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-04 05:05:19 +08:00
mavsdk_tests: restart SITL after each test case
This commit is contained in:
@@ -130,15 +130,27 @@ class GazeboRunner(Runner):
|
|||||||
|
|
||||||
|
|
||||||
class TestRunner(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)
|
super().__init__(log_dir)
|
||||||
self.env = {"PATH": os.environ['PATH']}
|
self.env = {"PATH": os.environ['PATH']}
|
||||||
self.cmd = workspace_dir + \
|
self.cmd = workspace_dir + \
|
||||||
"/build/px4_sitl_default/mavsdk_tests"
|
"/build/px4_sitl_default/mavsdk_tests"
|
||||||
self.args = [config['test_filter']]
|
self.args = [test]
|
||||||
self.log_prefix = "test_runner"
|
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):
|
def is_running(process_name):
|
||||||
for proc in psutil.process_iter(attrs=['name']):
|
for proc in psutil.process_iter(attrs=['name']):
|
||||||
if proc.info['name'] == process_name:
|
if proc.info['name'] == process_name:
|
||||||
@@ -186,28 +198,35 @@ def main():
|
|||||||
print("Running test group for '{}' with filter '{}'"
|
print("Running test group for '{}' with filter '{}'"
|
||||||
.format(group['model'], group['test_filter']))
|
.format(group['model'], group['test_filter']))
|
||||||
|
|
||||||
px4_runner = Px4Runner(
|
tests = determine_tests(os.getcwd(), group['test_filter'])
|
||||||
os.getcwd(), args.log_dir, args.speed_factor)
|
|
||||||
px4_runner.start(group)
|
|
||||||
|
|
||||||
gazebo_runner = GazeboRunner(
|
for test in tests:
|
||||||
os.getcwd(), args.log_dir, args.speed_factor)
|
|
||||||
gazebo_runner.start(group)
|
|
||||||
|
|
||||||
test_runner = TestRunner(os.getcwd(), args.log_dir, group)
|
print("Running test '{}'".format(test))
|
||||||
test_runner.start(group)
|
|
||||||
|
|
||||||
returncode = test_runner.wait(group['timeout_min'])
|
px4_runner = Px4Runner(
|
||||||
was_success = (returncode == 0)
|
os.getcwd(), args.log_dir, args.speed_factor)
|
||||||
print("Test group: {}".format("Success" if was_success else "Fail"))
|
px4_runner.start(group)
|
||||||
if not was_success:
|
|
||||||
overall_success = False
|
|
||||||
|
|
||||||
returncode = gazebo_runner.stop()
|
gazebo_runner = GazeboRunner(
|
||||||
print("Gazebo exited with {}".format(returncode))
|
os.getcwd(), args.log_dir, args.speed_factor)
|
||||||
|
gazebo_runner.start(group)
|
||||||
|
|
||||||
px4_runner.stop()
|
test_runner = TestRunner(os.getcwd(), args.log_dir, group, test)
|
||||||
print("PX4 exited with {}".format(returncode))
|
test_runner.start(group)
|
||||||
|
|
||||||
|
returncode = test_runner.wait(group['timeout_min'])
|
||||||
|
was_success = (returncode == 0)
|
||||||
|
print("Test '{}': {}".
|
||||||
|
format(test, "Success" if was_success else "Fail"))
|
||||||
|
if not was_success:
|
||||||
|
overall_success = False
|
||||||
|
|
||||||
|
returncode = gazebo_runner.stop()
|
||||||
|
print("Gazebo exited with {}".format(returncode))
|
||||||
|
|
||||||
|
px4_runner.stop()
|
||||||
|
print("PX4 exited with {}".format(returncode))
|
||||||
|
|
||||||
print("Overall result: {}".
|
print("Overall result: {}".
|
||||||
format("SUCCESS" if overall_success else "FAIL"))
|
format("SUCCESS" if overall_success else "FAIL"))
|
||||||
|
|||||||
Reference in New Issue
Block a user