mirror of
https://gitlab.com/brendanhaines/cpu.git
synced 2024-12-26 11:06:50 -07:00
add bh_asserts.sv. Untested
This commit is contained in:
parent
449efd3c3c
commit
249cf34339
48
src/bh_assert.sv
Normal file
48
src/bh_assert.sv
Normal 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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user