Skip to content

Commit d95f240

Browse files
committed
Add regression tests for array assignment-pattern output
Check that nonempty dynamic arrays, queues and class properties print with an assignment-pattern apostrophe. Cover one and multiple elements, real and string arrays, uppercase format specifiers and the shared `%0p` format. Check the existing `{}` representation for allocated empty arrays and queues. Use `$sformatf()` so the tests need no VPI module. Mark the vlog95 variants as expected compile failures for unsupported dynamic arrays, queues and classes. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
1 parent 3265b27 commit d95f240

7 files changed

Lines changed: 157 additions & 0 deletions
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Check that nonempty dynamic arrays print with an assignment-pattern prefix.
2+
3+
module test;
4+
int values[];
5+
real real_values[];
6+
string string_values[];
7+
string text;
8+
bit failed = 1'b0;
9+
10+
`define check(fmt, val, exp) do begin \
11+
text = $sformatf(fmt, val); \
12+
if (text != exp) begin \
13+
$display("FAILED(%0d). '%s' expected %s, got %s", `__LINE__, \
14+
`"val`", exp, text); \
15+
failed = 1'b1; \
16+
end \
17+
end while (0)
18+
19+
initial begin
20+
values = new[0];
21+
`check("%p", values, "{}");
22+
`check("%0p", values, "{}");
23+
24+
values = new[1];
25+
values[0] = 1;
26+
`check("%p", values, "'{1}");
27+
`check("%P", values, "'{1}");
28+
`check("%0p", values, "'{1}");
29+
`check("%0P", values, "'{1}");
30+
31+
values = new[2];
32+
values[0] = 1;
33+
values[1] = 2;
34+
`check("%p", values, "'{1, 2}");
35+
36+
real_values = new[2];
37+
real_values[0] = 1.5;
38+
real_values[1] = 2.5;
39+
`check("%p", real_values, "'{1.5, 2.5}");
40+
41+
string_values = new[2];
42+
string_values[0] = "one";
43+
string_values[1] = "two";
44+
`check("%p", string_values, "'{\"one\", \"two\"}");
45+
46+
if (!failed) begin
47+
$display("PASSED");
48+
end
49+
end
50+
endmodule
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Check that array and queue properties print with an assignment-pattern prefix.
2+
3+
class C;
4+
int values[];
5+
int queue[$];
6+
endclass
7+
8+
module test;
9+
C object;
10+
int values[];
11+
string text;
12+
bit failed = 1'b0;
13+
14+
`define check(fmt, val, exp) do begin \
15+
text = $sformatf(fmt, val); \
16+
if (text != exp) begin \
17+
$display("FAILED(%0d). '%s' expected %s, got %s", `__LINE__, \
18+
`"val`", exp, text); \
19+
failed = 1'b1; \
20+
end \
21+
end while (0)
22+
23+
initial begin
24+
object = new;
25+
values = new[2];
26+
values[0] = 1;
27+
values[1] = 2;
28+
object.values = values;
29+
object.queue.push_back(1);
30+
object.queue.push_back(2);
31+
32+
`check("%p", object.values, "'{1, 2}");
33+
`check("%0p", object.values, "'{1, 2}");
34+
`check("%p", object.queue, "'{1, 2}");
35+
`check("%0p", object.queue, "'{1, 2}");
36+
37+
if (!failed) begin
38+
$display("PASSED");
39+
end
40+
end
41+
endmodule
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Check that nonempty queues print with an assignment-pattern prefix.
2+
3+
module test;
4+
int values[$];
5+
int value;
6+
string text;
7+
bit failed = 1'b0;
8+
9+
`define check(fmt, val, exp) do begin \
10+
text = $sformatf(fmt, val); \
11+
if (text != exp) begin \
12+
$display("FAILED(%0d). '%s' expected %s, got %s", `__LINE__, \
13+
`"val`", exp, text); \
14+
failed = 1'b1; \
15+
end \
16+
end while (0)
17+
18+
initial begin
19+
values.push_back(1);
20+
`check("%p", values, "'{1}");
21+
`check("%P", values, "'{1}");
22+
`check("%0p", values, "'{1}");
23+
`check("%0P", values, "'{1}");
24+
25+
values.push_back(2);
26+
`check("%p", values, "'{1, 2}");
27+
value = values.pop_back();
28+
value = values.pop_back();
29+
`check("%p", values, "{}");
30+
`check("%0p", values, "{}");
31+
32+
if (!failed) begin
33+
$display("PASSED");
34+
end
35+
end
36+
endmodule

‎ivtest/regress-vvp.list‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,15 +854,18 @@ vams_abs3 vvp_tests/vams_abs3.json
854854
vams_min_max_default_argument vvp_tests/vams_min_max_default_argument.json
855855
vardly_undefined_vec vvp_tests/vardly_undefined_vec.json
856856
va_math vvp_tests/va_math.json
857+
vpi_array_pattern_prefix vvp_tests/vpi_array_pattern_prefix.json
857858
vpi_array_word_int vvp_tests/vpi_array_word_int.json
858859
vpi_array_word_scalar vvp_tests/vpi_array_word_scalar.json
859860
vpi_array_word_select_signedness vvp_tests/vpi_array_word_select_signedness.json
860861
vpi_array_word_vector vvp_tests/vpi_array_word_vector.json
862+
vpi_class_array_pattern_prefix vvp_tests/vpi_class_array_pattern_prefix.json
861863
vpi_enum_constant_signedness vvp_tests/vpi_enum_constant_signedness.json
862864
vpi_escaped_scope_names vvp_tests/vpi_escaped_scope_names.json
863865
vpi_expression_real_signedness vvp_tests/vpi_expression_real_signedness.json
864866
vpi_net_array_word_select_signedness vvp_tests/vpi_net_array_word_select_signedness.json
865867
vpi_part_select_range vvp_tests/vpi_part_select_range.json
868+
vpi_queue_pattern_prefix vvp_tests/vpi_queue_pattern_prefix.json
866869
vpi_short_package_fullname vvp_tests/vpi_short_package_fullname.json
867870
vvp_quiet_mode vvp_tests/vvp_quiet_mode.json
868871
wait_condition_real vvp_tests/wait_condition_real.json
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"type" : "normal",
3+
"source" : "vpi_array_pattern_prefix.v",
4+
"iverilog-args" : [ "-g2005-sv" ],
5+
"vlog95" : {
6+
"__comment" : "Dynamic arrays are not supported",
7+
"type" : "CE"
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"type" : "normal",
3+
"source" : "vpi_class_array_pattern_prefix.v",
4+
"iverilog-args" : [ "-g2005-sv" ],
5+
"vlog95" : {
6+
"__comment" : "Classes and dynamic arrays are not supported",
7+
"type" : "CE"
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"type" : "normal",
3+
"source" : "vpi_queue_pattern_prefix.v",
4+
"iverilog-args" : [ "-g2005-sv" ],
5+
"vlog95" : {
6+
"__comment" : "Queues are not supported",
7+
"type" : "CE"
8+
}
9+
}

0 commit comments

Comments
 (0)