From 78963493805bac95cc88388963e738ed6ad1d36d Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sat, 1 Oct 2022 17:40:02 +0200 Subject: [PATCH] Add regression tests for dynamic array/queue type compatibility Check for various dynamic array and queue types that their type compatibility is handled correctly. Signed-off-by: Lars-Peter Clausen --- ivtest/ivltests/sv_darray_assign1.v | 28 +++++++++++++++ ivtest/ivltests/sv_darray_assign2.v | 44 +++++++++++++++++++++++ ivtest/ivltests/sv_darray_assign_fail1.v | 15 ++++++++ ivtest/ivltests/sv_darray_assign_fail2.v | 15 ++++++++ ivtest/ivltests/sv_darray_assign_fail3.v | 14 ++++++++ ivtest/ivltests/sv_darray_assign_fail4.v | 17 +++++++++ ivtest/ivltests/sv_darray_assign_fail5.v | 14 ++++++++ ivtest/ivltests/sv_darray_assign_fail6.v | 14 ++++++++ ivtest/ivltests/sv_queue_assign1.v | 27 ++++++++++++++ ivtest/ivltests/sv_queue_assign2.v | 45 ++++++++++++++++++++++++ ivtest/ivltests/sv_queue_assign_fail1.v | 14 ++++++++ ivtest/ivltests/sv_queue_assign_fail2.v | 14 ++++++++ ivtest/ivltests/sv_queue_assign_fail3.v | 14 ++++++++ ivtest/ivltests/sv_queue_assign_fail4.v | 17 +++++++++ ivtest/ivltests/sv_queue_assign_fail5.v | 14 ++++++++ ivtest/ivltests/sv_queue_assign_fail6.v | 14 ++++++++ ivtest/regress-sv.list | 16 +++++++++ ivtest/regress-vlog95.list | 4 +++ 18 files changed, 340 insertions(+) create mode 100644 ivtest/ivltests/sv_darray_assign1.v create mode 100644 ivtest/ivltests/sv_darray_assign2.v create mode 100644 ivtest/ivltests/sv_darray_assign_fail1.v create mode 100644 ivtest/ivltests/sv_darray_assign_fail2.v create mode 100644 ivtest/ivltests/sv_darray_assign_fail3.v create mode 100644 ivtest/ivltests/sv_darray_assign_fail4.v create mode 100644 ivtest/ivltests/sv_darray_assign_fail5.v create mode 100644 ivtest/ivltests/sv_darray_assign_fail6.v create mode 100644 ivtest/ivltests/sv_queue_assign1.v create mode 100644 ivtest/ivltests/sv_queue_assign2.v create mode 100644 ivtest/ivltests/sv_queue_assign_fail1.v create mode 100644 ivtest/ivltests/sv_queue_assign_fail2.v create mode 100644 ivtest/ivltests/sv_queue_assign_fail3.v create mode 100644 ivtest/ivltests/sv_queue_assign_fail4.v create mode 100644 ivtest/ivltests/sv_queue_assign_fail5.v create mode 100644 ivtest/ivltests/sv_queue_assign_fail6.v diff --git a/ivtest/ivltests/sv_darray_assign1.v b/ivtest/ivltests/sv_darray_assign1.v new file mode 100644 index 000000000..b31e24214 --- /dev/null +++ b/ivtest/ivltests/sv_darray_assign1.v @@ -0,0 +1,28 @@ +// Check that dynamic arrays with compatible packed base types can be assigned +// to each other. Even if the element types are not identical. + +module test; + + typedef bit [31:0] T1; + typedef bit [31:0] T2[]; + + // For two packed types to be compatible they need to have the same packed + // width, both be 2-state or 4-state and both be either signed or unsigned. + bit [32:1] d1[]; + bit [7:0][3:0] d2[]; + int unsigned d3[]; + T1 d4[]; + T2 d5; + + initial begin + d1 = new[1]; + d2 = d1; + d3 = d2; + d4 = d3; + d5 = d4; + d1 = d5; + + $display("PASSED"); + end + +endmodule diff --git a/ivtest/ivltests/sv_darray_assign2.v b/ivtest/ivltests/sv_darray_assign2.v new file mode 100644 index 000000000..f3e7a78e4 --- /dev/null +++ b/ivtest/ivltests/sv_darray_assign2.v @@ -0,0 +1,44 @@ +// Check that dynamic arrays with compatible packed base types can be passed as +// task arguments. Even it the element types are not identical. + +module test; + + typedef logic [31:0] T[]; + + task t1(logic [31:0] d[]); + d[0] = 1; + endtask + + task t2(logic [7:0][3:0] d[]); + d[0] = 1; + endtask + + task t3([31:0] d[]); + d[0] = 1; + endtask + + task t4(T d); + d[0] = 1; + endtask + + // For two packed types to be compatible they need to have the same packed + // width, both be 2-state or 4-state and both be either signed or unsigned. + logic [31:0] d1[]; + logic [7:0][3:0] d2[]; + + initial begin + d1 = new[1]; + d2 = new[1]; + t1(d1); + t1(d2); + t2(d1); + t2(d2); + t3(d1); + t3(d2); + t4(d1); + t4(d2); + + $display("PASSED"); + end + +endmodule diff --git a/ivtest/ivltests/sv_darray_assign_fail1.v b/ivtest/ivltests/sv_darray_assign_fail1.v new file mode 100644 index 000000000..33699b1b1 --- /dev/null +++ b/ivtest/ivltests/sv_darray_assign_fail1.v @@ -0,0 +1,15 @@ +// Check that it is not possible to assign a dynamic array with a 2-state +// element type to a dynamic array with 4-state element type. Even if they are +// otherwise identical. + +module test; + + logic [31:0] d1[]; + bit [31:0] d2[]; + + initial begin + d1 = d2; + $dispaly("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/sv_darray_assign_fail2.v b/ivtest/ivltests/sv_darray_assign_fail2.v new file mode 100644 index 000000000..cda58dfb3 --- /dev/null +++ b/ivtest/ivltests/sv_darray_assign_fail2.v @@ -0,0 +1,15 @@ +// Check that it is not possible to assign a dynamic array with a signed element +// type to a dynamic array with a unsigned element type. Even if they are +// otherwise identical. + +module test; + + logic [31:0] d1[]; + logic signed [31:0] d2[]; + + initial begin + d1 = d2; + $dispaly("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/sv_darray_assign_fail3.v b/ivtest/ivltests/sv_darray_assign_fail3.v new file mode 100644 index 000000000..e5ac046cf --- /dev/null +++ b/ivtest/ivltests/sv_darray_assign_fail3.v @@ -0,0 +1,14 @@ +// Check that it is not possible to assign a dynamic array with different +// element type width. + +module test; + + int d1[]; + shortint d2[]; + + initial begin + d1 = d2; + $dispaly("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/sv_darray_assign_fail4.v b/ivtest/ivltests/sv_darray_assign_fail4.v new file mode 100644 index 000000000..85961bac2 --- /dev/null +++ b/ivtest/ivltests/sv_darray_assign_fail4.v @@ -0,0 +1,17 @@ +// Check that it is not possible to assign a dynamic array with an enum +// element type to a dynamic array with a packed type. Even if the enum base +// type is the same as the packed type. + +module test; + + enum logic [31:0] { + A + } d1[]; + logic [31:0] d2[]; + + initial begin + d1 = d2; + $dispaly("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/sv_darray_assign_fail5.v b/ivtest/ivltests/sv_darray_assign_fail5.v new file mode 100644 index 000000000..a1538d0b6 --- /dev/null +++ b/ivtest/ivltests/sv_darray_assign_fail5.v @@ -0,0 +1,14 @@ +// Check that it is not possible to assign a dynamic array with a real +// element type to a dynamic array with an int element type. + +module test; + + int d1[]; + real d2[]; + + initial begin + d1 = d2; + $display("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/sv_darray_assign_fail6.v b/ivtest/ivltests/sv_darray_assign_fail6.v new file mode 100644 index 000000000..8692e42da --- /dev/null +++ b/ivtest/ivltests/sv_darray_assign_fail6.v @@ -0,0 +1,14 @@ +// Check that it is not possible to assign a dynamic array with an int +// element type to a dynamic array with a real element type. + +module test; + + real d1[]; + int d2[]; + + initial begin + d1 = d2; + $display("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/sv_queue_assign1.v b/ivtest/ivltests/sv_queue_assign1.v new file mode 100644 index 000000000..fe0bb48df --- /dev/null +++ b/ivtest/ivltests/sv_queue_assign1.v @@ -0,0 +1,27 @@ +// Check that queues with compatible packed base types can be assigned to each +// other. Even if the element types are not identical. + +module test; + + typedef bit [31:0] T1; + typedef bit [31:0] T2[$]; + + // For two packed types to be compatible they need to have the same packed + // width, both be 2-state or 4-state and both be either signed or unsigned. + bit [32:1] q1[$]; + bit [7:0][3:0] q2[$]; + int unsigned q3[$]; + T1 q4[$]; + T2 q5; + + initial begin + q2 = q1; + q3 = q2; + q4 = q3; + q5 = q4; + q1 = q5; + + $display("PASSED"); + end + +endmodule diff --git a/ivtest/ivltests/sv_queue_assign2.v b/ivtest/ivltests/sv_queue_assign2.v new file mode 100644 index 000000000..472bc165e --- /dev/null +++ b/ivtest/ivltests/sv_queue_assign2.v @@ -0,0 +1,45 @@ +// Check that queues with compatible packed base types can be passed as task +// arguments. Even it the element types are not identical. + +module test; + + typedef logic [31:0] T[$]; + + task t1(logic [31:0] q[$]); + q[0] = 1; + endtask + + task t2(logic [7:0][3:0] q[$]); + q[0] = 1; + endtask + + task t3([31:0] q[$]); + q[0] = 1; + endtask + + task t4(T q); + q[0] = 1; + endtask + + // For two packed types to be compatible they need to have the same packed + // width, both be 2-state or 4-state and both be either signed or unsigned. + logic [31:0] q1[$]; + logic [7:0][3:0] q2[$]; + + initial begin + q1.push_back(1); + q2.push_back(2); + + t1(q1); + t1(q2); + t2(q1); + t2(q2); + t3(q1); + t3(q2); + t4(q1); + t4(q2); + + $display("PASSED"); + end + +endmodule diff --git a/ivtest/ivltests/sv_queue_assign_fail1.v b/ivtest/ivltests/sv_queue_assign_fail1.v new file mode 100644 index 000000000..d43f6afbe --- /dev/null +++ b/ivtest/ivltests/sv_queue_assign_fail1.v @@ -0,0 +1,14 @@ +// Check that it is not possible to assign a queue with a 2-state element type +// to a queue with 4-state element type. Even if they are otherwise identical. + +module test; + + logic [31:0] q1[$]; + bit [31:0] q2[$]; + + initial begin + q1 = q2; + $dispaly("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/sv_queue_assign_fail2.v b/ivtest/ivltests/sv_queue_assign_fail2.v new file mode 100644 index 000000000..cab584703 --- /dev/null +++ b/ivtest/ivltests/sv_queue_assign_fail2.v @@ -0,0 +1,14 @@ +// Check that it is not possible to assign a queue with a signed element type to +// a queue with a unsigned element type. Even if they are otherwise identical. + +module test; + + logic [31:0] q1[$]; + logic signed [31:0] q2[$]; + + initial begin + q1 = q2; + $dispaly("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/sv_queue_assign_fail3.v b/ivtest/ivltests/sv_queue_assign_fail3.v new file mode 100644 index 000000000..3d820f376 --- /dev/null +++ b/ivtest/ivltests/sv_queue_assign_fail3.v @@ -0,0 +1,14 @@ +// Check that it is not possible to assign a queue to another queue with a +// different element width. + +module test; + + int q1[$]; + shortint q2[$]; + + initial begin + q1 = q2; + $dispaly("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/sv_queue_assign_fail4.v b/ivtest/ivltests/sv_queue_assign_fail4.v new file mode 100644 index 000000000..5df7c9ed9 --- /dev/null +++ b/ivtest/ivltests/sv_queue_assign_fail4.v @@ -0,0 +1,17 @@ +// Check that it is not possible to assign a queue with an enum element type to +// a queue with a packed type. Even if the enum base type is the same as the +// packed type. + +module test; + + enum logic [31:0] { + A + } q1[$]; + logic [31:0] q2[$]; + + initial begin + q1 = q2; + $dispaly("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/sv_queue_assign_fail5.v b/ivtest/ivltests/sv_queue_assign_fail5.v new file mode 100644 index 000000000..7a5b1f425 --- /dev/null +++ b/ivtest/ivltests/sv_queue_assign_fail5.v @@ -0,0 +1,14 @@ +// Check that it is not possible to assign a queue with a real element type to a +// queue with an int element type. + +module test; + + int q1[$]; + real q2[$]; + + initial begin + q1 = q2; + $display("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/sv_queue_assign_fail6.v b/ivtest/ivltests/sv_queue_assign_fail6.v new file mode 100644 index 000000000..358533117 --- /dev/null +++ b/ivtest/ivltests/sv_queue_assign_fail6.v @@ -0,0 +1,14 @@ +// Check that it is not possible to assign a queue with an int element type to a +// queue with a real element type. + +module test; + + real q1[$]; + int q2[$]; + + initial begin + q1 = q2; + $display("FAILED"); + end + +endmodule diff --git a/ivtest/regress-sv.list b/ivtest/regress-sv.list index 9e133585b..a879003d8 100644 --- a/ivtest/regress-sv.list +++ b/ivtest/regress-sv.list @@ -553,6 +553,14 @@ sv_darray_args2 normal,-g2009 ivltests sv_darray_args2b normal,-g2009 ivltests sv_darray_args3 normal,-g2009 ivltests sv_darray_args4 normal,-g2009 ivltests +sv_darray_assign1 normal,-g2009 ivltests +sv_darray_assign2 normal,-g2009 ivltests +sv_darray_assign_fail1 CE,-g2009 ivltests +sv_darray_assign_fail2 CE,-g2009 ivltests +sv_darray_assign_fail3 CE,-g2009 ivltests +sv_darray_assign_fail4 CE,-g2009 ivltests +sv_darray_assign_fail5 CE,-g2009 ivltests +sv_darray_assign_fail6 CE,-g2009 ivltests sv_darray_copy_empty1 normal,-g2009 ivltests sv_darray_copy_empty2 normal,-g2009 ivltests sv_darray_copy_empty3 normal,-g2009 ivltests @@ -621,6 +629,14 @@ sv_ps_function3 normal,-g2009 ivltests sv_queue1 normal,-g2009 ivltests sv_queue2 normal,-g2009 ivltests sv_queue3 normal,-g2009 ivltests +sv_queue_assign1 normal,-g2009 ivltests +sv_queue_assign2 normal,-g2009 ivltests +sv_queue_assign_fail1 CE,-g2009 ivltests +sv_queue_assign_fail2 CE,-g2009 ivltests +sv_queue_assign_fail3 CE,-g2009 ivltests +sv_queue_assign_fail4 CE,-g2009 ivltests +sv_queue_assign_fail5 CE,-g2009 ivltests +sv_queue_assign_fail6 CE,-g2009 ivltests sv_queue_copy_empty1 normal,-g2009 ivltests sv_queue_copy_empty2 normal,-g2009 ivltests sv_queue_function1 normal,-g2009 ivltests diff --git a/ivtest/regress-vlog95.list b/ivtest/regress-vlog95.list index a42d24955..5601081fc 100644 --- a/ivtest/regress-vlog95.list +++ b/ivtest/regress-vlog95.list @@ -345,6 +345,8 @@ sv_darray_args2 CE,-g2009,-pallowsigned=1 ivltests sv_darray_args2b CE,-g2009,-pallowsigned=1 ivltests sv_darray_args3 CE,-g2009,-pallowsigned=1 ivltests sv_darray_args4 CE,-g2009,-pallowsigned=1 ivltests # Also string +sv_darray_assign1 CE,-g2009 ivltests +sv_darray_assign2 CE,-g2009 ivltests sv_darray_copy_empty1 CE,-g2009 ivltests sv_darray_copy_empty2 CE,-g2009 ivltests sv_darray_copy_empty3 CE,-g2009 ivltests @@ -486,6 +488,8 @@ pr3390385b CE,-g2009 ivltests # ++ pr3390385c CE,-g2009 ivltests # ++ pr3390385d CE,-g2009 ivltests # ++ pr3462145 CE,-g2009 ivltests # ++ +sv_queue_assign1 CE,-g2009 ivltests # queue +sv_queue_assign2 CE,-g2009 ivltests # queue sv_queue_copy_empty1 CE,-g2009 ivltests # queue sv_queue_copy_empty2 CE,-g2009 ivltests # queue sv_queue_function1 CE,-g2009,-pallowsigned=1 ivltests # queue