Add regression tests for chained constructors
Check that constructor chaining for various corner cases of mixing implicit and explicit constructors are handled correctly. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
parent
c512faa967
commit
8ca8ad3c81
|
|
@ -0,0 +1,40 @@
|
||||||
|
// Check that the constructor of a base class gets called exactly once when
|
||||||
|
// mixing implicit and explicit constructors.
|
||||||
|
|
||||||
|
module test;
|
||||||
|
|
||||||
|
bit failed = 1'b0;
|
||||||
|
|
||||||
|
`define check(val, exp) do begin \
|
||||||
|
if ((val) !== (exp)) begin \
|
||||||
|
$display("FAILED(%0d): `%s`, expected `%0d`, got `%0d`.", `__LINE__, \
|
||||||
|
`"val`", (exp), (val)); \
|
||||||
|
failed = 1'b1; \
|
||||||
|
end \
|
||||||
|
end while (0)
|
||||||
|
|
||||||
|
int c_new_calls = 0;
|
||||||
|
|
||||||
|
class C;
|
||||||
|
function new;
|
||||||
|
c_new_calls++;
|
||||||
|
endfunction
|
||||||
|
endclass
|
||||||
|
|
||||||
|
class D extends C;
|
||||||
|
int x = 10;
|
||||||
|
endclass
|
||||||
|
|
||||||
|
initial begin
|
||||||
|
D d;
|
||||||
|
d = new;
|
||||||
|
|
||||||
|
`check(c_new_calls, 1);
|
||||||
|
`check(d.x, 10);
|
||||||
|
|
||||||
|
if (!failed) begin
|
||||||
|
$display("PASSED");
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
endmodule
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
// Check that the constructor of a base class gets called exactly once when
|
||||||
|
// mixing implicit and explicit constructors.
|
||||||
|
|
||||||
|
module test;
|
||||||
|
|
||||||
|
bit failed = 1'b0;
|
||||||
|
|
||||||
|
`define check(val, exp) do begin \
|
||||||
|
if ((val) !== (exp)) begin \
|
||||||
|
$display("FAILED(%0d): `%s`, expected `%0d`, got `%0d`.", `__LINE__, \
|
||||||
|
`"val`", (exp), (val)); \
|
||||||
|
failed = 1'b1; \
|
||||||
|
end \
|
||||||
|
end while (0)
|
||||||
|
|
||||||
|
int d_new_calls = 0;
|
||||||
|
|
||||||
|
class C;
|
||||||
|
int x = 10;
|
||||||
|
endclass
|
||||||
|
|
||||||
|
class D extends C;
|
||||||
|
function new;
|
||||||
|
d_new_calls++;
|
||||||
|
endfunction
|
||||||
|
endclass
|
||||||
|
|
||||||
|
class E extends D;
|
||||||
|
int y;
|
||||||
|
function new;
|
||||||
|
y = 20;
|
||||||
|
endfunction
|
||||||
|
endclass
|
||||||
|
|
||||||
|
initial begin
|
||||||
|
E e;
|
||||||
|
e = new;
|
||||||
|
|
||||||
|
`check(d_new_calls, 1);
|
||||||
|
`check(e.x, 10);
|
||||||
|
`check(e.y, 20);
|
||||||
|
|
||||||
|
if (!failed) begin
|
||||||
|
$display("PASSED");
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
endmodule
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
// Check that forwarding base class constructor arguments through the `extends`
|
||||||
|
// works when the derived class has no constructor.
|
||||||
|
|
||||||
|
module test;
|
||||||
|
|
||||||
|
class C;
|
||||||
|
function new(int a);
|
||||||
|
if (a == 10) begin
|
||||||
|
$display("PASSED");
|
||||||
|
end else begin
|
||||||
|
$display("FAILED");
|
||||||
|
end
|
||||||
|
endfunction
|
||||||
|
endclass
|
||||||
|
|
||||||
|
// D has no constructor
|
||||||
|
class D extends C(10);
|
||||||
|
endclass
|
||||||
|
|
||||||
|
D d = new;
|
||||||
|
|
||||||
|
endmodule
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
// Check that forwarding base class constructor arguments through the `extends`
|
||||||
|
// works when the derived class has an implicit constructor.
|
||||||
|
|
||||||
|
module test;
|
||||||
|
|
||||||
|
class C;
|
||||||
|
function new(int a);
|
||||||
|
if (a == 10) begin
|
||||||
|
$display("PASSED");
|
||||||
|
end else begin
|
||||||
|
$display("FAILED");
|
||||||
|
end
|
||||||
|
endfunction
|
||||||
|
endclass
|
||||||
|
|
||||||
|
// D has an implicit constructor
|
||||||
|
class D extends C(10);
|
||||||
|
int y;
|
||||||
|
endclass
|
||||||
|
|
||||||
|
D d = new;
|
||||||
|
|
||||||
|
endmodule
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
// Check that forwarding base class constructor arguments through the `extends`
|
||||||
|
// works when the derived class has an explicit constructor.
|
||||||
|
|
||||||
|
module test;
|
||||||
|
|
||||||
|
class C;
|
||||||
|
function new(int a);
|
||||||
|
if (a == 10) begin
|
||||||
|
$display("PASSED");
|
||||||
|
end else begin
|
||||||
|
$display("FAILED");
|
||||||
|
end
|
||||||
|
endfunction
|
||||||
|
endclass
|
||||||
|
|
||||||
|
// D has an explicit constructor
|
||||||
|
class D extends C(10);
|
||||||
|
int x;
|
||||||
|
function new;
|
||||||
|
x = 10;
|
||||||
|
endfunction
|
||||||
|
endclass
|
||||||
|
|
||||||
|
D d = new;
|
||||||
|
|
||||||
|
endmodule
|
||||||
|
|
@ -61,6 +61,11 @@ sv_array_assign_fail2 vvp_tests/sv_array_assign_fail2.json
|
||||||
sv_array_cassign6 vvp_tests/sv_array_cassign6.json
|
sv_array_cassign6 vvp_tests/sv_array_cassign6.json
|
||||||
sv_array_cassign7 vvp_tests/sv_array_cassign7.json
|
sv_array_cassign7 vvp_tests/sv_array_cassign7.json
|
||||||
sv_automatic_2state vvp_tests/sv_automatic_2state.json
|
sv_automatic_2state vvp_tests/sv_automatic_2state.json
|
||||||
|
sv_chained_constructor1 vvp_tests/sv_chained_constructor1.json
|
||||||
|
sv_chained_constructor2 vvp_tests/sv_chained_constructor2.json
|
||||||
|
sv_chained_constructor3 vvp_tests/sv_chained_constructor3.json
|
||||||
|
sv_chained_constructor4 vvp_tests/sv_chained_constructor4.json
|
||||||
|
sv_chained_constructor5 vvp_tests/sv_chained_constructor5.json
|
||||||
sv_const1 vvp_tests/sv_const1.json
|
sv_const1 vvp_tests/sv_const1.json
|
||||||
sv_const2 vvp_tests/sv_const2.json
|
sv_const2 vvp_tests/sv_const2.json
|
||||||
sv_const3 vvp_tests/sv_const3.json
|
sv_const3 vvp_tests/sv_const3.json
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"type" : "normal",
|
||||||
|
"source" : "sv_chained_constructor1.v",
|
||||||
|
"iverilog-args" : [ "-g2005-sv" ]
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"type" : "normal",
|
||||||
|
"source" : "sv_chained_constructor2.v",
|
||||||
|
"iverilog-args" : [ "-g2005-sv" ]
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"type" : "normal",
|
||||||
|
"source" : "sv_chained_constructor3.v",
|
||||||
|
"iverilog-args" : [ "-g2005-sv" ]
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"type" : "normal",
|
||||||
|
"source" : "sv_chained_constructor4.v",
|
||||||
|
"iverilog-args" : [ "-g2005-sv" ]
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"type" : "normal",
|
||||||
|
"source" : "sv_chained_constructor5.v",
|
||||||
|
"iverilog-args" : [ "-g2005-sv" ]
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue