mavsdk_tests: run test runner, speed up sim

This commit is contained in:
Julian Oes
2019-10-28 16:26:37 +01:00
committed by Lorenz Meier
parent 728a0b033e
commit 2bbe4dac25
+31 -13
View File
@@ -5,7 +5,6 @@ import datetime
import os import os
import subprocess import subprocess
import sys import sys
import time
test_matrix = [ test_matrix = [
@@ -14,11 +13,11 @@ test_matrix = [
"test_filter": "[multicopter]", "test_filter": "[multicopter]",
"timeout_min": 10, "timeout_min": 10,
}, },
{ # {
"model": "standard_vtol", # "model": "standard_vtol",
"test_filter": "[vtol]", # "test_filter": "[vtol]",
"timeout_min": 10, # "timeout_min": 10,
} # }
] ]
@@ -52,6 +51,12 @@ class Runner:
stdout=f, stderr=f stdout=f, stderr=f
) )
def wait(self, timeout_s):
try:
return self.process.wait(timeout=timeout_s)
except subprocess.TimeoutExpired:
self.stop()
def stop(self): def stop(self):
returncode = self.process.poll() returncode = self.process.poll()
if returncode is not None: if returncode is not None:
@@ -95,13 +100,23 @@ class GazeboRunner(Runner):
workspace_dir + "/build/px4_sitl_default/build_gazebo", workspace_dir + "/build/px4_sitl_default/build_gazebo",
"GAZEBO_MODEL_PATH": "GAZEBO_MODEL_PATH":
workspace_dir + "/Tools/sitl_gazebo/models", workspace_dir + "/Tools/sitl_gazebo/models",
"PX4_SIM_SPEED_FACTOR": "1"} "PX4_SIM_SPEED_FACTOR": "5"}
self.cmd = "gzserver" self.cmd = "gzserver"
self.args = ["--verbose", self.args = ["--verbose",
workspace_dir + "/Tools/sitl_gazebo/worlds/iris.world"] workspace_dir + "/Tools/sitl_gazebo/worlds/iris.world"]
self.log_prefix = "gazebo" self.log_prefix = "gazebo"
class TestRunner(Runner):
def __init__(self, workspace_dir, log_dir, config):
super().__init__(log_dir)
self.env = {"PATH": os.environ['PATH']}
self.cmd = workspace_dir + \
"/build/px4_sitl_default/test_mission_multicopter"
self.args = [config['test_filter']]
self.log_prefix = "test_runner"
def main(): def main():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
@@ -113,20 +128,23 @@ 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(os.getcwd(), log_dir=args.log_dir) px4_runner = Px4Runner(os.getcwd(), args.log_dir)
px4_runner.start(group) px4_runner.start(group)
gazebo_runner = GazeboRunner(os.getcwd(), log_dir=args.log_dir) gazebo_runner = GazeboRunner(os.getcwd(), args.log_dir)
gazebo_runner.start(group) gazebo_runner.start(group)
# Run test here test_runner = TestRunner(os.getcwd(), args.log_dir, group)
time.sleep(group['timeout_min']*60) test_runner.start(group)
returncode = test_runner.wait(group['timeout_min']*60)
print("Test exited with {}".format(returncode))
returncode = gazebo_runner.stop() returncode = gazebo_runner.stop()
print("Gazebo stopped with {}".format(returncode)) print("Gazebo exited with {}".format(returncode))
px4_runner.stop() px4_runner.stop()
print("PX4 stopped with {}".format(returncode)) print("PX4 exited with {}".format(returncode))
if __name__ == '__main__': if __name__ == '__main__':