improve cpu usage test robustness (#20067)

* improve cpu usage test robustness

* more fix

Co-authored-by: Comma Device <device@comma.ai>
This commit is contained in:
Adeeb Shihadeh 2021-02-11 15:15:05 -08:00 committed by GitHub
parent fe7f3f0ec6
commit b85a0f19f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,10 +6,11 @@ import unittest
from pathlib import Path
import cereal.messaging as messaging
from cereal.services import service_list
from common.basedir import BASEDIR
from common.timeout import Timeout
from panda import Panda
from selfdrive.loggerd.config import ROOT
import selfdrive.manager as manager
from selfdrive.test.helpers import set_params_enabled
from tools.lib.logreader import LogReader
@ -19,11 +20,11 @@ PROCS = [
("selfdrive.locationd.locationd", 35.0),
("selfdrive.controls.plannerd", 20.0),
("selfdrive.locationd.paramsd", 12.0),
("./_modeld", 7.12),
("./camerad", 7.07),
("./_sensord", 6.17),
("./_ui", 5.82),
("selfdrive.controls.radard", 5.67),
("./_modeld", 4.48),
("./boardd", 3.63),
("./_dmonitoringmodeld", 2.67),
("selfdrive.logmessaged", 1.7),
@ -79,12 +80,12 @@ class TestOnroad(unittest.TestCase):
os.environ['FINGERPRINT'] = "TOYOTA COROLLA TSS2 2019"
set_params_enabled()
Panda().reset()
initial_segments = set(Path(ROOT).iterdir())
# start manager and run openpilot for a minute
try:
manager.build()
manager.manager_prepare()
manager_path = os.path.join(BASEDIR, "selfdrive/manager.py")
proc = subprocess.Popen(["python", manager_path])
@ -93,21 +94,26 @@ class TestOnroad(unittest.TestCase):
while sm.rcv_frame['carState'] < 0:
sm.update(1000)
time.sleep(60)
# make sure we get at least two full segments
cls.segments = []
with Timeout(180, "timed out waiting for logs"):
while len(cls.segments) < 3:
new_paths = set(Path(ROOT).iterdir()) - initial_segments
segs = [p for p in new_paths if "--" in str(p)]
cls.segments = sorted(segs, key=lambda s: int(str(s).rsplit('--')[-1]))
time.sleep(5)
finally:
proc.terminate()
if proc.wait(20) is None:
if proc.wait(60) is None:
proc.kill()
new_segments = set(Path(ROOT).iterdir()) - initial_segments
segments = [p for p in new_segments if len(list(p.iterdir())) > 1]
cls.segment = [s for s in segments if str(s).endswith("--0")][0]
cls.lr = list(LogReader(os.path.join(str(cls.segment), "rlog.bz2")))
cls.lr = list(LogReader(os.path.join(str(cls.segments[1]), "rlog.bz2")))
def test_cpu_usage(self):
proclogs = [m for m in self.lr if m.which() == 'procLog']
cpu_ok = check_cpu_usage(proclogs[5], proclogs[-3])
self.assertGreater(len(proclogs), service_list['procLog'].frequency * 45, "insufficient samples")
cpu_ok = check_cpu_usage(proclogs[0], proclogs[-1])
self.assertTrue(cpu_ok)
if __name__ == "__main__":