Skip to content

Commit ea55421

Browse files
committed
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 <[email protected]>
1 parent f95f995 commit ea55421

File tree

5 files changed

+97
-0
lines changed

5 files changed

+97
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Check that static class properties can be accessed for read and write in
2+
// class tasks. Check the property is shared across all instances and has the
3+
// same value for all instances.
4+
5+
class C;
6+
static int i;
7+
task t;
8+
int x;
9+
x = i;
10+
i = x + 1;
11+
endtask
12+
endclass
13+
14+
module test;
15+
16+
C c1 = new;
17+
C c2 = new;
18+
C c3 = new;
19+
20+
initial begin
21+
c1.t();
22+
c2.t();
23+
if (c1.i == 2 && c2.i == 2 && c3.i == 2) begin
24+
$display("PASSED");
25+
end else begin
26+
$display("FAILED");
27+
end
28+
end
29+
30+
endmodule
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Check that static class properties can be accessed for read and write in
2+
// class tasks using `this`. Check the property is shared across all instances
3+
// and has the same value for all instances.
4+
5+
class C;
6+
static int i;
7+
task t;
8+
int x;
9+
x = this.i;
10+
this.i = x + 1;
11+
endtask
12+
endclass
13+
14+
module test;
15+
16+
C c1 = new;
17+
C c2 = new;
18+
C c3 = new;
19+
20+
initial begin
21+
c1.t();
22+
c2.t();
23+
if (c1.i == 2 && c2.i == 2 && c3.i == 2) begin
24+
$display("PASSED");
25+
end else begin
26+
$display("FAILED");
27+
end
28+
end
29+
30+
endmodule
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Check that static class properties can be accessed for read and write on a
2+
// class object. Check the property is shared across all instances and has the
3+
// same value for all instances.
4+
5+
class C;
6+
static int i;
7+
endclass
8+
9+
module test;
10+
11+
C c1 = new;
12+
C c2 = new;
13+
C c3 = new;
14+
15+
task t(C c);
16+
int x;
17+
x = c.i;
18+
c.i = x + 1;
19+
endtask
20+
21+
initial begin
22+
t(c1);
23+
t(c2);
24+
if (c1.i == 2 && c2.i == 2 && c3.i == 2) begin
25+
$display("PASSED");
26+
end else begin
27+
$display("FAILED");
28+
end
29+
end
30+
31+
endmodule

ivtest/regress-sv.list

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,9 @@ sv_class_extends_scoped normal,-g2009 ivltests
487487
sv_class_localparam normal,-g2009 ivltests
488488
sv_class_new_init normal,-g2009 ivltests
489489
sv_class_in_module_decl normal,-g2009 ivltests
490+
sv_class_static_prop1 normal,-g2009 ivltests
491+
sv_class_static_prop2 normal,-g2009 ivltests
492+
sv_class_static_prop3 normal,-g2009 ivltests
490493
sv_class_super1 normal,-g2009 ivltests
491494
sv_class_super2 normal,-g2009 ivltests
492495
sv_class_task1 normal,-g2009 ivltests

ivtest/regress-vlog95.list

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,9 @@ sv_class_extends_scoped CE,-g2009 ivltests
383383
sv_class_localparam CE,-g2009 ivltests
384384
sv_class_new_init CE,-g2009 ivltests
385385
sv_class_in_module_decl CE,-g2009 ivltests
386+
sv_class_static_prop1 CE,-g2009 ivltests
387+
sv_class_static_prop2 CE,-g2009 ivltests
388+
sv_class_static_prop3 CE,-g2009 ivltests
386389
sv_class_super1 CE,-g2009 ivltests
387390
sv_class_super2 CE,-g2009 ivltests
388391
sv_class_task1 CE,-g2009 ivltests

0 commit comments

Comments
 (0)