From 6a3da36632a2c3bbd6662a7a36c983a9474c723e Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Tue, 5 Sep 2023 15:32:57 -0700 Subject: [PATCH] sensord: test updates for provisioning (#29768) * sensord: test updates for provisioning * fix --------- Co-authored-by: Comma Device old-commit-hash: 0908be80bda09d7cc476693ab17208cf0fca4ded --- system/sensord/tests/test_sensord.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/system/sensord/tests/test_sensord.py b/system/sensord/tests/test_sensord.py index e3cd77a1a3..ccdce3b4e5 100755 --- a/system/sensord/tests/test_sensord.py +++ b/system/sensord/tests/test_sensord.py @@ -9,6 +9,7 @@ import cereal.messaging as messaging from cereal import log from cereal.services import service_list from openpilot.common.gpio import get_irqs_for_action +from openpilot.common.timeout import Timeout from openpilot.system.hardware import TICI from openpilot.selfdrive.manager.process_config import managed_processes @@ -73,15 +74,24 @@ def get_irq_count(irq: int): def read_sensor_events(duration_sec): sensor_types = ['accelerometer', 'gyroscope', 'magnetometer', 'accelerometer2', 'gyroscope2', 'temperatureSensor', 'temperatureSensor2'] - esocks = {} + socks = {} + poller = messaging.Poller() events = defaultdict(list) for stype in sensor_types: - esocks[stype] = messaging.sub_sock(stype, timeout=0.1) - - start_time_sec = time.monotonic() - while time.monotonic() - start_time_sec < duration_sec: - for esock in esocks: - events[esock] += messaging.drain_sock(esocks[esock]) + socks[stype] = messaging.sub_sock(stype, poller=poller, timeout=100) + + # wait for sensors to come up + with Timeout(60, "sensors didn't come up"): + while len(poller.poll(250)) == 0: + pass + time.sleep(1) + for s in socks.values(): + messaging.drain_sock_raw(s) + + st = time.monotonic() + while time.monotonic() - st < duration_sec: + for s in socks: + events[s] += messaging.drain_sock(socks[s]) time.sleep(0.1) assert sum(map(len, events.values())) != 0, "No sensor events collected!" @@ -101,8 +111,7 @@ class TestSensord(unittest.TestCase): os.system("pkill -f ./_sensord") try: managed_processes["sensord"].start() - time.sleep(3) - cls.sample_secs = 10 + cls.sample_secs = int(os.getenv("SAMPLE_SECS", "10")) cls.events = read_sensor_events(cls.sample_secs) # determine sensord's irq