cpu/src/bh_assert.sv

49 lines
1.2 KiB
Systemverilog
Raw Normal View History

2022-11-19 18:41:50 -07:00
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