From b83daa3ae36891a372655652e53c9b4eefdfcafa Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sat, 14 May 2022 13:57:18 +0200 Subject: [PATCH] Add regression tests for dynamic array and queue out-of-bounds access Check that out-of-bounds access on a dynamic array or queue works and returns the correct value. * 2-state vectors: '0 with the element width * 4-state vectors: 'x with the element width * reals: 0.0 * strings: "" Note that the 2-state test currently still fails as out-of-bounds access on a 2-state vector incorrectly returns 'x. Signed-off-by: Lars-Peter Clausen --- ivtest/ivltests/sv_darray_oob_real.v | 18 ++++++++++++++++++ ivtest/ivltests/sv_darray_oob_string.v | 18 ++++++++++++++++++ ivtest/ivltests/sv_darray_oob_vec2.v | 18 ++++++++++++++++++ ivtest/ivltests/sv_darray_oob_vec4.v | 18 ++++++++++++++++++ ivtest/ivltests/sv_queue_oob_real.v | 18 ++++++++++++++++++ ivtest/ivltests/sv_queue_oob_string.v | 18 ++++++++++++++++++ ivtest/ivltests/sv_queue_oob_vec2.v | 18 ++++++++++++++++++ ivtest/ivltests/sv_queue_oob_vec4.v | 18 ++++++++++++++++++ ivtest/regress-fsv.list | 2 ++ ivtest/regress-sv.list | 6 ++++++ ivtest/regress-vlog95.list | 8 ++++++++ 11 files changed, 160 insertions(+) create mode 100644 ivtest/ivltests/sv_darray_oob_real.v create mode 100644 ivtest/ivltests/sv_darray_oob_string.v create mode 100644 ivtest/ivltests/sv_darray_oob_vec2.v create mode 100644 ivtest/ivltests/sv_darray_oob_vec4.v create mode 100644 ivtest/ivltests/sv_queue_oob_real.v create mode 100644 ivtest/ivltests/sv_queue_oob_string.v create mode 100644 ivtest/ivltests/sv_queue_oob_vec2.v create mode 100644 ivtest/ivltests/sv_queue_oob_vec4.v diff --git a/ivtest/ivltests/sv_darray_oob_real.v b/ivtest/ivltests/sv_darray_oob_real.v new file mode 100644 index 000000000..29fd5a821 --- /dev/null +++ b/ivtest/ivltests/sv_darray_oob_real.v @@ -0,0 +1,18 @@ +// Check that out-of-bounds access on a real typed dynamic array works and +// returns the correct value. + +module test; + + real d[]; + real x; + + initial begin + x = d[1]; + if (x == 0.0) begin + $display("PASSED"); + end else begin + $display("FAILED. Expected 0.0, got %f", x); + end + end + +endmodule diff --git a/ivtest/ivltests/sv_darray_oob_string.v b/ivtest/ivltests/sv_darray_oob_string.v new file mode 100644 index 000000000..2d8878662 --- /dev/null +++ b/ivtest/ivltests/sv_darray_oob_string.v @@ -0,0 +1,18 @@ +// Check that out-of-bounds access on a string typed dynamic array works and +// returns the right value. + +module test; + + string d[]; + string x; + + initial begin + x = d[1]; + if (x == "") begin + $display("PASSED"); + end else begin + $display("FAILED. Expected '', got '%s'", x); + end + end + +endmodule diff --git a/ivtest/ivltests/sv_darray_oob_vec2.v b/ivtest/ivltests/sv_darray_oob_vec2.v new file mode 100644 index 000000000..92468f335 --- /dev/null +++ b/ivtest/ivltests/sv_darray_oob_vec2.v @@ -0,0 +1,18 @@ +// Check that out-of-bounds access on a 2-state vector dynamic array works and +// returns the correct value. + +module test; + + bit [7:0] d[]; + logic [7:0] x; + + initial begin + x = d[1]; + if (x === 8'h00) begin + $display("PASSED"); + end else begin + $display("FAILED. Expected 00000000, got %b",x); + end + end + +endmodule diff --git a/ivtest/ivltests/sv_darray_oob_vec4.v b/ivtest/ivltests/sv_darray_oob_vec4.v new file mode 100644 index 000000000..fd77bd283 --- /dev/null +++ b/ivtest/ivltests/sv_darray_oob_vec4.v @@ -0,0 +1,18 @@ +// Check that out-of-bounds access on a 4-state vector dynamic array works and +// returns the correct value. + +module test; + + logic [7:0] d[]; + logic [7:0] x; + + initial begin + x = d[1]; + if (x === 8'hxx) begin + $display("PASSED"); + end else begin + $display("FAILED. Expected xxxxxxxx, got %b", x); + end + end + +endmodule diff --git a/ivtest/ivltests/sv_queue_oob_real.v b/ivtest/ivltests/sv_queue_oob_real.v new file mode 100644 index 000000000..f59256993 --- /dev/null +++ b/ivtest/ivltests/sv_queue_oob_real.v @@ -0,0 +1,18 @@ +// Check that out-of-bounds access on a real typed queue works and returns the +// correct value. + +module test; + + real q[$]; + real x; + + initial begin + x = q[1]; + if (x == 0.0) begin + $display("PASSED"); + end else begin + $display("FAILED. Expected 0.0, got %f", x); + end + end + +endmodule diff --git a/ivtest/ivltests/sv_queue_oob_string.v b/ivtest/ivltests/sv_queue_oob_string.v new file mode 100644 index 000000000..5126e4c8f --- /dev/null +++ b/ivtest/ivltests/sv_queue_oob_string.v @@ -0,0 +1,18 @@ +// Check that out-of-bounds access on a string typed queue works and returns the +// right value. + +module test; + + string q[$]; + string x; + + initial begin + x = q[1]; + if (x == "") begin + $display("PASSED"); + end else begin + $display("FAILED. Expected '', got '%s'", x); + end + end + +endmodule diff --git a/ivtest/ivltests/sv_queue_oob_vec2.v b/ivtest/ivltests/sv_queue_oob_vec2.v new file mode 100644 index 000000000..495d7e37b --- /dev/null +++ b/ivtest/ivltests/sv_queue_oob_vec2.v @@ -0,0 +1,18 @@ +// Check that out-of-bounds access on a 2-state vector queue works and returns +// the correct value. + +module test; + + bit [7:0] q[$]; + logic [7:0] x; + + initial begin + x = q[1]; + if (x === 8'h00) begin + $display("PASSED"); + end else begin + $display("FAILED. Expected 00000000, got %b",x); + end + end + +endmodule diff --git a/ivtest/ivltests/sv_queue_oob_vec4.v b/ivtest/ivltests/sv_queue_oob_vec4.v new file mode 100644 index 000000000..ca1a90afc --- /dev/null +++ b/ivtest/ivltests/sv_queue_oob_vec4.v @@ -0,0 +1,18 @@ +// Check that out-of-bounds access on a 4-state vector queue works and returns +// the correct value. + +module test; + + logic [7:0] q[$]; + logic [7:0] x; + + initial begin + x = q[1]; + if (x === 8'hxx) begin + $display("PASSED"); + end else begin + $display("FAILED. Expected xxxxxxxx, got %b", x); + end + end + +endmodule diff --git a/ivtest/regress-fsv.list b/ivtest/regress-fsv.list index 2bcbcd4aa..f8e0625a8 100644 --- a/ivtest/regress-fsv.list +++ b/ivtest/regress-fsv.list @@ -129,6 +129,7 @@ sv_darray_nest1 normal ivltests sv_darray_nest2 normal ivltests sv_darray_nest3 normal ivltests sv_darray_nest4 normal ivltests +sv_darray_oob_vec2 normal ivltests sv_deferred_assert1 normal ivltests sv_deferred_assert2 normal ivltests sv_deferred_assume1 normal ivltests @@ -137,3 +138,4 @@ sv_queue_nest1 normal ivltests sv_queue_nest2 normal ivltests sv_queue_nest3 normal ivltests sv_queue_nest4 normal ivltests +sv_queue_oob_vec2 normal ivltests diff --git a/ivtest/regress-sv.list b/ivtest/regress-sv.list index 2aa6adcbe..70ae36555 100644 --- a/ivtest/regress-sv.list +++ b/ivtest/regress-sv.list @@ -531,6 +531,9 @@ sv_darray_args3 normal,-g2009 ivltests sv_darray_args4 normal,-g2009 ivltests sv_darray_decl_assign normal,-g2009 ivltests sv_darray_function normal,-g2009 ivltests +sv_darray_oob_real normal,-g2009 ivltests +sv_darray_oob_string normal,-g2009 ivltests +sv_darray_oob_vec4 normal,-g2009 ivltests sv_darray_signed normal,-g2009 ivltests sv_darray_word_size normal,-g2005-sv ivltests sv_default_port_value1 normal,-g2009 ivltests @@ -589,6 +592,9 @@ sv_queue2 normal,-g2009 ivltests sv_queue3 normal,-g2009 ivltests sv_queue_function1 normal,-g2009 ivltests sv_queue_function2 normal,-g2009 ivltests +sv_queue_oob_real normal,-g2009 ivltests +sv_queue_oob_string normal,-g2009 ivltests +sv_queue_oob_vec4 normal,-g2009 ivltests sv_queue_parray normal,-g2009,-pfileline=1 ivltests gold=sv_queue_parray.gold sv_queue_parray_bounded normal,-g2009,-pfileline=1 ivltests gold=sv_queue_parray_bounded.gold sv_queue_parray_fail CE,-g2009 ivltests gold=sv_queue_parray_fail.gold diff --git a/ivtest/regress-vlog95.list b/ivtest/regress-vlog95.list index 48fc76b7c..cd6a919e5 100644 --- a/ivtest/regress-vlog95.list +++ b/ivtest/regress-vlog95.list @@ -342,6 +342,10 @@ sv_darray_args3 CE,-g2009,-pallowsigned=1 ivltests sv_darray_args4 CE,-g2009,-pallowsigned=1 ivltests # Also string sv_darray_decl_assign CE,-g2009,-pallowsigned=1 ivltests sv_darray_function CE,-g2009,-pallowsigned=1 ivltests +sv_darray_oob_real CE,-g2009 ivltests +sv_darray_oob_string CE,-g2009 ivltests # Also string +sv_darray_oob_vec2 CE,-g2009 ivltests # Also 2-state +sv_darray_oob_vec4 CE,-g2009 ivltests sv_darray_signed CE,-g2009,-pallowsigned=1 ivltests # Also string sv_darray_word_size CE,-g2009 ivltests sv_new_array_error CE,-g2009, ivltests @@ -475,6 +479,10 @@ pr3390385d CE,-g2009 ivltests # ++ pr3462145 CE,-g2009 ivltests # ++ sv_queue_function1 CE,-g2009,-pallowsigned=1 ivltests # queue sv_queue_function2 CE,-g2009,-pallowsigned=1 ivltests # queue +sv_queue_oob_real CE,-g2009 ivltests # queue +sv_queue_oob_string CE,-g2009 ivltests # queue, string +sv_queue_oob_vec2 CE,-g2009 ivltests # queue, 2-state +sv_queue_oob_vec4 CE,-g2009 ivltests # queue sv_typedef_darray_base1 CE,-g2009 ivltests # Dyanmic array sv_typedef_darray_base2 CE,-g2009 ivltests # Dyanmic array sv_typedef_darray_base3 CE,-g2009 ivltests # Dyanmic array