mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-08-21 16:23:46 +08:00
improve cpu usage test robustness (#20067)
* improve cpu usage test robustness * more fix Co-authored-by: Comma Device <device@comma.ai> old-commit-hash: b85a0f19f4062ed74a9b53f6b58b38bca04f5f6e
This commit is contained in:
@@ -6,10 +6,11 @@ import unittest
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import cereal.messaging as messaging
|
import cereal.messaging as messaging
|
||||||
|
from cereal.services import service_list
|
||||||
from common.basedir import BASEDIR
|
from common.basedir import BASEDIR
|
||||||
from common.timeout import Timeout
|
from common.timeout import Timeout
|
||||||
from panda import Panda
|
|
||||||
from selfdrive.loggerd.config import ROOT
|
from selfdrive.loggerd.config import ROOT
|
||||||
|
import selfdrive.manager as manager
|
||||||
from selfdrive.test.helpers import set_params_enabled
|
from selfdrive.test.helpers import set_params_enabled
|
||||||
from tools.lib.logreader import LogReader
|
from tools.lib.logreader import LogReader
|
||||||
|
|
||||||
@@ -19,11 +20,11 @@ PROCS = [
|
|||||||
("selfdrive.locationd.locationd", 35.0),
|
("selfdrive.locationd.locationd", 35.0),
|
||||||
("selfdrive.controls.plannerd", 20.0),
|
("selfdrive.controls.plannerd", 20.0),
|
||||||
("selfdrive.locationd.paramsd", 12.0),
|
("selfdrive.locationd.paramsd", 12.0),
|
||||||
("./_modeld", 7.12),
|
|
||||||
("./camerad", 7.07),
|
("./camerad", 7.07),
|
||||||
("./_sensord", 6.17),
|
("./_sensord", 6.17),
|
||||||
("./_ui", 5.82),
|
("./_ui", 5.82),
|
||||||
("selfdrive.controls.radard", 5.67),
|
("selfdrive.controls.radard", 5.67),
|
||||||
|
("./_modeld", 4.48),
|
||||||
("./boardd", 3.63),
|
("./boardd", 3.63),
|
||||||
("./_dmonitoringmodeld", 2.67),
|
("./_dmonitoringmodeld", 2.67),
|
||||||
("selfdrive.logmessaged", 1.7),
|
("selfdrive.logmessaged", 1.7),
|
||||||
@@ -79,12 +80,12 @@ class TestOnroad(unittest.TestCase):
|
|||||||
os.environ['FINGERPRINT'] = "TOYOTA COROLLA TSS2 2019"
|
os.environ['FINGERPRINT'] = "TOYOTA COROLLA TSS2 2019"
|
||||||
set_params_enabled()
|
set_params_enabled()
|
||||||
|
|
||||||
Panda().reset()
|
|
||||||
|
|
||||||
initial_segments = set(Path(ROOT).iterdir())
|
initial_segments = set(Path(ROOT).iterdir())
|
||||||
|
|
||||||
# start manager and run openpilot for a minute
|
# start manager and run openpilot for a minute
|
||||||
try:
|
try:
|
||||||
|
manager.build()
|
||||||
|
manager.manager_prepare()
|
||||||
manager_path = os.path.join(BASEDIR, "selfdrive/manager.py")
|
manager_path = os.path.join(BASEDIR, "selfdrive/manager.py")
|
||||||
proc = subprocess.Popen(["python", manager_path])
|
proc = subprocess.Popen(["python", manager_path])
|
||||||
|
|
||||||
@@ -93,21 +94,26 @@ class TestOnroad(unittest.TestCase):
|
|||||||
while sm.rcv_frame['carState'] < 0:
|
while sm.rcv_frame['carState'] < 0:
|
||||||
sm.update(1000)
|
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:
|
finally:
|
||||||
proc.terminate()
|
proc.terminate()
|
||||||
if proc.wait(20) is None:
|
if proc.wait(60) is None:
|
||||||
proc.kill()
|
proc.kill()
|
||||||
|
|
||||||
new_segments = set(Path(ROOT).iterdir()) - initial_segments
|
cls.lr = list(LogReader(os.path.join(str(cls.segments[1]), "rlog.bz2")))
|
||||||
|
|
||||||
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")))
|
|
||||||
|
|
||||||
def test_cpu_usage(self):
|
def test_cpu_usage(self):
|
||||||
proclogs = [m for m in self.lr if m.which() == 'procLog']
|
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)
|
self.assertTrue(cpu_ok)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user