From 295b65da2cd2cedbe317406d01727140c4a80a6a Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sat, 17 Dec 2022 18:03:29 -0800 Subject: [PATCH] Add regression tests for using `super` to access the base class Check that it is possible to use the `super` keyword to access properties and methods of the base class that exist with the same name in current class. Also check that `this.super` is supported as an alternative to `super` and has the same behavior. Signed-off-by: Lars-Peter Clausen --- ivtest/ivltests/sv_class_super3.v | 39 +++++++++++++++++++++++++++++++ ivtest/ivltests/sv_class_super4.v | 26 +++++++++++++++++++++ ivtest/ivltests/sv_class_super5.v | 30 ++++++++++++++++++++++++ ivtest/ivltests/sv_class_super6.v | 39 +++++++++++++++++++++++++++++++ ivtest/regress-sv.list | 4 ++++ ivtest/regress-vlog95.list | 4 ++++ 6 files changed, 142 insertions(+) create mode 100644 ivtest/ivltests/sv_class_super3.v create mode 100644 ivtest/ivltests/sv_class_super4.v create mode 100644 ivtest/ivltests/sv_class_super5.v create mode 100644 ivtest/ivltests/sv_class_super6.v diff --git a/ivtest/ivltests/sv_class_super3.v b/ivtest/ivltests/sv_class_super3.v new file mode 100644 index 000000000..861721a85 --- /dev/null +++ b/ivtest/ivltests/sv_class_super3.v @@ -0,0 +1,39 @@ +// Check that `super` keyword can be used to access members of the base class + +class B; + int x, y; + + task set_y; + y = 2000; + endtask + + function bit check_x; + return x === 1000; + endfunction +endclass + +class C extends B; + byte x, y; + task set_x; + super.x = 1000; + endtask + + function bit check_y; + return super.y === 2000; + endfunction +endclass + +module test; + C c; + + initial begin + c = new; + c.set_x; + c.set_y; + if (c.check_x() && c.check_y()) begin + $display("PASSED"); + end else begin + $display("FAILED"); + end + end +endmodule diff --git a/ivtest/ivltests/sv_class_super4.v b/ivtest/ivltests/sv_class_super4.v new file mode 100644 index 000000000..f0e05a757 --- /dev/null +++ b/ivtest/ivltests/sv_class_super4.v @@ -0,0 +1,26 @@ +// Check that `super` keyword can be used to call tasks of the base class + +class B; + task t; + $display("PASSED"); + endtask +endclass + +class C extends B; + task t; + $display("FAILED"); + endtask + + task check; + super.t; + endtask +endclass + +module test; + C c; + + initial begin + c = new; + c.check; + end +endmodule diff --git a/ivtest/ivltests/sv_class_super5.v b/ivtest/ivltests/sv_class_super5.v new file mode 100644 index 000000000..d11b755c3 --- /dev/null +++ b/ivtest/ivltests/sv_class_super5.v @@ -0,0 +1,30 @@ +// Check that `super` keyword can be used to call functions of the base class + +class B; + function int f; + return 1; + endfunction +endclass + +class C extends B; + function int f; + return 2; + endfunction + + task check; + if (super.f() === 1) begin + $display("PASSED"); + end else begin + $display("FAILED"); + end + endtask +endclass + +module test; + C c; + + initial begin + c = new; + c.check; + end +endmodule diff --git a/ivtest/ivltests/sv_class_super6.v b/ivtest/ivltests/sv_class_super6.v new file mode 100644 index 000000000..cfc1a156f --- /dev/null +++ b/ivtest/ivltests/sv_class_super6.v @@ -0,0 +1,39 @@ +// Check that `this.super` is supported + +class B; + int x, y; + + task set_y; + y = 2000; + endtask + + function bit check_x; + return x === 1000; + endfunction +endclass + +class C extends B; + byte x, y; + task set_x; + this.super.x = 1000; + endtask + + function bit check_y; + return this.super.y === 2000; + endfunction +endclass + +module test; + C c; + + initial begin + c = new; + c.set_x; + c.set_y; + if (c.check_x() && c.check_y()) begin + $display("PASSED"); + end else begin + $display("FAILED"); + end + end +endmodule diff --git a/ivtest/regress-sv.list b/ivtest/regress-sv.list index 3af28d4ff..be291eb87 100644 --- a/ivtest/regress-sv.list +++ b/ivtest/regress-sv.list @@ -587,6 +587,10 @@ 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_super3 normal,-g2009 ivltests +sv_class_super4 normal,-g2009 ivltests +sv_class_super5 normal,-g2009 ivltests +sv_class_super6 normal,-g2009 ivltests sv_class_task1 normal,-g2009 ivltests sv_class_virt_new_fail CE,-g2009 ivltests sv_darray1 normal,-g2009 ivltests diff --git a/ivtest/regress-vlog95.list b/ivtest/regress-vlog95.list index d042f2b8c..abb56ce33 100644 --- a/ivtest/regress-vlog95.list +++ b/ivtest/regress-vlog95.list @@ -435,6 +435,10 @@ 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_super3 CE,-g2009 ivltests +sv_class_super4 CE,-g2009 ivltests +sv_class_super5 CE,-g2009 ivltests +sv_class_super6 CE,-g2009 ivltests sv_class_task1 CE,-g2009 ivltests sv_end_label CE,-g2009 ivltests # Also generate sv_foreach2 CE,-g2009,-pallowsigned=1 ivltests