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 <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2023-07-23 14:38:08 -07:00
parent 3daa2982ac
commit f092820599
27 changed files with 299 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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