2021-02-27 09:14:37 +08:00
|
|
|
import os
|
2022-10-26 02:33:02 +08:00
|
|
|
import glob
|
2021-02-27 09:14:37 +08:00
|
|
|
import signal
|
|
|
|
import subprocess
|
|
|
|
import time
|
|
|
|
|
2023-08-21 11:49:55 +08:00
|
|
|
from openpilot.common.basedir import BASEDIR
|
|
|
|
from openpilot.common.timeout import Timeout
|
2024-01-12 09:02:47 +08:00
|
|
|
from openpilot.tools.plotjuggler.juggle import DEMO_ROUTE, install
|
2021-02-27 09:14:37 +08:00
|
|
|
|
2022-10-26 02:33:02 +08:00
|
|
|
PJ_DIR = os.path.join(BASEDIR, "tools/plotjuggler")
|
|
|
|
|
2024-05-18 02:01:44 +08:00
|
|
|
class TestPlotJuggler:
|
2021-02-27 09:14:37 +08:00
|
|
|
|
2022-01-01 08:44:57 +08:00
|
|
|
def test_demo(self):
|
|
|
|
install()
|
2021-02-27 09:14:37 +08:00
|
|
|
|
2022-10-26 02:33:02 +08:00
|
|
|
pj = os.path.join(PJ_DIR, "juggle.py")
|
2024-01-12 09:02:47 +08:00
|
|
|
with subprocess.Popen(f'QT_QPA_PLATFORM=offscreen {pj} "{DEMO_ROUTE}/:2"',
|
|
|
|
stderr=subprocess.PIPE, shell=True, start_new_session=True) as p:
|
2023-08-29 01:26:19 +08:00
|
|
|
# Wait for "Done reading Rlog data" signal from the plugin
|
|
|
|
output = "\n"
|
|
|
|
with Timeout(180, error_msg=output):
|
|
|
|
while output.splitlines()[-1] != "Done reading Rlog data":
|
|
|
|
output += p.stderr.readline().decode("utf-8")
|
|
|
|
|
|
|
|
# ensure plotjuggler didn't crash after exiting the plugin
|
2024-05-26 02:40:10 +08:00
|
|
|
time.sleep(2)
|
2024-05-18 02:01:44 +08:00
|
|
|
assert p.poll() is None
|
2023-08-29 01:26:19 +08:00
|
|
|
os.killpg(os.getpgid(p.pid), signal.SIGTERM)
|
2021-02-27 09:14:37 +08:00
|
|
|
|
2024-05-18 02:01:44 +08:00
|
|
|
assert "Raw file read failed" not in output
|
2024-01-17 04:40:49 +08:00
|
|
|
|
2022-10-26 02:33:02 +08:00
|
|
|
# TODO: also test that layouts successfully load
|
2024-05-18 02:01:44 +08:00
|
|
|
def test_layouts(self, subtests):
|
2022-10-26 02:33:02 +08:00
|
|
|
bad_strings = (
|
|
|
|
# if a previously loaded file is defined,
|
|
|
|
# PJ will throw a warning when loading the layout
|
|
|
|
"fileInfo",
|
|
|
|
"previouslyLoaded_Datafiles",
|
|
|
|
)
|
|
|
|
for fn in glob.glob(os.path.join(PJ_DIR, "layouts/*")):
|
|
|
|
name = os.path.basename(fn)
|
2024-05-18 02:01:44 +08:00
|
|
|
with subtests.test(layout=name):
|
2022-10-26 02:33:02 +08:00
|
|
|
with open(fn) as f:
|
|
|
|
layout = f.read()
|
|
|
|
violations = [s for s in bad_strings if s in layout]
|
|
|
|
assert len(violations) == 0, f"These should be stripped out of the layout: {str(violations)}"
|