Skip to content

Commit

Permalink
Merge branch 'python-example' into 'main'
Browse files Browse the repository at this point in the history
Add example checkscript in python

See merge request repositories/verilator-infrastructure-bugpoint!30
  • Loading branch information
sgizler committed Oct 11, 2024
2 parents 22ff963 + df51464 commit 5808767
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ First, you need to prepare:
- a script that takes the path to a SystemVerilog file as the first argument and asserts that the same bug (or another property you wish to preserve) is still occurring.
It should exit with 0 if the assertion is successful.
For reference, see [`examples/caliptra_verilation_err/sv-bugpoint-check.sh`](examples/caliptra_verilation_err/sv-bugpoint-check.sh) and [`examples/caliptra_vcd/sv-bugpoint-check.sh`](examples/caliptra_vcd/sv-bugpoint-check.sh).
The script can be written in any language you are comfortable with, it just needs to be an executable. See the Python example: [`examples/caliptra_verilation_err/sv-bugpoint-check.py`](examples/caliptra_verilation_err/sv-bugpoint-check.py).
- SystemVerilog code that `sv-bugpoint` will attempt to minimize. In order to get one from a multi-file design,
you can use a preprocessor of your choice (e.g `verilator -E -P [other flags...] > sv-bugpoint-input.sv`).

Expand Down
47 changes: 47 additions & 0 deletions examples/caliptra_verilation_err/sv-bugpoint-check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env python3
"""
SPDX-License-Identifier: Apache-2.0
test script that asserts that verilation fails with same error message as in golden file
meant to debug case with caliptra-rtl@67fc658 and verilator@9a8e68928
"""

import subprocess
import sys
import shutil
import shlex
import os


def verilate_and_save_errmsg(verilator_argv):
"""run verilator, strip out volatile metadata from stderr and save it to file"""
subprocess.Popen(
["sv-bugpoint-strip-verilator-errmsg"],
stdin=subprocess.Popen(verilator_argv, stderr=subprocess.PIPE).stderr,
stdout=open("actual_stderr", "w", encoding="utf-8"),
).communicate()


def check():
"""check if actual equals golden, print diff if not"""
diff_proc = subprocess.run(
["diff", "golden_stderr", "actual_stderr", "--color"], check=False
)
return diff_proc.returncode == 0


CMD = """
verilator --cc --autoflush --timescale 1ns/1ps --timing --top-module caliptra_top_tb \
-Wno-WIDTH -Wno-UNOPTFLAT -Wno-LITENDIAN -Wno-CMPCONST -Wno-MULTIDRIVEN -Wno-UNPACKED -Wno-ALWCOMBORDER
"""

verilate_and_save_errmsg(shlex.split(CMD) + [sys.argv[1]])
print("\n\n\n", end="")
if check():
print("SUCCESS\n\n\n", end="")
sys.exit(0)
else:
if "GOLDEN" in os.environ:
shutil.copyfile("actual_stderr", "golden_stderr")
sys.exit(1)

0 comments on commit 5808767

Please sign in to comment.