add bh_asserts.sv. Untested

This commit is contained in:
Brendan Haines 2022-11-19 18:41:50 -07:00
parent 449efd3c3c
commit 249cf34339

48
src/bh_assert.sv Normal file
View File

@ -0,0 +1,48 @@
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