mavsdk_tests: better process management

We now error if px4 or gzserver are already running on startup, and we
also make sure to terminate what we started if interrupted.
This commit is contained in:
Julian Oes 2019-11-11 13:44:16 +01:00 committed by Lorenz Meier
parent 2bbe4dac25
commit 22bac037ed
1 changed files with 24 additions and 0 deletions

View File

@ -1,8 +1,10 @@
#!/usr/bin/env python3
import argparse
import atexit
import datetime
import os
import psutil
import subprocess
import sys
@ -51,6 +53,8 @@ class Runner:
stdout=f, stderr=f
)
atexit.register(self.stop)
def wait(self, timeout_s):
try:
return self.process.wait(timeout=timeout_s)
@ -58,6 +62,8 @@ class Runner:
self.stop()
def stop(self):
atexit.unregister(self.stop)
returncode = self.process.poll()
if returncode is not None:
return returncode
@ -117,6 +123,21 @@ class TestRunner(Runner):
self.log_prefix = "test_runner"
def is_everything_ready():
result = True
for proc in psutil.process_iter(attrs=['name']):
if proc.info['name'] == 'gzserver':
print("gzserver process already running\n"
"run `killall gzserver` and try again")
result = False
elif proc.info['name'] == 'px4':
print("px4 process already running\n"
"run `killall px4` and try again")
result = False
return result
def main():
parser = argparse.ArgumentParser()
@ -124,6 +145,9 @@ def main():
help="Directory for log files, stdout if not provided")
args = parser.parse_args()
if not is_everything_ready():
return
for group in test_matrix:
print("Running test group for '{}' with filter '{}'"
.format(group['model'], group['test_filter']))