Add regression test for accessing static class properties

Check that static class properties can be accessed for read and write and
that they are shared between all instances of a class type.

Check that this works for the following 3 cases

 * accessing the static property in a class function or task
 * accessing the static property in a class function or task using `this`
 * accessing the static property on a class object instance

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2022-03-30 10:21:43 +02:00
parent f95f9955c8
commit ea55421a07
5 changed files with 97 additions and 0 deletions

View File

@ -0,0 +1,30 @@
// Check that static class properties can be accessed for read and write in
// class tasks. Check the property is shared across all instances and has the
// same value for all instances.
class C;
static int i;
task t;
int x;
x = i;
i = x + 1;
endtask
endclass
module test;
C c1 = new;
C c2 = new;
C c3 = new;
initial begin
c1.t();
c2.t();
if (c1.i == 2 && c2.i == 2 && c3.i == 2) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule

View File

@ -0,0 +1,30 @@
// Check that static class properties can be accessed for read and write in
// class tasks using `this`. Check the property is shared across all instances
// and has the same value for all instances.
class C;
static int i;
task t;
int x;
x = this.i;
this.i = x + 1;
endtask
endclass
module test;
C c1 = new;
C c2 = new;
C c3 = new;
initial begin
c1.t();
c2.t();
if (c1.i == 2 && c2.i == 2 && c3.i == 2) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule

View File

@ -0,0 +1,31 @@
// Check that static class properties can be accessed for read and write on a
// class object. Check the property is shared across all instances and has the
// same value for all instances.
class C;
static int i;
endclass
module test;
C c1 = new;
C c2 = new;
C c3 = new;
task t(C c);
int x;
x = c.i;
c.i = x + 1;
endtask
initial begin
t(c1);
t(c2);
if (c1.i == 2 && c2.i == 2 && c3.i == 2) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule

View File

@ -487,6 +487,9 @@ sv_class_extends_scoped normal,-g2009 ivltests
sv_class_localparam normal,-g2009 ivltests
sv_class_new_init normal,-g2009 ivltests
sv_class_in_module_decl normal,-g2009 ivltests
sv_class_static_prop1 normal,-g2009 ivltests
sv_class_static_prop2 normal,-g2009 ivltests
sv_class_static_prop3 normal,-g2009 ivltests
sv_class_super1 normal,-g2009 ivltests
sv_class_super2 normal,-g2009 ivltests
sv_class_task1 normal,-g2009 ivltests

View File

@ -383,6 +383,9 @@ sv_class_extends_scoped CE,-g2009 ivltests
sv_class_localparam CE,-g2009 ivltests
sv_class_new_init CE,-g2009 ivltests
sv_class_in_module_decl CE,-g2009 ivltests
sv_class_static_prop1 CE,-g2009 ivltests
sv_class_static_prop2 CE,-g2009 ivltests
sv_class_static_prop3 CE,-g2009 ivltests
sv_class_super1 CE,-g2009 ivltests
sv_class_super2 CE,-g2009 ivltests
sv_class_task1 CE,-g2009 ivltests