Skip to content

Commit

Permalink
Add regression tests for const variables
Browse files Browse the repository at this point in the history
Check that const variables are supported and they can not be overridden by
type of assignment.

Signed-off-by: Lars-Peter Clausen <[email protected]>
  • Loading branch information
larsclausen committed Jul 23, 2023
1 parent 3daa298 commit f092820
Show file tree
Hide file tree
Showing 27 changed files with 299 additions and 0 deletions.
18 changes: 18 additions & 0 deletions ivtest/ivltests/sv_const1.v
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions ivtest/ivltests/sv_const2.v
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions ivtest/ivltests/sv_const3.v
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions ivtest/ivltests/sv_const4.v
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions ivtest/ivltests/sv_const5.v
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions ivtest/ivltests/sv_const_fail1.v
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions ivtest/ivltests/sv_const_fail2.v
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions ivtest/ivltests/sv_const_fail3.v
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions ivtest/ivltests/sv_const_fail4.v
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions ivtest/ivltests/sv_const_fail5.v
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions ivtest/ivltests/sv_const_fail6.v
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions ivtest/ivltests/sv_const_fail7.v
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions ivtest/ivltests/sv_const_fail8.v
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions ivtest/regress-vvp.list
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions ivtest/vvp_tests/sv_const1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type" : "normal",
"source" : "sv_const1.v",
"iverilog-args" : [ "-g2005-sv" ]
}
5 changes: 5 additions & 0 deletions ivtest/vvp_tests/sv_const2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type" : "normal",
"source" : "sv_const2.v",
"iverilog-args" : [ "-g2005-sv" ]
}
5 changes: 5 additions & 0 deletions ivtest/vvp_tests/sv_const3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type" : "normal",
"source" : "sv_const3.v",
"iverilog-args" : [ "-g2005-sv" ]
}
5 changes: 5 additions & 0 deletions ivtest/vvp_tests/sv_const4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type" : "normal",
"source" : "sv_const4.v",
"iverilog-args" : [ "-g2005-sv" ]
}
5 changes: 5 additions & 0 deletions ivtest/vvp_tests/sv_const5.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type" : "normal",
"source" : "sv_const5.v",
"iverilog-args" : [ "-g2005-sv" ]
}
5 changes: 5 additions & 0 deletions ivtest/vvp_tests/sv_const_fail1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type" : "CE",
"source" : "sv_const_fail1.v",
"iverilog-args" : [ "-g2005-sv" ]
}
5 changes: 5 additions & 0 deletions ivtest/vvp_tests/sv_const_fail2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type" : "CE",
"source" : "sv_const_fail2.v",
"iverilog-args" : [ "-g2005-sv" ]
}
5 changes: 5 additions & 0 deletions ivtest/vvp_tests/sv_const_fail3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type" : "CE",
"source" : "sv_const_fail3.v",
"iverilog-args" : [ "-g2005-sv" ]
}
5 changes: 5 additions & 0 deletions ivtest/vvp_tests/sv_const_fail4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type" : "CE",
"source" : "sv_const_fail4.v",
"iverilog-args" : [ "-g2005-sv" ]
}
5 changes: 5 additions & 0 deletions ivtest/vvp_tests/sv_const_fail5.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type" : "CE",
"source" : "sv_const_fail5.v",
"iverilog-args" : [ "-g2005-sv" ]
}
5 changes: 5 additions & 0 deletions ivtest/vvp_tests/sv_const_fail6.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type" : "CE",
"source" : "sv_const_fail6.v",
"iverilog-args" : [ "-g2005-sv" ]
}
5 changes: 5 additions & 0 deletions ivtest/vvp_tests/sv_const_fail7.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type" : "CE",
"source" : "sv_const_fail7.v",
"iverilog-args" : [ "-g2005-sv" ]
}
5 changes: 5 additions & 0 deletions ivtest/vvp_tests/sv_const_fail8.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type" : "CE",
"source" : "sv_const_fail8.v",
"iverilog-args" : [ "-g2005-sv" ]
}

0 comments on commit f092820

Please sign in to comment.