Almost works

log-compat-test
Kacper Rączy 2 weeks ago
parent b7cbeecbd1
commit a2b3754607
  1. 22
      selfdrive/test/process_replay/test_log_compat.py

@ -1,16 +1,16 @@
import os
import capnp
import pytest
import shutil
import hypothesis.strategies as st
from hypothesis import given, settings, HealthCheck
from glob import glob
from cereal import CEREAL_PATH
from openpilot.selfdrive.test.fuzzy_generation import FuzzyGenerator
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", "2"))
TARGET_REMOTE = os.environ.get("TARGET_REMOTE", "origin")
TARGET_BRANCH = os.environ.get("TARGET_BRANCH", "master")
@ -18,21 +18,21 @@ TARGET_BRANCH = os.environ.get("TARGET_BRANCH", "master")
@pytest.fixture(scope="module")
def parent_schema_file(tmp_path_factory):
tmp_dir = tmp_path_factory.mktemp("cereal")
# FIXME this is an ugly way to do this, but for some reason capnp.load ignores the `imports``, and only looks at dir where the file is
# how it supposed to work is: capnp.load(my_custom_log_capnp, imports=[CEREAL_PATH])
shutil.copytree(CEREAL_PATH, tmp_dir, dirs_exist_ok=True)
# TODO this will fail if the any capnp files are added/removed vs what was on the parent commit
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_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])
for capnp_fp in glob(os.path.join(CEREAL_PATH, "**", "*.capnp"), recursive=True):
fname = os.path.relpath(capnp_fp, CEREAL_PATH)
capnp_url = f"https://raw.githubusercontent.com/commaai/openpilot/{commit}/cereal/{os.path.relpath(capnp_fp, CEREAL_PATH)}"
tmp_capnp_path = tmp_dir / fname
if not tmp_capnp_path.exists():
run_cmd(["curl", "-o", str(tmp_capnp_path), "--create-dirs", capnp_url])
return str(tmp_log_capnp_path)
return str(tmp_dir / "log.capnp")
@given(st.data())
@settings(max_examples=MAX_EXAMPLES, suppress_health_check=[HealthCheck.large_base_example])
@settings(max_examples=MAX_EXAMPLES, derandomize=True, suppress_health_check=[HealthCheck.large_base_example, HealthCheck.too_slow])
def test_log_backwards_compatibility(parent_schema_file, data):
# capnp global parser needs to be cleaned up to avoid schema/struct ID conflicts
capnp_parser = capnp.SchemaParser()

Loading…
Cancel
Save