IQ.Pilot Prebuilt Release @ 27f668a

This commit is contained in:
IQ.Lvbs CI [bot]
2026-09-03 18:23:24 -05:00
commit b073c5182b
2554 changed files with 679696 additions and 0 deletions

View File

View File

@@ -0,0 +1,136 @@
import os
import pytest
import signal
import time
from iqpilot.cereal import car
from iqpilot.common.params import Params
import iqpilot.system.manager.manager as manager
from iqpilot.system.manager.process import BundleProcess, NativeProcess, ensure_running
from iqpilot.system.manager.process_config import managed_processes, procs
from iqpilot.system.hardware import HARDWARE
os.environ['FAKEUPLOAD'] = "1"
MAX_STARTUP_TIME = 3
BLACKLIST_PROCS = ['manage_hephaestusd', 'pandad', 'pigeond']
class TestManager:
def setup_method(self):
HARDWARE.set_power_save(False)
# ensure clean CarParams
params = Params()
params.clear_all()
def teardown_method(self):
manager.manager_cleanup()
@pytest.mark.linux
def test_manager_prepare(self):
os.environ['PREPAREONLY'] = '1'
manager.main()
def test_duplicate_procs(self):
assert len(procs) == len(managed_processes), "Duplicate process names"
def test_models_manager_uses_private_bundle(self):
proc = managed_processes["models_manager"]
assert isinstance(proc, BundleProcess)
assert proc.bundle == "iqpilot_model_selector_private"
assert proc.entry == "iqpilot_private.models.manager"
def test_modeld_watchdog_restarts_stalled_process(self, mocker):
proc = mocker.Mock()
proc.proc.is_alive.return_value = True
deadline = manager.update_modeld_watchdog(None, True, False, proc, 10.0)
assert deadline == 10.0 + manager.MODELD_WATCHDOG_TIMEOUT
assert manager.update_modeld_watchdog(deadline, True, False, proc, deadline - 0.1) == deadline
proc.restart.assert_not_called()
next_deadline = manager.update_modeld_watchdog(deadline, True, False, proc, deadline)
proc.restart.assert_called_once_with()
assert next_deadline == deadline + manager.MODELD_WATCHDOG_TIMEOUT
def test_modeld_watchdog_tracks_output_and_resets(self, mocker):
proc = mocker.Mock()
proc.proc.is_alive.return_value = True
deadline = manager.update_modeld_watchdog(20.0, True, True, proc, 15.0)
assert deadline == 15.0 + manager.MODELD_WATCHDOG_TIMEOUT
assert manager.update_modeld_watchdog(deadline, False, False, proc, 16.0) is None
proc.proc.is_alive.return_value = False
assert manager.update_modeld_watchdog(deadline, True, False, proc, 16.0) is None
proc.restart.assert_not_called()
def test_bundle_process_stops_with_sigterm(self, mocker):
proc = BundleProcess("test", "bundle", "entry", lambda *_: True)
proc.proc = mocker.Mock(exitcode=None, pid=123)
proc.proc.is_alive.return_value = True
signal_mock = mocker.patch.object(proc, "signal")
proc.stop(block=False)
signal_mock.assert_called_once_with(signal.SIGTERM)
def test_native_process_stop_timeout(self, mocker):
proc = NativeProcess("test", ".", ["true"], lambda *_: True)
native_process = mocker.Mock(exitcode=None, pid=123)
proc.proc = native_process
signal_mock = mocker.patch.object(proc, "signal")
join_mock = mocker.patch("iqpilot.system.manager.process.join_process", side_effect=lambda process, _: setattr(process, "exitcode", 0))
assert proc.stop(timeout=30) == 0
signal_mock.assert_called_once_with(signal.SIGINT)
join_mock.assert_called_once_with(native_process, 30)
def test_blacklisted_procs(self):
# TODO: ensure there are blacklisted procs until we have a dedicated test
assert len(BLACKLIST_PROCS), "No blacklisted procs to test not_run"
@pytest.mark.linux
def test_set_params_with_default_value(self):
params = Params()
params.clear_all()
os.environ['PREPAREONLY'] = '1'
manager.main()
for k in params.all_keys():
default_value = params.get_default_value(k)
if default_value is not None:
assert params.get(k) == default_value
assert params.get("OpenpilotEnabledToggle")
assert params.get("RouteCount") == 0
@pytest.mark.tici
def test_clean_exit(self, subtests):
"""
Ensure all processes exit cleanly when stopped.
"""
HARDWARE.set_power_save(False)
manager.manager_init()
CP = car.CarParams.new_message()
procs = ensure_running(managed_processes.values(), True, Params(), CP, not_run=BLACKLIST_PROCS)
time.sleep(10)
for p in procs:
with subtests.test(proc=p.name):
state = p.get_process_state_msg()
assert state.running, f"{p.name} not running"
exit_code = p.stop(retry=False)
assert p.name not in BLACKLIST_PROCS, f"{p.name} was started"
assert exit_code is not None, f"{p.name} failed to exit"
# TODO: interrupted blocking read exits with 1 in cereal. use a more unique return code
exit_codes = [0, 1]
if p.sigkill:
exit_codes = [-signal.SIGKILL]
assert exit_code in exit_codes, f"{p.name} died with {exit_code}"

View File

@@ -0,0 +1,65 @@
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
def test_generated_header_declares_the_stamp_for_the_compile_fallback():
assert "#define SERVICES_REGISTRY_STAMPED 1" in build_header()
def test_pre_build_purge_drops_an_unstamped_or_old_header(tmp_path):
from iqpilot.system.manager.build import purge_stale_registry_header
_write(tmp_path, "iqpilot/cereal/services.h", b"static std::map<std::string, service> services = {};\n")
_write(tmp_path, "iqpilot/cereal/messaging/socketmaster.o", b"o")
_write(tmp_path, "iqpilot/cereal/libsocketmaster.a", b"a")
assert purge_stale_registry_header(str(tmp_path))
assert not (tmp_path / "iqpilot/cereal/services.h").exists()
assert not (tmp_path / "iqpilot/cereal/messaging/socketmaster.o").exists()
assert not (tmp_path / "iqpilot/cereal/libsocketmaster.a").exists()
_write(tmp_path, "iqpilot/cereal/services.h", build_header().encode())
assert not purge_stale_registry_header(str(tmp_path))
assert (tmp_path / "iqpilot/cereal/services.h").exists()
assert not purge_stale_registry_header(str(tmp_path / "nowhere"))