|
|
@@ -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()
|