Add regression test for $bits() on array identifiers

Check that for array identifiers $bits() includes the total size of the
signal.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2023-06-25 09:04:34 -07:00
parent 7908e15093
commit 708f7bc651
3 changed files with 43 additions and 0 deletions

37
ivtest/ivltests/bits4.v Normal file
View File

@ -0,0 +1,37 @@
// Check that passing a array identifiers and array slices to $bits works as expected
module test;
bit failed = 1'b0;
`define check(expr, value) do begin \
if ($bits(expr) !== value) begin \
$display("FAILED(%d): $bits(", `"expr`", ") is %0d", `__LINE__, $bits(expr), " expected %0d", value); \
failed = 1'b1; \
end \
end while (0)
typedef bit T[3:0];
T x;
byte y[7:0][2:0];
initial begin
integer i;
i = 4;
`check(x, 4);
`check(y, $bits(byte) * 3 * 8);
`check(y[0], $bits(byte) * 3);
`check(y[1:0], $bits(byte) * 3 * 2);
`check(y[1+:3], $bits(byte) * 3 * 3);
`check(y[4-:4], $bits(byte) * 3 * 4);
`check(y[i-:2], $bits(byte) * 3 * 2);
`check(y[i+:2], $bits(byte) * 3 * 2);
if (!failed) begin
$display("PASSED");
end
end
endmodule

View File

@ -3,6 +3,7 @@
# describes the test.
array_packed_write_read vvp_tests/array_packed_write_read.json
bits4 vvp_tests/bits4.json
bitsel11 vvp_tests/bitsel11.json
br_gh13a vvp_tests/br_gh13a.json
br_gh13a-vlog95 vvp_tests/br_gh13a-vlog95.json

View File

@ -0,0 +1,5 @@
{
"type" : "normal",
"source" : "bits4.v",
"iverilog-args" : [ "-g2005-sv" ]
}