Add regression tests for unpacked array assignment patterns

Check that basic assignment patterns are supported for unpacked arrays.
Check that all of packed types, reals and string arrays are supported.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2023-06-04 16:02:31 -07:00
parent 9549156226
commit 90a1168086
17 changed files with 342 additions and 0 deletions

View File

@ -0,0 +1,44 @@
// Check that procedural assignment of unpacked array assignment patterns is
// supported and a entries are assigned in the right order.
module test;
bit failed;
`define check(val, exp) do \
if (val !== exp) begin \
$display("FAILED(%0d). '%s' expected %0d, got %0d", `__LINE__, `"val`", exp, val); \
failed = 1'b1; \
end \
while(0)
int x[3:0];
int y[0:3];
int z[4];
initial begin
x = '{1'b1, 1 + 1, 3.3, "TEST"};
y = '{1'b1, 1 + 1, 3.3, "TEST"};
z = '{1'b1, 1 + 1, 3.3, "TEST"};
`check(x[0], 1413829460);
`check(x[1], 3);
`check(x[2], 2);
`check(x[3], 1);
`check(y[0], 1);
`check(y[1], 2);
`check(y[2], 3);
`check(y[3], 1413829460);
`check(z[0], 1);
`check(z[1], 2);
`check(z[2], 3);
`check(z[3], 1413829460);
if (!failed) begin
$display("PASSED");
end
end
endmodule

View File

@ -0,0 +1,45 @@
// Check that procedural assignment of unpacked array assignment patterns to
// multi-dimensional arrays is supported and entries are assigned in the right
// order.
module test;
bit failed;
`define check(val, exp) do \
if (val !== exp) begin \
$display("FAILED(%0d). '%s' expected %0d, got %0d", `__LINE__, `"val`", exp, val); \
failed = 1'b1; \
end \
while(0)
int x[1:0][1:0];
int y[1:0][0:1];
int z[2][2];
initial begin
x = '{'{1'b1, 1 + 1}, '{3.3, "TEST"}};
y = '{'{1'b1, 1 + 1}, '{3.3, "TEST"}};
z = '{'{1'b1, 1 + 1}, '{3.3, "TEST"}};
`check(x[0][0], 1413829460);
`check(x[0][1], 3);
`check(x[1][0], 2);
`check(x[1][1], 1);
`check(y[0][0], 3);
`check(y[0][1], 1413829460);
`check(y[1][0], 1);
`check(y[1][1], 2);
`check(z[0][0], 1);
`check(z[0][1], 2);
`check(z[1][0], 3);
`check(z[1][1], 1413829460);
if (!failed) begin
$display("PASSED");
end
end
endmodule

View File

@ -0,0 +1,44 @@
// Check that continuous assignment of unpacked array assignment patterns is
// supported and entries are assigned in the right order.
module test;
bit failed;
`define check(val, exp) do \
if (val !== exp) begin \
$display("FAILED(%0d). '%s' expected %0d, got %0d", `__LINE__, `"val`", exp, val); \
failed = 1'b1; \
end \
while(0)
int x[3:0];
int y[0:3];
int z[4];
assign x = '{1'b1, 1 + 1, 3.3, "TEST"};
assign y = '{1'b1, 1 + 1, 3.3, "TEST"};
assign z = '{1'b1, 1 + 1, 3.3, "TEST"};
initial begin
`check(x[0], 1413829460);
`check(x[1], 3);
`check(x[2], 2);
`check(x[3], 1);
`check(y[0], 1);
`check(y[1], 2);
`check(y[2], 3);
`check(y[3], 1413829460);
`check(z[0], 1);
`check(z[1], 2);
`check(z[2], 3);
`check(z[3], 1413829460);
if (!failed) begin
$display("PASSED");
end
end
endmodule

View File

@ -0,0 +1,45 @@
// Check that continuous assignment of unpacked array assignment patterns to
// multi-dimensional arrays is supported and entries are assigned in the right
// order.
module test;
bit failed;
`define check(val, exp) do \
if (val !== exp) begin \
$display("FAILED(%0d). '%s' expected %0d, got %0d", `__LINE__, `"val`", exp, val); \
failed = 1'b1; \
end \
while(0)
int x[1:0][1:0];
int y[1:0][0:1];
int z[2][2];
assign x = '{'{1'b1, 1 + 1}, '{3.3, "TEST"}};
assign y = '{'{1'b1, 1 + 1}, '{3.3, "TEST"}};
assign z = '{'{1'b1, 1 + 1}, '{3.3, "TEST"}};
initial begin
`check(x[0][0], 1413829460);
`check(x[0][1], 3);
`check(x[1][0], 2);
`check(x[1][1], 1);
`check(y[0][0], 3);
`check(y[0][1], 1413829460);
`check(y[1][0], 1);
`check(y[1][1], 2);
`check(z[0][0], 1);
`check(z[0][1], 2);
`check(z[1][0], 3);
`check(z[1][1], 1413829460);
if (!failed) begin
$display("PASSED");
end
end
endmodule

View File

@ -0,0 +1,45 @@
// Check that procedural assignment of unpacked real array assignment patterns
// to multi-dimensional arrays is supported and entries are assigned in the
// right order.
module test;
bit failed;
`define check(val, exp) do \
if (val != exp) begin \
$display("FAILED(%0d). '%s' expected %0f, got %0f", `__LINE__, `"val`", exp, val); \
failed = 1'b1; \
end \
while(0)
real x[1:0][1:0];
real y[1:0][0:1];
real z[2][2];
initial begin
x = '{'{1'b1, 1 + 1}, '{3.3, "TEST"}};
y = '{'{1'b1, 1 + 1}, '{3.3, "TEST"}};
z = '{'{1'b1, 1 + 1}, '{3.3, "TEST"}};
`check(x[0][0], 1413829460.0);
`check(x[0][1], 3.3);
`check(x[1][0], 2.0);
`check(x[1][1], 1.0);
`check(y[0][1], 1413829460.0);
`check(y[0][0], 3.3);
`check(y[1][1], 2.0);
`check(y[1][0], 1.0);
`check(z[0][0], 1.0);
`check(z[0][1], 2.0);
`check(z[1][0], 3.3);
`check(z[1][1], 1413829460.0);
if (!failed) begin
$display("PASSED");
end
end
endmodule

View File

@ -0,0 +1,45 @@
// Check that procedural assignment of unpacked string array assignment patterns
// to multi-dimensional arrays is supported and entries are assigned in the
// right order.
module test;
bit failed;
`define check(val, exp) do \
if (val != exp) begin \
$display("FAILED(%0d). '%s' expected %s, got %s", `__LINE__, `"val`", exp, val); \
failed = 1'b1; \
end \
while(0)
string x[1:0][1:0];
string y[1:0][0:1];
string z[2][2];
initial begin
x = '{'{"Hello", "World"}, '{"Array", "Pattern"}};
y = '{'{"Hello", "World"}, '{"Array", "Pattern"}};
z = '{'{"Hello", "World"}, '{"Array", "Pattern"}};
`check(x[0][0], "Pattern");
`check(x[0][1], "Array");
`check(x[1][0], "World");
`check(x[1][1], "Hello");
`check(y[0][0], "Array");
`check(y[0][1], "Pattern");
`check(y[1][0], "Hello");
`check(y[1][1], "World");
`check(z[0][0], "Hello");
`check(z[0][1], "World");
`check(z[1][0], "Array");
`check(z[1][1], "Pattern");
if (!failed) begin
$display("PASSED");
end
end
endmodule

View File

@ -0,0 +1,13 @@
// Check that an unpacked array assignment pattern with too many elements
// results in an error.
module test;
int x[1:0];
initial begin
x = '{1, 2, 3}; // Should fail, more elements in assignment pattern than
// array size.
end
endmodule

View File

@ -0,0 +1,13 @@
// Check that an unpacked array assignment pattern with not enough elements
// results in an error.
module test;
int x[1:0];
initial begin
x = '{1}; // Should fail, less elements in assignment pattern than array
// size.
end
endmodule

View File

@ -45,6 +45,14 @@ pv_wr_fn_vec2 vvp_tests/pv_wr_fn_vec2.json
pv_wr_fn_vec4 vvp_tests/pv_wr_fn_vec4.json
struct_packed_write_read vvp_tests/struct_packed_write_read.json
struct_packed_write_read2 vvp_tests/struct_packed_write_read2.json
sv_ap_uarray1 vvp_tests/sv_ap_uarray1.json
sv_ap_uarray2 vvp_tests/sv_ap_uarray2.json
sv_ap_uarray3 vvp_tests/sv_ap_uarray3.json
sv_ap_uarray4 vvp_tests/sv_ap_uarray4.json
sv_ap_uarray5 vvp_tests/sv_ap_uarray5.json
sv_ap_uarray6 vvp_tests/sv_ap_uarray6.json
sv_ap_uarray_fail1 vvp_tests/sv_ap_uarray_fail1.json
sv_ap_uarray_fail2 vvp_tests/sv_ap_uarray_fail2.json
sv_array_cassign6 vvp_tests/sv_array_cassign6.json
sv_array_cassign7 vvp_tests/sv_array_cassign7.json
sv_foreach9 vvp_tests/sv_foreach9.json

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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