Jelajahi Sumber

fix-fw-test-failure-semantics-and-cache-isolation

root 3 bulan lalu
induk
melakukan
58b107777b
3 mengubah file dengan 58 tambahan dan 17 penghapusan
  1. 28 7
      tests/unit/test_fw_6400_v1_entrypoint.py
  2. 17 4
      tools/fw_cli.py
  3. 13 6
      tools/run_6400_v1.py

+ 28 - 7
tests/unit/test_fw_6400_v1_entrypoint.py

@@ -1,6 +1,5 @@
 from __future__ import annotations
 
-import inspect
 import sys
 from unittest import mock
 
@@ -8,15 +7,37 @@ from tools import fw_cli
 
 
 def test_fw_test_6400_uses_current_v1_runner() -> None:
-    expected_actions = ["unit"] if sys.platform == "win32" else ["all"]
+    expected_action = "unit" if sys.platform == "win32" else "all"
 
     with (
         mock.patch("tools.fw_cli._generate_one"),
-        mock.patch("tools.run_6400_v1.main", return_value=0) as current_runner,
+        mock.patch("tools.fw_cli._python", return_value="/test/python"),
+        mock.patch("tools.fw_cli.subprocess.call", return_value=0) as current_runner,
     ):
         assert fw_cli.main(["test", "6400"]) == 0
 
-    current_runner.assert_called_once_with(expected_actions)
-    dispatch_source = inspect.getsource(fw_cli._run_6400_verify)
-    assert "from tools.run_6400_v1 import" in dispatch_source
-    assert "from tools.run_6400_verify import" not in dispatch_source
+    argv = current_runner.call_args.args[0]
+    assert argv[:2] == ["/test/python", "-B"]
+    assert argv[-2].endswith("tools/run_6400_v1.py")
+    assert argv[-1] == expected_action
+    assert current_runner.call_args.kwargs["env"]["PYTHONDONTWRITEBYTECODE"] == "1"
+
+
+def test_fw_test_6400_returns_runner_failure_code() -> None:
+    with (
+        mock.patch("tools.fw_cli._generate_one"),
+        mock.patch("tools.fw_cli._python", return_value="/test/python"),
+        mock.patch("tools.fw_cli.subprocess.call", return_value=7),
+    ):
+        assert fw_cli.main(["test", "6400"]) == 7
+
+
+def test_fw_test_all_continues_after_6400_failure() -> None:
+    with (
+        mock.patch("tools.fw_cli._generate_one"),
+        mock.patch("tools.fw_cli._run_6400_verify", return_value=7),
+        mock.patch("tools.fw_cli._run_mrdimm_matrix", return_value=0) as mrdimm,
+    ):
+        assert fw_cli.main(["test", "all"]) == 7
+
+    mrdimm.assert_called_once_with("python,icarus,verilator,cocotb,formal")

+ 17 - 4
tools/fw_cli.py

@@ -138,10 +138,23 @@ def _run_mrdimm_matrix(lanes: str) -> int:
 
 
 def _run_6400_verify() -> int:
-    from tools.run_6400_v1 import main as verify_6400
-
-    actions = ["unit"] if sys.platform == "win32" else ["all"]
-    return verify_6400(actions)
+    action = "unit" if sys.platform == "win32" else "all"
+    env = os.environ.copy()
+    env.setdefault("PYTHONDONTWRITEBYTECODE", "1")
+    env.setdefault(
+        "PYTHONPYCACHEPREFIX",
+        str(_external_run_root("python-cache")),
+    )
+    return subprocess.call(
+        [
+            _python(),
+            "-B",
+            str(ROOT / "tools" / "run_6400_v1.py"),
+            action,
+        ],
+        cwd=str(ROOT),
+        env=env,
+    )
 
 
 def cmd_test(args: argparse.Namespace) -> int:

+ 13 - 6
tools/run_6400_v1.py

@@ -5,6 +5,7 @@ from __future__ import annotations
 
 import argparse
 import json
+import os
 from pathlib import Path
 import subprocess
 import sys
@@ -34,11 +35,17 @@ def sources() -> list[str]:
 
 def run(argv: list[str]) -> None:
     print("+ " + " ".join(argv), flush=True)
-    subprocess.run(argv, cwd=ROOT, check=True)
+    env = os.environ.copy()
+    env.setdefault("PYTHONDONTWRITEBYTECODE", "1")
+    env.setdefault(
+        "PYTHONPYCACHEPREFIX",
+        str(Path(tempfile.gettempdir()) / "prod2u-6400-v1-pycache"),
+    )
+    subprocess.run(argv, cwd=ROOT, check=True, env=env)
 
 
 def generate(check: bool = True) -> None:
-    argv = ["python3", "tools/generate_6400_v1.py"]
+    argv = [sys.executable, "-B", "tools/generate_6400_v1.py"]
     if check:
         argv.append("--check")
     run(argv)
@@ -87,7 +94,7 @@ def pwm_acceptance() -> None:
 
 def unit() -> None:
     run([
-        "pytest", "-q",
+        sys.executable, "-B", "-m", "pytest", "-p", "no:cacheprovider", "-q",
         "tests/unit/test_6400_v1_contract.py",
         "tests/unit/test_6400_v1_source_closure.py",
         "tests/unit/test_encode_6400_hex.py",
@@ -96,15 +103,15 @@ def unit() -> None:
 
 
 def cocotb_integration() -> None:
-    run(["python3", "tests/cocotb/run_6400_v1_integration.py"])
+    run([sys.executable, "-B", "tests/cocotb/run_6400_v1_integration.py"])
 
 
 def bmc_fuzz() -> None:
-    run(["python3", "tests/cocotb/run_6400_bmc_fuzz.py"])
+    run([sys.executable, "-B", "tests/cocotb/run_6400_bmc_fuzz.py"])
 
 
 def pi_differential() -> None:
-    run(["python3", "tests/cocotb/run_6400_pi_differential.py"])
+    run([sys.executable, "-B", "tests/cocotb/run_6400_pi_differential.py"])
 
 
 def main(argv: list[str] | None = None) -> int: