Add regression test for package scoped method call
Check that it is possible to call a method on a package scoped identifier. Both for built-in types as well as class objects. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
parent
c1f2e0c21f
commit
535c09db62
|
|
@ -0,0 +1,39 @@
|
|||
// Check that it is possible to perform method call on a package scoped
|
||||
// identifier of an enum.
|
||||
|
||||
package P;
|
||||
enum integer {
|
||||
A, B
|
||||
} e = A;
|
||||
endpackage
|
||||
|
||||
module test;
|
||||
|
||||
bit failed = 1'b0;
|
||||
|
||||
`define check(expr, val) \
|
||||
if (val !== expr) begin \
|
||||
$display("FAILED(%0d). `%s` got %b, expected %b.", `__LINE__, `"expr`", expr, val); \
|
||||
failed = 1'b1; \
|
||||
end
|
||||
|
||||
initial begin
|
||||
// Calling without a parameter. Both variants are allowed
|
||||
`check(P::e.first, P::A)
|
||||
`check(P::e.first(), P::A)
|
||||
|
||||
// Is the width reported correctly for both variants?
|
||||
`check($bits(P::e.first), $bits(integer))
|
||||
`check($bits(P::e.first()), $bits(integer))
|
||||
|
||||
// Calling with a parameter
|
||||
`check(P::e.next(1), P::B)
|
||||
|
||||
`check($bits(P::e.next(1)), $bits(integer))
|
||||
|
||||
if (!failed) begin
|
||||
$display("PASSED");
|
||||
end
|
||||
end
|
||||
|
||||
endmodule
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
// Check that it is possible to perform method call on a package scoped
|
||||
// identifier of a class object.
|
||||
|
||||
package P;
|
||||
class C;
|
||||
function int f1(int x);
|
||||
return x + 1;
|
||||
endfunction
|
||||
|
||||
function int f2();
|
||||
return 10;
|
||||
endfunction
|
||||
endclass
|
||||
|
||||
C c = new;
|
||||
endpackage
|
||||
|
||||
module test;
|
||||
|
||||
bit failed = 1'b0;
|
||||
|
||||
`define check(expr, val) \
|
||||
if (val !== expr) begin \
|
||||
$display("FAILED(%0d). `%s` got %b, expected %b.", `__LINE__, `"expr`", expr, val); \
|
||||
failed = 1'b1; \
|
||||
end
|
||||
|
||||
initial begin
|
||||
`check(P::c.f1(10), 11)
|
||||
`check(P::c.f2(), 10)
|
||||
|
||||
`check($bits(P::c.f1(10)), $bits(int))
|
||||
`check($bits(P::c.f2()), $bits(int))
|
||||
|
||||
if (!failed) begin
|
||||
$display("PASSED");
|
||||
end
|
||||
end
|
||||
|
||||
endmodule
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
// Check that the parameter to a method on a package scoped identifier is
|
||||
// evaluated in the scope where the method is called, not where the identifier
|
||||
// is declared.
|
||||
|
||||
package P;
|
||||
localparam N = 1;
|
||||
enum {
|
||||
A, B, C
|
||||
} e = A;
|
||||
endpackage
|
||||
|
||||
module test;
|
||||
localparam N = 2;
|
||||
|
||||
initial begin
|
||||
if (P::e.next(N) === P::C) begin
|
||||
$display("PASSED");
|
||||
end else begin
|
||||
$display("FAILED");
|
||||
end
|
||||
end
|
||||
endmodule
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
// Check that the parameter to a class method on a package scoped identifier is
|
||||
// evaluated in the scope where the method is called, not where the identifier
|
||||
// is declared.
|
||||
|
||||
package P;
|
||||
localparam N = 1;
|
||||
|
||||
class C;
|
||||
function int f(int x);
|
||||
return x;
|
||||
endfunction
|
||||
endclass
|
||||
|
||||
C c = new;
|
||||
endpackage
|
||||
|
||||
module test;
|
||||
localparam N = 2;
|
||||
|
||||
initial begin
|
||||
if (P::c.f(N) === 2) begin
|
||||
$display("PASSED");
|
||||
end else begin
|
||||
$display("FAILED");
|
||||
end
|
||||
end
|
||||
endmodule
|
||||
|
|
@ -700,6 +700,10 @@ sv_ps_function_fail3 CE,-g2009 ivltests
|
|||
sv_ps_member_sel1 normal,-g2009 ivltests
|
||||
sv_ps_member_sel2 normal,-g2009 ivltests
|
||||
sv_ps_member_sel3 normal,-g2009 ivltests
|
||||
sv_ps_method1 normal,-g2009 ivltests
|
||||
sv_ps_method2 normal,-g2009 ivltests
|
||||
sv_ps_method3 normal,-g2009 ivltests
|
||||
sv_ps_method4 normal,-g2009 ivltests
|
||||
sv_ps_type1 normal,-g2009 ivltests
|
||||
sv_ps_type_cast1 normal,-g2009 ivltests
|
||||
sv_ps_type_cast2 normal,-g2009 ivltests
|
||||
|
|
|
|||
|
|
@ -463,6 +463,8 @@ sv_port_default7 CE,-g2009,-pallowsigned=1 ivltests
|
|||
sv_port_default8 CE,-g2009,-pallowsigned=1 ivltests
|
||||
sv_port_default9 CE,-g2009 ivltests
|
||||
sv_ps_member_sel3 CE,-g2009 ivltests
|
||||
sv_ps_method2 CE,-g2009 ivltests
|
||||
sv_ps_method4 CE,-g2009 ivltests
|
||||
sv_ps_type_class1 CE,-g2009 ivltests
|
||||
sv_ps_type_class_prop CE,-g2009 ivltests
|
||||
sv_root_class CE,-g2009 ivltests
|
||||
|
|
@ -521,6 +523,8 @@ pr3390385b CE,-g2009 ivltests # ++
|
|||
pr3390385c CE,-g2009 ivltests # ++
|
||||
pr3390385d CE,-g2009 ivltests # ++
|
||||
pr3462145 CE,-g2009 ivltests # ++
|
||||
sv_ps_method1 CE,-g2009 ivltests # enum
|
||||
sv_ps_method3 CE,-g2009 ivltests # enum
|
||||
sv_queue_assign1 CE,-g2009 ivltests # queue
|
||||
sv_queue_assign2 CE,-g2009 ivltests # queue
|
||||
sv_queue_copy_empty1 CE,-g2009 ivltests # queue
|
||||
|
|
|
|||
Loading…
Reference in New Issue