mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-10-28 00:53:45 +08:00
Fix model runtime test fixtures
This commit is contained in:
@@ -1,25 +1,44 @@
|
||||
"""Persistent startup cache selection; not GPU or road qualification."""
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
from openpilot.starpilot.models.runtime_bridge import runtime
|
||||
from openpilot.starpilot.models import manager
|
||||
from openpilot.starpilot.models.runtime_bridge import native, runtime
|
||||
|
||||
|
||||
@pytest.mark.parametrize("family", ["legacy9d", "native02e"])
|
||||
@pytest.mark.parametrize("role", ["driving", "monitoring"])
|
||||
def test_inference_cache_survives_reboot_without_changing_role_isolation(role):
|
||||
def test_inference_cache_survives_reboot_without_changing_role_isolation(role, family):
|
||||
selected = {"role": role}
|
||||
plan = SimpleNamespace(family=family)
|
||||
with (patch("openpilot.common.hardware.AGNOS", True),
|
||||
patch.object(runtime, "_selection", None),
|
||||
patch.object(runtime, "_plan", None),
|
||||
patch.object(manager, "freeze_runtime", return_value=plan) as freeze,
|
||||
patch.object(native, "prepare", return_value=selected) as native_prepare,
|
||||
patch.object(runtime, "_verify_policy") as verify,
|
||||
patch.object(runtime, "activate", return_value=selected) as activate):
|
||||
assert runtime.prepare(role) is selected
|
||||
verify.assert_called_once()
|
||||
activate.assert_called_once_with(runtime.BUNDLE, runtime.MANIFEST_SHA256,
|
||||
runtime.LEGACY_REVISION, role, Path("/data/starpilot-model-runtime"))
|
||||
if role == "driving":
|
||||
freeze.assert_called_once_with(recovery_small_only=False)
|
||||
else:
|
||||
freeze.assert_not_called()
|
||||
if role == "driving" and family == "legacy9d":
|
||||
verify.assert_called_once()
|
||||
activate.assert_called_once_with(runtime.BUNDLE, runtime.MANIFEST_SHA256,
|
||||
runtime.LEGACY_REVISION, role, Path("/data/starpilot-model-runtime"))
|
||||
native_prepare.assert_not_called()
|
||||
else:
|
||||
native_prepare.assert_called_once_with(role, plan if role == "driving" else None)
|
||||
verify.assert_not_called()
|
||||
activate.assert_not_called()
|
||||
assert runtime.prepare(role) is selected
|
||||
assert activate.call_count == 1
|
||||
assert (activate.call_count if role == "driving" and family == "legacy9d" else native_prepare.call_count) == 1
|
||||
with pytest.raises(RuntimeError, match="cannot change its execution role"):
|
||||
runtime.prepare("monitoring" if role == "driving" else "driving")
|
||||
|
||||
|
||||
def test_host_does_not_create_device_cache():
|
||||
|
||||
@@ -65,7 +65,8 @@ def test_big_default_disabled_and_explicit_download_preserved(tmp_path):
|
||||
|
||||
def test_verified_download_precedes_shipped_default(tmp_path, monkeypatch):
|
||||
path = tmp_path / "download.pkl"
|
||||
monkeypatch.setattr(manager, "catalog", lambda _: {DEFAULT_SMALL: {"artifact_sha256": "download-hash", "version": "v15"}})
|
||||
monkeypatch.setattr(manager, "catalog", lambda _: {DEFAULT_SMALL: {"artifact_sha256": "download-hash", "version": "v15",
|
||||
"_runtime_family": "native02e"}})
|
||||
monkeypatch.setattr(manager, "verified_artifact", lambda *args: path)
|
||||
fallback = tmp_path / "fallback.pkl"
|
||||
def verified_fallback(plan):
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"protected_inventory_sha256": "17d6284308eb3d8e76211225eb215c60181dc700e1a1c68d14f906906a86b45e", "schema_version": 1}
|
||||
{"protected_inventory_sha256": "fa4314474b7db3e6ffae318ed89afaaf1a14ae9044f3410e7c190ec09c2e7a36", "schema_version": 1}
|
||||
|
||||
Reference in New Issue
Block a user