IQ.Pilot Release Commit @ 717ce45

This commit is contained in:
IQ.Lvbs CI [bot]
2026-09-02 15:53:36 -05:00
parent 43ee82d228
commit 4fb3da761f
11 changed files with 230 additions and 95 deletions

View File

@@ -12,6 +12,9 @@
#include "common/timing.h"
#include "msgq/ipc.h"
const char *messaging_registry_tag();
bool messaging_has_service(const char *name);
class SubMaster {
public:
SubMaster(const std::vector<const char *> &service_list, const std::vector<const char *> &poll = {},

View File

@@ -49,7 +49,7 @@ SubMaster::SubMaster(const std::vector<const char *> &service_list, const std::v
poller_ = Poller::create();
for (auto name : service_list) {
if (services.count(std::string(name)) == 0) {
fprintf(stderr, "SubMaster: unknown service '%s', skipping subscription\n", name);
fprintf(stderr, "SubMaster: unknown service '%s' in %s, skipping subscription\n", name, SERVICES_REGISTRY_TAG);
continue;
}
@@ -71,6 +71,14 @@ SubMaster::SubMaster(const std::vector<const char *> &service_list, const std::v
}
}
const char *messaging_registry_tag() {
return SERVICES_REGISTRY_TAG;
}
bool messaging_has_service(const char *name) {
return services.count(std::string(name)) != 0;
}
void SubMaster::update(int timeout) {
for (auto &kv : messages_) kv.second->updated = false;

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python3
import hashlib
from enum import IntEnum
from typing import Optional
@@ -134,6 +135,22 @@ SERVICE_LIST = {name: Service(*vals) for
idx, (name, vals) in enumerate(_services.items())}
REGISTRY_TAG_PREFIX = "IQ_SERVICES_REGISTRY:"
def registry_hash() -> str:
digest = hashlib.sha256()
for name in sorted(SERVICE_LIST):
v = SERVICE_LIST[name]
decimation = -1 if v.decimation is None else v.decimation
digest.update(f"{name}|{int(v.should_log)}|{v.frequency:f}|{decimation}|{int(v.queue_size)}\n".encode())
return digest.hexdigest()[:16]
def registry_tag() -> str:
return REGISTRY_TAG_PREFIX + registry_hash()
def build_header():
h = ""
h += "/* THIS IS AN AUTOGENERATED FILE, PLEASE EDIT services.py */\n"
@@ -151,6 +168,7 @@ def build_header():
h += ' { "%s", {"%s", %s, %f, %d, %d}},\n' % \
(k, k, should_log, v.frequency, decimation, v.queue_size)
h += "};\n"
h += f'static const char SERVICES_REGISTRY_TAG[] = "{registry_tag()}";\n'
h += "#endif\n"
return h

View File

@@ -734,6 +734,13 @@ int AtlasLocator::run() {
const std::initializer_list<const char *> service_list = {gps_location_socket, "cameraOdometry", "extrinsicsCalibration",
"carState", "accelerometer", "gyroscope"};
for (const char *service : service_list) {
if (!messaging_has_service(service)) {
LOGE("service '%s' is missing from the compiled service registry %s: stale build, rebuild required", service, messaging_registry_tag());
return 2;
}
}
SubMaster sm(service_list, {}, nullptr, {gps_location_socket});
PubMaster pm({"iqLiveLocation"});

View File

@@ -128,12 +128,13 @@ class TestIQLocdProc:
if case in ("odometry_short", "odometry_empty", "odometry_nan", "odometry_nan_std"):
msg = messaging.new_message("cameraOdometry")
odo = msg.cameraOdometry
if case == "odometry_short":
odo.rot = [0.0] * 6; odo.trans = [0.0] * 6; odo.rotStd = [0.01] * 6; odo.transStd = [0.01] * 6
elif case == "odometry_nan":
odo.rot = [float("nan"), 0.0, 0.0]; odo.trans = [0.0] * 3; odo.rotStd = [0.01] * 3; odo.transStd = [0.01] * 3
elif case == "odometry_nan_std":
odo.rot = [0.0] * 3; odo.trans = [0.0] * 3; odo.rotStd = [float("nan"), 0.01, 0.01]; odo.transStd = [0.01] * 3
shapes = {
"odometry_short": ([0.0] * 6, [0.0] * 6, [0.01] * 6, [0.01] * 6),
"odometry_nan": ([float("nan"), 0.0, 0.0], [0.0] * 3, [0.01] * 3, [0.01] * 3),
"odometry_nan_std": ([0.0] * 3, [0.0] * 3, [float("nan"), 0.01, 0.01], [0.01] * 3),
}
if case in shapes:
odo.rot, odo.trans, odo.rotStd, odo.transStd = shapes[case]
elif case in ("calibration_short", "calibration_nan"):
msg = messaging.new_message("extrinsicsCalibration")
msg.extrinsicsCalibration.calStatus = "calibrated"

View File

@@ -51,7 +51,44 @@ class _SilentProgress:
pass
def build(spinner, dirty: bool = False, minimal: bool = False, show_error_window: bool = True) -> None:
REGISTRY_ARTIFACTS = [
"iqpilot/cereal/services.h",
"iqpilot/cereal/messaging/socketmaster.o",
"iqpilot/cereal/libsocketmaster.a",
"iqpilot/cereal/messaging/bridge",
"iqpilot/selfdrive/iqlocd/iqlocd",
"iqpilot/selfdrive/pandad/pandad",
"iqpilot/system/camerad/camerad",
"iqpilot/system/loggerd/loggerd",
"iqpilot/system/loggerd/encoderd",
"iqpilot/system/loggerd/bootlog",
]
def stale_registry_artifacts(basedir: str = BASEDIR) -> list[str]:
from iqpilot.cereal.services import REGISTRY_TAG_PREFIX, registry_tag
expected = registry_tag().encode()
prefix = REGISTRY_TAG_PREFIX.encode()
stale = []
for rel in REGISTRY_ARTIFACTS:
path = os.path.join(basedir, rel)
if not os.path.isfile(path):
continue
with open(path, "rb") as f:
data = f.read()
if prefix in data and expected not in data:
stale.append(rel)
return stale
def purge_registry_artifacts(stale: list[str], basedir: str = BASEDIR) -> None:
for rel in set(stale) | set(REGISTRY_ARTIFACTS[:3]):
path = os.path.join(basedir, rel)
if os.path.isfile(path):
os.remove(path)
def build(spinner, dirty: bool = False, minimal: bool = False, show_error_window: bool = True, registry_retry: bool = False) -> None:
env = os.environ.copy()
env.pop('PWD', None)
env['SCONS_PROGRESS'] = "1"
@@ -110,6 +147,22 @@ def build(spinner, dirty: bool = False, minimal: bool = False, show_error_window
t.wait_for_exit()
exit(1)
stale = stale_registry_artifacts()
if stale and not registry_retry:
cloudlog.error(f"compiled service registry is stale in {', '.join(stale)}, rebuilding messaging")
purge_registry_artifacts(stale)
build(spinner, dirty, minimal, show_error_window, registry_retry=True)
return
if stale:
error_s = "compiled service registry is still stale after rebuild: " + ", ".join(stale)
add_file_handler(cloudlog)
cloudlog.error(error_s)
spinner.close()
if not os.getenv("CI") and show_error_window:
with TextWindow("IQ.Pilot failed to build\n \n" + error_s) as t:
t.wait_for_exit()
exit(1)
# enforce max cache size
cache_files = [f for f in CACHE_DIR.rglob('*') if f.is_file()]
cache_files.sort(key=lambda f: f.stat().st_mtime)

View File

@@ -0,0 +1,45 @@
import os
import re
from iqpilot.cereal.services import REGISTRY_TAG_PREFIX, SERVICE_LIST, build_header, registry_hash, registry_tag
from iqpilot.system.manager.build import REGISTRY_ARTIFACTS, purge_registry_artifacts, stale_registry_artifacts
def test_registry_tag_is_derived_from_the_service_list():
assert re.fullmatch(r"[0-9a-f]{16}", registry_hash())
assert registry_tag() == REGISTRY_TAG_PREFIX + registry_hash()
assert "extrinsicsCalibration" in SERVICE_LIST
def test_generated_header_embeds_the_tag():
header = build_header()
assert f'static const char SERVICES_REGISTRY_TAG[] = "{registry_tag()}";' in header
assert '{ "extrinsicsCalibration", {"extrinsicsCalibration"' in header
def _write(tmp_path, rel, payload):
path = tmp_path / rel
path.parent.mkdir(parents=True, exist_ok=True)
path.write_bytes(payload)
return path
def test_stale_detection_flags_only_binaries_carrying_an_old_tag(tmp_path):
current = registry_tag().encode()
old = (REGISTRY_TAG_PREFIX + "0" * 16).encode()
_write(tmp_path, "iqpilot/selfdrive/iqlocd/iqlocd", b"\x7fELF" + old)
_write(tmp_path, "iqpilot/system/loggerd/loggerd", b"\x7fELF" + current)
_write(tmp_path, "iqpilot/system/camerad/camerad", b"\x7fELF no registry linked")
assert stale_registry_artifacts(str(tmp_path)) == ["iqpilot/selfdrive/iqlocd/iqlocd"]
def test_purge_removes_the_stale_binary_and_the_messaging_table(tmp_path):
for rel in REGISTRY_ARTIFACTS:
_write(tmp_path, rel, b"x")
purge_registry_artifacts(["iqpilot/selfdrive/iqlocd/iqlocd"], str(tmp_path))
remaining = [rel for rel in REGISTRY_ARTIFACTS if os.path.isfile(tmp_path / rel)]
assert "iqpilot/selfdrive/iqlocd/iqlocd" not in remaining
assert "iqpilot/cereal/services.h" not in remaining
assert "iqpilot/cereal/messaging/socketmaster.o" not in remaining
assert "iqpilot/cereal/libsocketmaster.a" not in remaining
assert "iqpilot/system/loggerd/loggerd" in remaining