Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[circt-test] Add simple runner interface for choosing modes and depth #7763

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions integration_test/circt-test/basic.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ verif.formal @ALUCanAdd {
verif.assert %eq : i1
}

verif.formal @ALUCanSub {
verif.formal @ALUCanSub attributes {mode = "cover,induction"} {
%a = verif.symbolic_value : i4
%b = verif.symbolic_value : i4
%true = hw.constant true
Expand All @@ -96,7 +96,7 @@ verif.formal @ALUCanSub {
verif.assert %eq : i1
}

verif.formal @ALUWorks {
verif.formal @ALUWorks attributes {mode = "cover,bmc", depth = 5} {
%a = verif.symbolic_value : i4
%b = verif.symbolic_value : i4
%sub = verif.symbolic_value : i1
Expand Down Expand Up @@ -132,7 +132,7 @@ verif.formal @ALUIgnoreFailure attributes {ignore = true} {
verif.assert %ne : i1
}

verif.formal @ALUFailure {
verif.formal @ALUFailure attributes {depth = 3} {
%a = verif.symbolic_value : i4
%b = verif.symbolic_value : i4
%sub = verif.symbolic_value : i1
Expand Down
36 changes: 23 additions & 13 deletions tools/circt-test/circt-test-runner-sby.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,39 @@
parser.add_argument("verilog")
parser.add_argument("-t", "--test")
parser.add_argument("-d", "--directory")
parser.add_argument("-m", "--mode")
parser.add_argument("-k", "--depth")
args = parser.parse_args()

directory = Path(args.directory)
source_path = Path(args.verilog)
script_path = directory / "script.sby"

if args.mode is not None:
tasks = args.mode.split(",")
else:
tasks = ["cover", "bmc", "induction"]

depth = f"depth {args.depth}" if args.depth is not None else ""

options = """
[options]
"""
for task in tasks:
mode = {"induction": "prove"}.get(task, task)
options += f"""
{task}:
mode {mode}
{depth}
--
"""

# Generate the SymbiYosys script.
script = f"""
[tasks]
cover
bmc
induction
{('\n ').join(tasks)}

[options]
cover:
mode cover
--
bmc:
mode bmc
--
induction:
mode prove
--
{options}

[engines]
smtbmc z3
Expand Down
22 changes: 22 additions & 0 deletions tools/circt-test/circt-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,28 @@ static LogicalResult execute(MLIRContext *context) {
args.push_back("-d");
args.push_back(testDir);

if (auto mode = test.attrs.get("mode")) {
args.push_back("-m");
auto modeStr = dyn_cast<StringAttr>(mode);
if (!modeStr) {
mlir::emitError(test.loc) << "invalid mode for test " << test.name;
return;
}
args.push_back(cast<StringAttr>(mode).getValue());
}

if (auto depth = test.attrs.get("depth")) {
args.push_back("-k");
auto depthInt = dyn_cast<IntegerAttr>(depth);
if (!depthInt) {
mlir::emitError(test.loc) << "invalid depth for test " << test.name;
return;
}
SmallVector<char> str;
depthInt.getValue().toStringUnsigned(str);
args.push_back(std::string(str.begin(), str.end()));
}

// Execute the test runner.
std::string errorMessage;
auto result =
Expand Down
Loading