test_negative_tool_fixtures.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. from __future__ import annotations
  2. import shutil
  3. import subprocess
  4. import tempfile
  5. import unittest
  6. from pathlib import Path
  7. from tools.prod2u_p4_harness import resolve_tool, tool_env
  8. ROOT = Path(__file__).resolve().parents[2]
  9. FIXTURES = ROOT / "tests" / "fixtures"
  10. class NegativeToolFixtureTests(unittest.TestCase):
  11. def _run_fixture(self, tool: str, args: list[str], *, cwd: Path) -> subprocess.CompletedProcess[str]:
  12. executable = resolve_tool(tool)
  13. if not executable:
  14. self.skipTest(f"{tool} is unavailable in the configured toolchain")
  15. return subprocess.run(
  16. [executable, *args],
  17. cwd=cwd,
  18. env=tool_env(),
  19. text=True,
  20. stdout=subprocess.PIPE,
  21. stderr=subprocess.PIPE,
  22. timeout=60,
  23. check=False,
  24. )
  25. def test_icarus_rejects_negative_fixture(self):
  26. with tempfile.TemporaryDirectory() as directory:
  27. output = Path(directory) / "bad.vvp"
  28. result = self._run_fixture(
  29. "iverilog",
  30. ["-g2012", "-o", str(output), str(FIXTURES / "bad_icarus_tb.v")],
  31. cwd=FIXTURES,
  32. )
  33. self.assertNotEqual(result.returncode, 0, result.stdout + result.stderr)
  34. def test_verilator_rejects_negative_fixture(self):
  35. result = self._run_fixture(
  36. "verilator",
  37. ["--lint-only", str(FIXTURES / "bad_verilator_lint.v")],
  38. cwd=FIXTURES,
  39. )
  40. self.assertNotEqual(result.returncode, 0, result.stdout + result.stderr)
  41. def test_formal_runner_rejects_negative_fixture(self):
  42. sby = resolve_tool("sby")
  43. if not sby:
  44. self.skipTest("sby is unavailable in the configured toolchain")
  45. with tempfile.TemporaryDirectory() as directory:
  46. root = Path(directory)
  47. shutil.copy2(FIXTURES / "bad_formal_fail.v", root / "bad_formal_fail.v")
  48. shutil.copy2(FIXTURES / "bad_formal_fail.sby", root / "bad_formal_fail.sby")
  49. result = subprocess.run(
  50. [sby, "-f", "bad_formal_fail.sby"],
  51. cwd=root,
  52. env=tool_env(),
  53. text=True,
  54. stdout=subprocess.PIPE,
  55. stderr=subprocess.PIPE,
  56. timeout=60,
  57. check=False,
  58. )
  59. self.assertNotEqual(result.returncode, 0, result.stdout + result.stderr)
  60. if __name__ == "__main__":
  61. unittest.main()