From f092820599bb9983f14e909586fa65092b014870 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sun, 23 Jul 2023 14:38:08 -0700 Subject: [PATCH] Add regression tests for const variables Check that const variables are supported and they can not be overridden by type of assignment. Signed-off-by: Lars-Peter Clausen --- ivtest/ivltests/sv_const1.v | 18 +++++++++++++++++ ivtest/ivltests/sv_const2.v | 29 ++++++++++++++++++++++++++++ ivtest/ivltests/sv_const3.v | 17 ++++++++++++++++ ivtest/ivltests/sv_const4.v | 18 +++++++++++++++++ ivtest/ivltests/sv_const5.v | 20 +++++++++++++++++++ ivtest/ivltests/sv_const_fail1.v | 13 +++++++++++++ ivtest/ivltests/sv_const_fail2.v | 12 ++++++++++++ ivtest/ivltests/sv_const_fail3.v | 12 ++++++++++++ ivtest/ivltests/sv_const_fail4.v | 12 ++++++++++++ ivtest/ivltests/sv_const_fail5.v | 12 ++++++++++++ ivtest/ivltests/sv_const_fail6.v | 16 +++++++++++++++ ivtest/ivltests/sv_const_fail7.v | 21 ++++++++++++++++++++ ivtest/ivltests/sv_const_fail8.v | 21 ++++++++++++++++++++ ivtest/regress-vvp.list | 13 +++++++++++++ ivtest/vvp_tests/sv_const1.json | 5 +++++ ivtest/vvp_tests/sv_const2.json | 5 +++++ ivtest/vvp_tests/sv_const3.json | 5 +++++ ivtest/vvp_tests/sv_const4.json | 5 +++++ ivtest/vvp_tests/sv_const5.json | 5 +++++ ivtest/vvp_tests/sv_const_fail1.json | 5 +++++ ivtest/vvp_tests/sv_const_fail2.json | 5 +++++ ivtest/vvp_tests/sv_const_fail3.json | 5 +++++ ivtest/vvp_tests/sv_const_fail4.json | 5 +++++ ivtest/vvp_tests/sv_const_fail5.json | 5 +++++ ivtest/vvp_tests/sv_const_fail6.json | 5 +++++ ivtest/vvp_tests/sv_const_fail7.json | 5 +++++ ivtest/vvp_tests/sv_const_fail8.json | 5 +++++ 27 files changed, 299 insertions(+) create mode 100644 ivtest/ivltests/sv_const1.v create mode 100644 ivtest/ivltests/sv_const2.v create mode 100644 ivtest/ivltests/sv_const3.v create mode 100644 ivtest/ivltests/sv_const4.v create mode 100644 ivtest/ivltests/sv_const5.v create mode 100644 ivtest/ivltests/sv_const_fail1.v create mode 100644 ivtest/ivltests/sv_const_fail2.v create mode 100644 ivtest/ivltests/sv_const_fail3.v create mode 100644 ivtest/ivltests/sv_const_fail4.v create mode 100644 ivtest/ivltests/sv_const_fail5.v create mode 100644 ivtest/ivltests/sv_const_fail6.v create mode 100644 ivtest/ivltests/sv_const_fail7.v create mode 100644 ivtest/ivltests/sv_const_fail8.v create mode 100644 ivtest/vvp_tests/sv_const1.json create mode 100644 ivtest/vvp_tests/sv_const2.json create mode 100644 ivtest/vvp_tests/sv_const3.json create mode 100644 ivtest/vvp_tests/sv_const4.json create mode 100644 ivtest/vvp_tests/sv_const5.json create mode 100644 ivtest/vvp_tests/sv_const_fail1.json create mode 100644 ivtest/vvp_tests/sv_const_fail2.json create mode 100644 ivtest/vvp_tests/sv_const_fail3.json create mode 100644 ivtest/vvp_tests/sv_const_fail4.json create mode 100644 ivtest/vvp_tests/sv_const_fail5.json create mode 100644 ivtest/vvp_tests/sv_const_fail6.json create mode 100644 ivtest/vvp_tests/sv_const_fail7.json create mode 100644 ivtest/vvp_tests/sv_const_fail8.json diff --git a/ivtest/ivltests/sv_const1.v b/ivtest/ivltests/sv_const1.v new file mode 100644 index 0000000000..085e5672ac --- /dev/null +++ b/ivtest/ivltests/sv_const1.v @@ -0,0 +1,18 @@ +// Check that const variables in module scope are supported. + +module test; + + const integer x = 10; + + // The initializer expression is allowed to reference other const variables. + const integer y = 20 + x; + + initial begin + if (x === 10 && y === 30) begin + $display("PASSED"); + end else begin + $display("FAILED"); + end + end + +endmodule diff --git a/ivtest/ivltests/sv_const2.v b/ivtest/ivltests/sv_const2.v new file mode 100644 index 0000000000..ac668b9093 --- /dev/null +++ b/ivtest/ivltests/sv_const2.v @@ -0,0 +1,29 @@ +// Check that const variables are supported in function and task scope. + +module test; + + function automatic integer f(integer x); + // Automatic const variables can have a non-const initializer epxression + const integer y = 2 * x; + return y; + endfunction + + task automatic t(input integer x, output integer y); + // Automatic const variables can have a non-const initializer epxression + const integer z = 2 * x; + y = z; + endtask + + initial begin + integer y; + + t(15, y); + + if (f(10) === 20 && y === 30) begin + $display("PASSED"); + end else begin + $display("FAILED"); + end + end + +endmodule diff --git a/ivtest/ivltests/sv_const3.v b/ivtest/ivltests/sv_const3.v new file mode 100644 index 0000000000..1f0a6a82bc --- /dev/null +++ b/ivtest/ivltests/sv_const3.v @@ -0,0 +1,17 @@ +// Check that const variables in block scope are supported. + +module test; + + initial begin + const static integer x = 10; + // The initializer expression is allowed to reference other const variables. + const static integer y = 20 + x; + + if (x === 10 && y === 30) begin + $display("PASSED"); + end else begin + $display("FAILED"); + end + end + +endmodule diff --git a/ivtest/ivltests/sv_const4.v b/ivtest/ivltests/sv_const4.v new file mode 100644 index 0000000000..3d0af22917 --- /dev/null +++ b/ivtest/ivltests/sv_const4.v @@ -0,0 +1,18 @@ +// Check that const variables are supported in the unit scope. + +const integer x = 10; + +// The initializer expression is allowed to reference other const variables. +const integer y = 20 + x; + +module test; + + initial begin + if (x === 10 && y === 30) begin + $display("PASSED"); + end else begin + $display("FAILED"); + end + end + +endmodule diff --git a/ivtest/ivltests/sv_const5.v b/ivtest/ivltests/sv_const5.v new file mode 100644 index 0000000000..e08bdfbc12 --- /dev/null +++ b/ivtest/ivltests/sv_const5.v @@ -0,0 +1,20 @@ +// Check that const variables are supported in a package scope. + +package P; + const integer x = 10; + + // The initializer expression is allowed to reference other const variables. + const integer y = 20 + x; +endpackage + +module test; + + initial begin + if (P::x === 10 && P::y === 30) begin + $display("PASSED"); + end else begin + $display("FAILED"); + end + end + +endmodule diff --git a/ivtest/ivltests/sv_const_fail1.v b/ivtest/ivltests/sv_const_fail1.v new file mode 100644 index 0000000000..f654272729 --- /dev/null +++ b/ivtest/ivltests/sv_const_fail1.v @@ -0,0 +1,13 @@ +// Check that continuous assignment to a const variable fails. + +module test; + + const integer x = 10; + + assign x = 20; // Error: Assignment to const variable + + initial begin + $display("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/sv_const_fail2.v b/ivtest/ivltests/sv_const_fail2.v new file mode 100644 index 0000000000..2d0b2d6382 --- /dev/null +++ b/ivtest/ivltests/sv_const_fail2.v @@ -0,0 +1,12 @@ +// Check that blocking assignment to a const variable fails. + +module test; + + const integer x = 10; + + initial begin + x = 20; // Error: Assignment to const variable + $display("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/sv_const_fail3.v b/ivtest/ivltests/sv_const_fail3.v new file mode 100644 index 0000000000..41546994fa --- /dev/null +++ b/ivtest/ivltests/sv_const_fail3.v @@ -0,0 +1,12 @@ +// Check that non-blocking assignment to a const variable fails. + +module test; + + const integer x = 10; + + initial begin + x <= 20; // Error: Assignment to const variable + $display("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/sv_const_fail4.v b/ivtest/ivltests/sv_const_fail4.v new file mode 100644 index 0000000000..56b24a8744 --- /dev/null +++ b/ivtest/ivltests/sv_const_fail4.v @@ -0,0 +1,12 @@ +// Check that force assignment to a const variable fails. + +module test; + + const integer x = 10; + + initial begin + force x = 20; // Error: Assignment to const variable + $display("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/sv_const_fail5.v b/ivtest/ivltests/sv_const_fail5.v new file mode 100644 index 0000000000..58a856ea18 --- /dev/null +++ b/ivtest/ivltests/sv_const_fail5.v @@ -0,0 +1,12 @@ +// Check that procedural continuous assignment to a const variable fails. + +module test; + + const integer x = 10; + + initial begin + assign x = 20; // Error: Assignment to const variable + $display("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/sv_const_fail6.v b/ivtest/ivltests/sv_const_fail6.v new file mode 100644 index 0000000000..34dd551e23 --- /dev/null +++ b/ivtest/ivltests/sv_const_fail6.v @@ -0,0 +1,16 @@ +// Check that binding a const variable to a task output port fails. + +module test; + + const integer x = 10; + + task t(output integer x); + x = 20; + endtask + + initial begin + t(x); + $display("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/sv_const_fail7.v b/ivtest/ivltests/sv_const_fail7.v new file mode 100644 index 0000000000..8cad8fa795 --- /dev/null +++ b/ivtest/ivltests/sv_const_fail7.v @@ -0,0 +1,21 @@ +// Check that binding a const variable to a module output port fails. + +module M( + output integer x +); + assign x = 20; +endmodule + +module test; + + const integer x = 10; + + M i_m ( + .x (x) + ); + + initial begin + $display("FAILED"); + end + +endmodule diff --git a/ivtest/ivltests/sv_const_fail8.v b/ivtest/ivltests/sv_const_fail8.v new file mode 100644 index 0000000000..af9cfa3e65 --- /dev/null +++ b/ivtest/ivltests/sv_const_fail8.v @@ -0,0 +1,21 @@ +// Check that binding a const variable to a module inout port fails. + +module M( + inout integer x +); + assign x = 20; +endmodule + +module test; + + const integer x = 10; + + M i_m ( + .x (x) + ); + + initial begin + $display("FAILED"); + end + +endmodule diff --git a/ivtest/regress-vvp.list b/ivtest/regress-vvp.list index 05fd8b6d4c..11f9dc682c 100644 --- a/ivtest/regress-vvp.list +++ b/ivtest/regress-vvp.list @@ -60,6 +60,19 @@ sv_array_assign_fail1 vvp_tests/sv_array_assign_fail1.json sv_array_assign_fail2 vvp_tests/sv_array_assign_fail2.json sv_array_cassign6 vvp_tests/sv_array_cassign6.json sv_array_cassign7 vvp_tests/sv_array_cassign7.json +sv_const1 vvp_tests/sv_const1.json +sv_const2 vvp_tests/sv_const2.json +sv_const3 vvp_tests/sv_const3.json +sv_const4 vvp_tests/sv_const4.json +sv_const5 vvp_tests/sv_const5.json +sv_const_fail1 vvp_tests/sv_const_fail1.json +sv_const_fail2 vvp_tests/sv_const_fail2.json +sv_const_fail3 vvp_tests/sv_const_fail3.json +sv_const_fail4 vvp_tests/sv_const_fail4.json +sv_const_fail5 vvp_tests/sv_const_fail5.json +sv_const_fail6 vvp_tests/sv_const_fail6.json +sv_const_fail7 vvp_tests/sv_const_fail7.json +sv_const_fail8 vvp_tests/sv_const_fail8.json sv_foreach9 vvp_tests/sv_foreach9.json sv_foreach10 vvp_tests/sv_foreach10.json sv_module_port1 vvp_tests/sv_module_port1.json diff --git a/ivtest/vvp_tests/sv_const1.json b/ivtest/vvp_tests/sv_const1.json new file mode 100644 index 0000000000..80a6a307bb --- /dev/null +++ b/ivtest/vvp_tests/sv_const1.json @@ -0,0 +1,5 @@ +{ + "type" : "normal", + "source" : "sv_const1.v", + "iverilog-args" : [ "-g2005-sv" ] +} diff --git a/ivtest/vvp_tests/sv_const2.json b/ivtest/vvp_tests/sv_const2.json new file mode 100644 index 0000000000..39efe30738 --- /dev/null +++ b/ivtest/vvp_tests/sv_const2.json @@ -0,0 +1,5 @@ +{ + "type" : "normal", + "source" : "sv_const2.v", + "iverilog-args" : [ "-g2005-sv" ] +} diff --git a/ivtest/vvp_tests/sv_const3.json b/ivtest/vvp_tests/sv_const3.json new file mode 100644 index 0000000000..c151c363b9 --- /dev/null +++ b/ivtest/vvp_tests/sv_const3.json @@ -0,0 +1,5 @@ +{ + "type" : "normal", + "source" : "sv_const3.v", + "iverilog-args" : [ "-g2005-sv" ] +} diff --git a/ivtest/vvp_tests/sv_const4.json b/ivtest/vvp_tests/sv_const4.json new file mode 100644 index 0000000000..7cc53be8b7 --- /dev/null +++ b/ivtest/vvp_tests/sv_const4.json @@ -0,0 +1,5 @@ +{ + "type" : "normal", + "source" : "sv_const4.v", + "iverilog-args" : [ "-g2005-sv" ] +} diff --git a/ivtest/vvp_tests/sv_const5.json b/ivtest/vvp_tests/sv_const5.json new file mode 100644 index 0000000000..d3da84c817 --- /dev/null +++ b/ivtest/vvp_tests/sv_const5.json @@ -0,0 +1,5 @@ +{ + "type" : "normal", + "source" : "sv_const5.v", + "iverilog-args" : [ "-g2005-sv" ] +} diff --git a/ivtest/vvp_tests/sv_const_fail1.json b/ivtest/vvp_tests/sv_const_fail1.json new file mode 100644 index 0000000000..5fb0d364a3 --- /dev/null +++ b/ivtest/vvp_tests/sv_const_fail1.json @@ -0,0 +1,5 @@ +{ + "type" : "CE", + "source" : "sv_const_fail1.v", + "iverilog-args" : [ "-g2005-sv" ] +} diff --git a/ivtest/vvp_tests/sv_const_fail2.json b/ivtest/vvp_tests/sv_const_fail2.json new file mode 100644 index 0000000000..39c51cc427 --- /dev/null +++ b/ivtest/vvp_tests/sv_const_fail2.json @@ -0,0 +1,5 @@ +{ + "type" : "CE", + "source" : "sv_const_fail2.v", + "iverilog-args" : [ "-g2005-sv" ] +} diff --git a/ivtest/vvp_tests/sv_const_fail3.json b/ivtest/vvp_tests/sv_const_fail3.json new file mode 100644 index 0000000000..19353d4edd --- /dev/null +++ b/ivtest/vvp_tests/sv_const_fail3.json @@ -0,0 +1,5 @@ +{ + "type" : "CE", + "source" : "sv_const_fail3.v", + "iverilog-args" : [ "-g2005-sv" ] +} diff --git a/ivtest/vvp_tests/sv_const_fail4.json b/ivtest/vvp_tests/sv_const_fail4.json new file mode 100644 index 0000000000..50c209472c --- /dev/null +++ b/ivtest/vvp_tests/sv_const_fail4.json @@ -0,0 +1,5 @@ +{ + "type" : "CE", + "source" : "sv_const_fail4.v", + "iverilog-args" : [ "-g2005-sv" ] +} diff --git a/ivtest/vvp_tests/sv_const_fail5.json b/ivtest/vvp_tests/sv_const_fail5.json new file mode 100644 index 0000000000..1278627cdb --- /dev/null +++ b/ivtest/vvp_tests/sv_const_fail5.json @@ -0,0 +1,5 @@ +{ + "type" : "CE", + "source" : "sv_const_fail5.v", + "iverilog-args" : [ "-g2005-sv" ] +} diff --git a/ivtest/vvp_tests/sv_const_fail6.json b/ivtest/vvp_tests/sv_const_fail6.json new file mode 100644 index 0000000000..f8eaa2d355 --- /dev/null +++ b/ivtest/vvp_tests/sv_const_fail6.json @@ -0,0 +1,5 @@ +{ + "type" : "CE", + "source" : "sv_const_fail6.v", + "iverilog-args" : [ "-g2005-sv" ] +} diff --git a/ivtest/vvp_tests/sv_const_fail7.json b/ivtest/vvp_tests/sv_const_fail7.json new file mode 100644 index 0000000000..542ae9d9ac --- /dev/null +++ b/ivtest/vvp_tests/sv_const_fail7.json @@ -0,0 +1,5 @@ +{ + "type" : "CE", + "source" : "sv_const_fail7.v", + "iverilog-args" : [ "-g2005-sv" ] +} diff --git a/ivtest/vvp_tests/sv_const_fail8.json b/ivtest/vvp_tests/sv_const_fail8.json new file mode 100644 index 0000000000..3835ef9f9c --- /dev/null +++ b/ivtest/vvp_tests/sv_const_fail8.json @@ -0,0 +1,5 @@ +{ + "type" : "CE", + "source" : "sv_const_fail8.v", + "iverilog-args" : [ "-g2005-sv" ] +}