|
|
@ -1,21 +1,38 @@ |
|
|
|
import os |
|
|
|
import os |
|
|
|
import capnp |
|
|
|
import capnp |
|
|
|
|
|
|
|
import pytest |
|
|
|
|
|
|
|
import shutil |
|
|
|
import hypothesis.strategies as st |
|
|
|
import hypothesis.strategies as st |
|
|
|
from hypothesis import given, settings, HealthCheck |
|
|
|
from hypothesis import given, settings, HealthCheck |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from cereal import CEREAL_PATH |
|
|
|
from openpilot.selfdrive.test.fuzzy_generation import FuzzyGenerator |
|
|
|
from openpilot.selfdrive.test.fuzzy_generation import FuzzyGenerator |
|
|
|
from openpilot.tools.lib.logreader import LogReader |
|
|
|
from openpilot.tools.lib.logreader import LogReader |
|
|
|
|
|
|
|
from openpilot.common.run import run_cmd |
|
|
|
|
|
|
|
|
|
|
|
MAX_EXAMPLES = int(os.environ.get("MAX_EXAMPLES", "10")) |
|
|
|
MAX_EXAMPLES = int(os.environ.get("MAX_EXAMPLES", "10")) |
|
|
|
|
|
|
|
TARGET_REMOTE = os.environ.get("TARGET_REMOTE", "origin") |
|
|
|
|
|
|
|
TARGET_BRANCH = os.environ.get("TARGET_BRANCH", "master") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module") |
|
|
|
|
|
|
|
def parent_schema_file(tmp_path_factory): |
|
|
|
|
|
|
|
commit = run_cmd(["git", "merge-base", f"{TARGET_REMOTE}/{TARGET_BRANCH}", "HEAD"]) |
|
|
|
|
|
|
|
log_capnp_url = f"https://raw.githubusercontent.com/commaai/openpilot/{commit}/cereal/log.capnp" |
|
|
|
|
|
|
|
tmp_dir = tmp_path_factory.mktemp("capnp") |
|
|
|
|
|
|
|
tmp_log_capnp_path = tmp_dir / f"{commit}-log.capnp" |
|
|
|
|
|
|
|
if not tmp_log_capnp_path.exists(): |
|
|
|
|
|
|
|
run_cmd(["curl", "-o", str(tmp_log_capnp_path), log_capnp_url]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return str(tmp_log_capnp_path) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@given(st.data()) |
|
|
|
@given(st.data()) |
|
|
|
@settings(max_examples=MAX_EXAMPLES, suppress_health_check=[HealthCheck.large_base_example]) |
|
|
|
@settings(max_examples=MAX_EXAMPLES, suppress_health_check=[HealthCheck.large_base_example]) |
|
|
|
def test_log_backwards_compatibility(schema_path, data): |
|
|
|
def test_log_backwards_compatibility(parent_schema_file, data): |
|
|
|
# capnp global parser needs to be cleaned up to avoid schema/struct ID conflicts |
|
|
|
# capnp global parser needs to be cleaned up to avoid schema/struct ID conflicts |
|
|
|
capnp.cleanup_global_schema_parser() |
|
|
|
capnp_parser = capnp.SchemaParser() |
|
|
|
old_log = capnp.load(schema_path) |
|
|
|
old_log = capnp_parser.load(parent_schema_file, imports=[CEREAL_PATH]) |
|
|
|
capnp.cleanup_global_schema_parser() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
msgs_dicts = FuzzyGenerator.get_random_event_msg(data.draw, log_schema=old_log, events=old_log.Event.schema.union_fields, real_floats=True) |
|
|
|
msgs_dicts = FuzzyGenerator.get_random_event_msg(data.draw, log_schema=old_log, events=old_log.Event.schema.union_fields, real_floats=True) |
|
|
|
msgs = [old_log.Event.new_message(**m).as_reader() for m in msgs_dicts] |
|
|
|
msgs = [old_log.Event.new_message(**m).as_reader() for m in msgs_dicts] |
|
|
|