-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[circt-test] Add runner for circt-bmc
Add a runner script for `circt-bmc` to circt-test. This allows CIRCT's own model checker to be used to verify `verif.formal` operations in MLIR inputs. The user currently has to pass the runner to circt-test explicitly using the `-r` option. In the future, we'll want to add a mechanism to circt-test to list available runners, check if the needed software is installed on the system, and configure new local runners through some config file.
- Loading branch information
1 parent
2cc17e0
commit 95946b0
Showing
7 changed files
with
77 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// RUN: env Z3LIB=%libz3 circt-test %S/basic.mlir -r circt-test-runner-circt-bmc.py --mlir-runner | FileCheck %S/basic.mlir | ||
// XFAIL: * | ||
// REQUIRES: libz3 | ||
// REQUIRES: circt-bmc-jit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// RUN: circt-test %S/basic.mlir -r circt-test-runner-sby.py | FileCheck %S/basic.mlir | ||
// XFAIL: * | ||
// REQUIRES: sby |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env python3 | ||
from pathlib import Path | ||
import argparse | ||
import os | ||
import shlex | ||
import subprocess | ||
import sys | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument("mlir") | ||
parser.add_argument("-t", "--test", required=True) | ||
parser.add_argument("-d", "--directory", required=True) | ||
parser.add_argument("-m", "--mode") | ||
parser.add_argument("-k", "--depth", type=int) | ||
args = parser.parse_args() | ||
|
||
# Use circt-opt to lower any `verif.formal` ops to `hw.module`s. Once circt-bmc | ||
# natively supports `verif.formal`, we can directly run it on the input MLIR. | ||
lowered_mlir = Path(args.directory) / "lowered.mlir" | ||
cmd = ["circt-opt", args.mlir, "-o", lowered_mlir, "--lower-formal-to-hw"] | ||
sys.stderr.write("# " + shlex.join(str(c) for c in cmd) + "\n") | ||
sys.stderr.flush() | ||
result = subprocess.call(cmd) | ||
if result != 0: | ||
sys.exit(result) | ||
|
||
# Run circt-bmc. We currently have to capture the output and look for a specific | ||
# string to know if the verification passed or failed. Once the tool properly | ||
# exits on test failure, we can skip this. | ||
cmd = ["circt-bmc", lowered_mlir] | ||
cmd += ["-b", str(args.depth or 20)] | ||
cmd += ["--module", args.test] | ||
cmd += ["--shared-libs", os.environ.get("Z3LIB", "/usr/lib/libz3.so")] | ||
|
||
sys.stderr.write("# " + shlex.join(str(c) for c in cmd) + "\n") | ||
sys.stderr.flush() | ||
with open(Path(args.directory) / "output.log", "w") as output: | ||
result = subprocess.call(cmd, stdout=output, stderr=output) | ||
with open(Path(args.directory) / "output.log", "r") as output: | ||
output_str = output.read() | ||
sys.stderr.write(output_str) | ||
if result != 0: | ||
sys.exit(result) | ||
sys.exit(0 if "Bound reached with no violations" in output_str else 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters