restructure testbenches and common code

This commit is contained in:
2022-12-01 00:45:57 -07:00
parent a2b0b2a709
commit ebc3b22ac7
7 changed files with 184 additions and 8 deletions

View File

@@ -1,48 +0,0 @@
int bh_assert_pass_count = 0;
int bh_assert_fail_count = 0;
logic bh_info_enable = 0;
function logic bh_assert_equal(int val, int expected, string description);
// display results
$timeformat(-9, 2, " ns", 20);
$display(
"%t: %s: %d %s %d - %s",
$time,
val == expected ? "PASS" : "FAIL",
val,
val == expected ? "==" : "!=",
expected,
description
);
// update statistics
if (val == expected) begin
bh_assert_pass_count = bh_assert_pass_count + 1;
end else begin
bh_assert_fail_count = bh_assert_fail_count + 1;
end
return val == expected;
endfunction
function void bh_assert_stats();
$timeformat(-9, 2, " ns", 20);
$display("%t: DONE: ");
if (bh_assert_pass_count + bh_assert_fail_count == 0) begin
$display("ERROR: no assertions found");
// TODO: error in a better way?
end else if (bh_assert_fail_count > 0) begin
$display("ERROR: some tests failed");
end else begin
$display("SUCCESS: all tests passed");
end
endfunction
function void bh_info(string description);
if (bh_info_enable) begin
$display(description);
end
endfunction