services: capitalize constant service list (#30005)

* rename

* bump

* Apply suggestions from code review
pull/29889/head
Shane Smiskol 2 years ago committed by GitHub
parent 37422d0437
commit 7f073483bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      cereal
  2. 4
      selfdrive/athena/athenad.py
  3. 4
      selfdrive/controls/lib/events.py
  4. 4
      selfdrive/debug/check_lag.py
  5. 6
      selfdrive/debug/count_events.py
  6. 4
      selfdrive/debug/dump.py
  7. 4
      selfdrive/debug/internal/qlog_size.py
  8. 6
      selfdrive/locationd/test/test_locationd.py
  9. 6
      selfdrive/test/process_replay/process_replay.py
  10. 4
      selfdrive/test/profiling/lib.py
  11. 6
      selfdrive/test/test_onroad.py
  12. 6
      system/camerad/test/test_camerad.py
  13. 4
      system/hardware/tici/tests/test_power_draw.py
  14. 12
      system/loggerd/tests/test_loggerd.py
  15. 6
      system/sensord/tests/test_pigeond.py
  16. 4
      system/sensord/tests/test_sensord.py

@ -1 +1 @@
Subproject commit 4b334f6f10877e4a666b23983de2d27934ebf3b1 Subproject commit aed84aeedf8fa7fe2a6bae700ccaf9667d3bdbb0

@ -29,7 +29,7 @@ from websocket import (ABNF, WebSocket, WebSocketException, WebSocketTimeoutExce
import cereal.messaging as messaging import cereal.messaging as messaging
from cereal import log from cereal import log
from cereal.services import service_list from cereal.services import SERVICE_LIST
from openpilot.common.api import Api from openpilot.common.api import Api
from openpilot.common.basedir import PERSIST from openpilot.common.basedir import PERSIST
from openpilot.common.file_helpers import CallbackReader from openpilot.common.file_helpers import CallbackReader
@ -309,7 +309,7 @@ def _do_upload(upload_item: UploadItem, callback: Optional[Callable] = None) ->
# security: user should be able to request any message from their car # security: user should be able to request any message from their car
@dispatcher.add_method @dispatcher.add_method
def getMessage(service: str, timeout: int = 1000) -> dict: def getMessage(service: str, timeout: int = 1000) -> dict:
if service is None or service not in service_list: if service is None or service not in SERVICE_LIST:
raise Exception("invalid service") raise Exception("invalid service")
socket = messaging.sub_sock(service, timeout=timeout) socket = messaging.sub_sock(service, timeout=timeout)

@ -969,7 +969,7 @@ EVENTS: Dict[int, Dict[str, Union[Alert, AlertCallbackType]]] = {
if __name__ == '__main__': if __name__ == '__main__':
# print all alerts by type and priority # print all alerts by type and priority
from cereal.services import service_list from cereal.services import SERVICE_LIST
from collections import defaultdict, OrderedDict from collections import defaultdict, OrderedDict
event_names = {v: k for k, v in EventName.schema.enumerants.items()} event_names = {v: k for k, v in EventName.schema.enumerants.items()}
@ -977,7 +977,7 @@ if __name__ == '__main__':
CP = car.CarParams.new_message() CP = car.CarParams.new_message()
CS = car.CarState.new_message() CS = car.CarState.new_message()
sm = messaging.SubMaster(list(service_list.keys())) sm = messaging.SubMaster(list(SERVICE_LIST.keys()))
for i, alerts in EVENTS.items(): for i, alerts in EVENTS.items():
for et, alert in alerts.items(): for et, alert in alerts.items():

@ -2,7 +2,7 @@
from typing import Dict from typing import Dict
import cereal.messaging as messaging import cereal.messaging as messaging
from cereal.services import service_list from cereal.services import SERVICE_LIST
TO_CHECK = ['carState'] TO_CHECK = ['carState']
@ -20,7 +20,7 @@ if __name__ == "__main__":
t = sm.logMonoTime[s] / 1e9 t = sm.logMonoTime[s] / 1e9
if s in prev_t: if s in prev_t:
expected = 1.0 / (service_list[s].frequency) expected = 1.0 / (SERVICE_LIST[s].frequency)
dt = t - prev_t[s] dt = t - prev_t[s]
if dt > 10 * expected: if dt > 10 * expected:
print(t, s, dt) print(t, s, dt)

@ -7,7 +7,7 @@ from pprint import pprint
from tqdm import tqdm from tqdm import tqdm
from typing import List, Tuple, cast from typing import List, Tuple, cast
from cereal.services import service_list from cereal.services import SERVICE_LIST
from openpilot.tools.lib.route import Route from openpilot.tools.lib.route import Route
from openpilot.tools.lib.logreader import LogReader from openpilot.tools.lib.logreader import LogReader
@ -17,7 +17,7 @@ if __name__ == "__main__":
cnt_valid: Counter = Counter() cnt_valid: Counter = Counter()
cnt_events: Counter = Counter() cnt_events: Counter = Counter()
cams = [s for s in service_list if s.endswith('CameraState')] cams = [s for s in SERVICE_LIST if s.endswith('CameraState')]
cnt_cameras = dict.fromkeys(cams, 0) cnt_cameras = dict.fromkeys(cams, 0)
alerts: List[Tuple[float, str]] = [] alerts: List[Tuple[float, str]] = []
@ -62,7 +62,7 @@ if __name__ == "__main__":
print("\n") print("\n")
print("Cameras") print("Cameras")
for k, v in cnt_cameras.items(): for k, v in cnt_cameras.items():
s = service_list[k] s = SERVICE_LIST[k]
expected_frames = int(s.frequency * duration / cast(float, s.decimation)) expected_frames = int(s.frequency * duration / cast(float, s.decimation))
print(" ", k.ljust(20), f"{v}, {v/expected_frames:.1%} of expected") print(" ", k.ljust(20), f"{v}, {v/expected_frames:.1%} of expected")

@ -8,7 +8,7 @@ import cereal.messaging as messaging
from hexdump import hexdump from hexdump import hexdump
from cereal import log from cereal import log
from cereal.services import service_list from cereal.services import SERVICE_LIST
codecs.register_error("strict", codecs.backslashreplace_errors) codecs.register_error("strict", codecs.backslashreplace_errors)
@ -31,7 +31,7 @@ if __name__ == "__main__":
poller = messaging.Poller() poller = messaging.Poller()
for m in args.socket if len(args.socket) > 0 else service_list: for m in args.socket if len(args.socket) > 0 else SERVICE_LIST:
messaging.sub_sock(m, poller, addr=args.addr) messaging.sub_sock(m, poller, addr=args.addr)
values = None values = None

@ -5,7 +5,7 @@ from collections import defaultdict
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from cereal.services import service_list from cereal.services import SERVICE_LIST
from openpilot.tools.lib.logreader import LogReader from openpilot.tools.lib.logreader import LogReader
from openpilot.tools.lib.route import Route from openpilot.tools.lib.route import Route
@ -49,7 +49,7 @@ if __name__ == "__main__":
msgs_by_type[m.which()].append(m.as_builder().to_bytes()) msgs_by_type[m.which()].append(m.as_builder().to_bytes())
qlog_by_type = defaultdict(list) qlog_by_type = defaultdict(list)
for name, service in service_list.items(): for name, service in SERVICE_LIST.items():
if service.decimation is None: if service.decimation is None:
continue continue

@ -6,7 +6,7 @@ import time
import capnp import capnp
import cereal.messaging as messaging import cereal.messaging as messaging
from cereal.services import service_list from cereal.services import SERVICE_LIST
from openpilot.common.params import Params from openpilot.common.params import Params
from openpilot.common.transformations.coordinates import ecef2geodetic from openpilot.common.transformations.coordinates import ecef2geodetic
@ -74,8 +74,8 @@ class TestLocationdProc(unittest.TestCase):
msgs = [] msgs = []
for sec in range(65): for sec in range(65):
for name in self.LLD_MSGS: for name in self.LLD_MSGS:
for j in range(int(service_list[name].frequency)): for j in range(int(SERVICE_LIST[name].frequency)):
msgs.append(self.get_msg(name, int((sec + j / service_list[name].frequency) * 1e9))) msgs.append(self.get_msg(name, int((sec + j / SERVICE_LIST[name].frequency) * 1e9)))
for msg in sorted(msgs, key=lambda x: x.logMonoTime): for msg in sorted(msgs, key=lambda x: x.logMonoTime):
self.pm.send(msg.which(), msg) self.pm.send(msg.which(), msg)

@ -14,7 +14,7 @@ import capnp
import cereal.messaging as messaging import cereal.messaging as messaging
from cereal import car from cereal import car
from cereal.services import service_list from cereal.services import SERVICE_LIST
from cereal.visionipc import VisionIpcServer, get_endpoint_name as vipc_get_endpoint_name from cereal.visionipc import VisionIpcServer, get_endpoint_name as vipc_get_endpoint_name
from openpilot.common.params import Params from openpilot.common.params import Params
from openpilot.common.prefix import OpenpilotPrefix from openpilot.common.prefix import OpenpilotPrefix
@ -364,7 +364,7 @@ def controlsd_rcv_callback(msg, cfg, frame):
socks = [ socks = [
s for s in cfg.subs if s for s in cfg.subs if
frame % int(service_list[msg.which()].frequency / service_list[s].frequency) == 0 frame % int(SERVICE_LIST[msg.which()].frequency / SERVICE_LIST[s].frequency) == 0
] ]
if "sendcan" in socks and (frame - 1) < 2000: if "sendcan" in socks and (frame - 1) < 2000:
socks.remove("sendcan") socks.remove("sendcan")
@ -428,7 +428,7 @@ class FrequencyBasedRcvCallback:
resp_sockets = [ resp_sockets = [
s for s in cfg.subs s for s in cfg.subs
if frame % max(1, int(service_list[msg.which()].frequency / service_list[s].frequency)) == 0 if frame % max(1, int(SERVICE_LIST[msg.which()].frequency / SERVICE_LIST[s].frequency)) == 0
] ]
return bool(len(resp_sockets)) return bool(len(resp_sockets))

@ -1,5 +1,5 @@
from collections import defaultdict, deque from collections import defaultdict, deque
from cereal.services import service_list from cereal.services import SERVICE_LIST
import cereal.messaging as messaging import cereal.messaging as messaging
import capnp import capnp
@ -67,7 +67,7 @@ class SubMaster(messaging.SubMaster):
self.msgs = list(reversed(self.msgs)) self.msgs = list(reversed(self.msgs))
for s in services: for s in services:
self.freq[s] = service_list[s].frequency self.freq[s] = SERVICE_LIST[s].frequency
try: try:
data = messaging.new_message(s) data = messaging.new_message(s)
except capnp.lib.capnp.KjException: except capnp.lib.capnp.KjException:

@ -13,7 +13,7 @@ from pathlib import Path
from cereal import car from cereal import car
import cereal.messaging as messaging import cereal.messaging as messaging
from cereal.services import service_list from cereal.services import SERVICE_LIST
from openpilot.common.basedir import BASEDIR from openpilot.common.basedir import BASEDIR
from openpilot.common.timeout import Timeout from openpilot.common.timeout import Timeout
from openpilot.common.params import Params from openpilot.common.params import Params
@ -179,7 +179,7 @@ class TestOnroad(unittest.TestCase):
continue continue
with self.subTest(service=s): with self.subTest(service=s):
assert len(msgs) >= math.floor(service_list[s].frequency*55) assert len(msgs) >= math.floor(SERVICE_LIST[s].frequency*55)
def test_cloudlog_size(self): def test_cloudlog_size(self):
msgs = [m for m in self.lr if m.which() == 'logMessage'] msgs = [m for m in self.lr if m.which() == 'logMessage']
@ -356,7 +356,7 @@ class TestOnroad(unittest.TestCase):
raise Exception(f"missing {s}") raise Exception(f"missing {s}")
ts = np.diff(msgs) / 1e9 ts = np.diff(msgs) / 1e9
dt = 1 / service_list[s].frequency dt = 1 / SERVICE_LIST[s].frequency
try: try:
np.testing.assert_allclose(np.mean(ts), dt, rtol=0.03, err_msg=f"{s} - failed mean timing check") np.testing.assert_allclose(np.mean(ts), dt, rtol=0.03, err_msg=f"{s} - failed mean timing check")

@ -6,7 +6,7 @@ from collections import defaultdict
import cereal.messaging as messaging import cereal.messaging as messaging
from cereal import log from cereal import log
from cereal.services import service_list from cereal.services import SERVICE_LIST
from openpilot.selfdrive.manager.process_config import managed_processes from openpilot.selfdrive.manager.process_config import managed_processes
from openpilot.system.hardware import TICI from openpilot.system.hardware import TICI
@ -43,10 +43,10 @@ class TestCamerad(unittest.TestCase):
for cam, msgs in cls.logs.items(): for cam, msgs in cls.logs.items():
if cls.sensor_type is None: if cls.sensor_type is None:
cls.sensor_type = getattr(msgs[0], msgs[0].which()).sensor.raw cls.sensor_type = getattr(msgs[0], msgs[0].which()).sensor.raw
expected_frames = service_list[cam].frequency * TEST_TIMESPAN expected_frames = SERVICE_LIST[cam].frequency * TEST_TIMESPAN
assert expected_frames*0.95 < len(msgs) < expected_frames*1.05, f"unexpected frame count {cam}: {expected_frames=}, got {len(msgs)}" assert expected_frames*0.95 < len(msgs) < expected_frames*1.05, f"unexpected frame count {cam}: {expected_frames=}, got {len(msgs)}"
dts = np.abs(np.diff([getattr(m, m.which()).timestampSof/1e6 for m in msgs]) - 1000/service_list[cam].frequency) dts = np.abs(np.diff([getattr(m, m.which()).timestampSof/1e6 for m in msgs]) - 1000/SERVICE_LIST[cam].frequency)
assert (dts < FRAME_DELTA_TOLERANCE[cls.sensor_type]).all(), f"{cam} dts(ms) out of spec: max diff {dts.max()}, 99 percentile {np.percentile(dts, 99)}" assert (dts < FRAME_DELTA_TOLERANCE[cls.sensor_type]).all(), f"{cam} dts(ms) out of spec: max diff {dts.max()}, 99 percentile {np.percentile(dts, 99)}"
for m in msgs: for m in msgs:

@ -8,7 +8,7 @@ from tabulate import tabulate
from typing import List from typing import List
import cereal.messaging as messaging import cereal.messaging as messaging
from cereal.services import service_list from cereal.services import SERVICE_LIST
from openpilot.system.hardware import HARDWARE, TICI from openpilot.system.hardware import HARDWARE, TICI
from openpilot.system.hardware.tici.power_monitor import get_power from openpilot.system.hardware.tici.power_monitor import get_power
from openpilot.selfdrive.manager.process_config import managed_processes from openpilot.selfdrive.manager.process_config import managed_processes
@ -91,7 +91,7 @@ class TestPowerDraw(unittest.TestCase):
cur = used[proc.name] cur = used[proc.name]
expected = proc.power expected = proc.power
msgs_received = sum(msg_counts[msg] for msg in proc.msgs) msgs_received = sum(msg_counts[msg] for msg in proc.msgs)
msgs_expected = int(sum(SAMPLE_TIME * service_list[msg].frequency for msg in proc.msgs)) msgs_expected = int(sum(SAMPLE_TIME * SERVICE_LIST[msg].frequency for msg in proc.msgs))
tab.append([proc.name, round(expected, 2), round(cur, 2), msgs_expected, msgs_received]) tab.append([proc.name, round(expected, 2), round(cur, 2), msgs_expected, msgs_received])
with self.subTest(proc=proc.name): with self.subTest(proc=proc.name):
self.assertTrue(math.isclose(cur, expected, rel_tol=proc.rtol, abs_tol=proc.atol)) self.assertTrue(math.isclose(cur, expected, rel_tol=proc.rtol, abs_tol=proc.atol))

@ -12,7 +12,7 @@ from typing import Dict, List
import cereal.messaging as messaging import cereal.messaging as messaging
from cereal import log from cereal import log
from cereal.services import service_list from cereal.services import SERVICE_LIST
from openpilot.common.basedir import BASEDIR from openpilot.common.basedir import BASEDIR
from openpilot.common.params import Params from openpilot.common.params import Params
from openpilot.common.timeout import Timeout from openpilot.common.timeout import Timeout
@ -27,8 +27,8 @@ from openpilot.common.transformations.camera import tici_f_frame_size, tici_d_fr
SentinelType = log.Sentinel.SentinelType SentinelType = log.Sentinel.SentinelType
CEREAL_SERVICES = [f for f in log.Event.schema.union_fields if f in service_list CEREAL_SERVICES = [f for f in log.Event.schema.union_fields if f in SERVICE_LIST
and service_list[f].should_log and "encode" not in f.lower()] and SERVICE_LIST[f].should_log and "encode" not in f.lower()]
class TestLoggerd(unittest.TestCase): class TestLoggerd(unittest.TestCase):
@ -219,8 +219,8 @@ class TestLoggerd(unittest.TestCase):
self.assertEqual(expected_val, bootlog_val) self.assertEqual(expected_val, bootlog_val)
def test_qlog(self): def test_qlog(self):
qlog_services = [s for s in CEREAL_SERVICES if service_list[s].decimation is not None] qlog_services = [s for s in CEREAL_SERVICES if SERVICE_LIST[s].decimation is not None]
no_qlog_services = [s for s in CEREAL_SERVICES if service_list[s].decimation is None] no_qlog_services = [s for s in CEREAL_SERVICES if SERVICE_LIST[s].decimation is None]
services = random.sample(qlog_services, random.randint(2, min(10, len(qlog_services)))) + \ services = random.sample(qlog_services, random.randint(2, min(10, len(qlog_services)))) + \
random.sample(no_qlog_services, random.randint(2, min(10, len(no_qlog_services)))) random.sample(no_qlog_services, random.randint(2, min(10, len(no_qlog_services))))
@ -245,7 +245,7 @@ class TestLoggerd(unittest.TestCase):
self.assertEqual(recv_cnt, 0, f"got {recv_cnt} {s} msgs in qlog") self.assertEqual(recv_cnt, 0, f"got {recv_cnt} {s} msgs in qlog")
else: else:
# check logged message count matches decimation # check logged message count matches decimation
expected_cnt = (len(msgs) - 1) // service_list[s].decimation + 1 expected_cnt = (len(msgs) - 1) // SERVICE_LIST[s].decimation + 1
self.assertEqual(recv_cnt, expected_cnt, f"expected {expected_cnt} msgs for {s}, got {recv_cnt}") self.assertEqual(recv_cnt, expected_cnt, f"expected {expected_cnt} msgs for {s}, got {recv_cnt}")
def test_rlog(self): def test_rlog(self):

@ -3,7 +3,7 @@ import time
import unittest import unittest
import cereal.messaging as messaging import cereal.messaging as messaging
from cereal.services import service_list from cereal.services import SERVICE_LIST
from openpilot.common.gpio import gpio_read from openpilot.common.gpio import gpio_read
from openpilot.selfdrive.test.helpers import with_processes from openpilot.selfdrive.test.helpers import with_processes
from openpilot.selfdrive.manager.process_config import managed_processes from openpilot.selfdrive.manager.process_config import managed_processes
@ -26,10 +26,10 @@ class TestPigeond(unittest.TestCase):
sm = messaging.SubMaster(['ubloxRaw']) sm = messaging.SubMaster(['ubloxRaw'])
# setup time # setup time
for _ in range(int(5 * service_list['ubloxRaw'].frequency)): for _ in range(int(5 * SERVICE_LIST['ubloxRaw'].frequency)):
sm.update() sm.update()
for _ in range(int(10 * service_list['ubloxRaw'].frequency)): for _ in range(int(10 * SERVICE_LIST['ubloxRaw'].frequency)):
sm.update() sm.update()
assert sm.all_checks() assert sm.all_checks()

@ -7,7 +7,7 @@ from collections import namedtuple, defaultdict
import cereal.messaging as messaging import cereal.messaging as messaging
from cereal import log from cereal import log
from cereal.services import service_list from cereal.services import SERVICE_LIST
from openpilot.common.gpio import get_irqs_for_action from openpilot.common.gpio import get_irqs_for_action
from openpilot.common.timeout import Timeout from openpilot.common.timeout import Timeout
from openpilot.system.hardware import TICI from openpilot.system.hardware import TICI
@ -172,7 +172,7 @@ class TestSensord(unittest.TestCase):
for s, msgs in self.events.items(): for s, msgs in self.events.items():
with self.subTest(sensor=s): with self.subTest(sensor=s):
freq = len(msgs) / self.sample_secs freq = len(msgs) / self.sample_secs
ef = service_list[s].frequency ef = SERVICE_LIST[s].frequency
assert ef*0.85 <= freq <= ef*1.15 assert ef*0.85 <= freq <= ef*1.15
def test_logmonottime_timestamp_diff(self): def test_logmonottime_timestamp_diff(self):

Loading…
Cancel
Save