Kaynağa Gözat

test: execute negative tool fixtures

Codex Resource Selftest 4 ay önce
ebeveyn
işleme
f171b67688

+ 72 - 0
tests/unit/test_negative_tool_fixtures.py

@@ -0,0 +1,72 @@
+from __future__ import annotations
+
+import shutil
+import subprocess
+import tempfile
+import unittest
+from pathlib import Path
+
+from tools.prod2u_p4_harness import resolve_tool, tool_env
+
+
+ROOT = Path(__file__).resolve().parents[2]
+FIXTURES = ROOT / "tests" / "fixtures"
+
+
+class NegativeToolFixtureTests(unittest.TestCase):
+    def _run_fixture(self, tool: str, args: list[str], *, cwd: Path) -> subprocess.CompletedProcess[str]:
+        executable = resolve_tool(tool)
+        if not executable:
+            self.skipTest(f"{tool} is unavailable in the configured toolchain")
+        return subprocess.run(
+            [executable, *args],
+            cwd=cwd,
+            env=tool_env(),
+            text=True,
+            stdout=subprocess.PIPE,
+            stderr=subprocess.PIPE,
+            timeout=60,
+            check=False,
+        )
+
+    def test_icarus_rejects_negative_fixture(self):
+        with tempfile.TemporaryDirectory() as directory:
+            output = Path(directory) / "bad.vvp"
+            result = self._run_fixture(
+                "iverilog",
+                ["-g2012", "-o", str(output), str(FIXTURES / "bad_icarus_tb.v")],
+                cwd=FIXTURES,
+            )
+        self.assertNotEqual(result.returncode, 0, result.stdout + result.stderr)
+
+    def test_verilator_rejects_negative_fixture(self):
+        result = self._run_fixture(
+            "verilator",
+            ["--lint-only", str(FIXTURES / "bad_verilator_lint.v")],
+            cwd=FIXTURES,
+        )
+        self.assertNotEqual(result.returncode, 0, result.stdout + result.stderr)
+
+    def test_formal_runner_rejects_negative_fixture(self):
+        sby = resolve_tool("sby")
+        if not sby:
+            self.skipTest("sby is unavailable in the configured toolchain")
+        with tempfile.TemporaryDirectory() as directory:
+            root = Path(directory)
+            shutil.copy2(FIXTURES / "bad_formal_fail.v", root / "bad_formal_fail.v")
+            shutil.copy2(FIXTURES / "bad_formal_fail.sby", root / "bad_formal_fail.sby")
+            result = subprocess.run(
+                [sby, "-f", "bad_formal_fail.sby"],
+                cwd=root,
+                env=tool_env(),
+                text=True,
+                stdout=subprocess.PIPE,
+                stderr=subprocess.PIPE,
+                timeout=60,
+                check=False,
+            )
+        self.assertNotEqual(result.returncode, 0, result.stdout + result.stderr)
+
+
+if __name__ == "__main__":
+    unittest.main()

+ 10 - 4
tests/unit/test_project_config.py

@@ -57,17 +57,23 @@ class ProjectConfigTests(unittest.TestCase):
         self.assertEqual(
             set(project["resource_policy"]),
             {
-                "target_ram_blocks",
-                "request_ram_blocks",
-                "temperature_ram_blocks",
+                "target_ram",
+                "request_ram",
+                "temperature_ram",
                 "dsp",
                 "shared_pwm_comparators",
                 "shared_motor_executors",
                 "shared_i2c_readers",
             },
         )
+        for key in ("target_ram", "request_ram", "temperature_ram"):
+            self.assertIn(project["resource_policy"][key], {"optional", "required", "forbidden"})
         self.assertTrue(
-            all(isinstance(value, int) and value >= 0 for value in project["resource_policy"].values())
+            all(
+                isinstance(project["resource_policy"][key], int)
+                and project["resource_policy"][key] >= 0
+                for key in ("dsp", "shared_pwm_comparators", "shared_motor_executors", "shared_i2c_readers")
+            )
         )
 
     def test_project_config_uses_only_new_protocol_types(self):