Skip to content

Commit

Permalink
mavsdk_tests: better process management
Browse files Browse the repository at this point in the history
We now error if px4 or gzserver are already running on startup, and we
also make sure to terminate what we started if interrupted.
  • Loading branch information
julianoes authored and LorenzMeier committed Dec 26, 2019
1 parent 2bbe4da commit 22bac03
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/mavsdk_tests/mavsdk_test_runner.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/usr/bin/env python3

import argparse
import atexit
import datetime
import os
import psutil
import subprocess
import sys

Expand Down Expand Up @@ -51,13 +53,17 @@ def start(self, config):
stdout=f, stderr=f
)

atexit.register(self.stop)

def wait(self, timeout_s):
try:
return self.process.wait(timeout=timeout_s)
except subprocess.TimeoutExpired:
self.stop()

def stop(self):
atexit.unregister(self.stop)

returncode = self.process.poll()
if returncode is not None:
return returncode
Expand Down Expand Up @@ -117,13 +123,31 @@ def __init__(self, workspace_dir, log_dir, config):
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()
parser.add_argument("--log-dir",
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']))
Expand Down

0 comments on commit 22bac03

Please sign in to comment.