Add regression tests for signed class properties
Check that the signedness of class properties is handled correctly * When sign extending * When passing as a value to a system function Check this for both when accessing the property from within a class method as well as accessing it on a class object. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
parent
0c123b8498
commit
031fbac5be
|
|
@ -0,0 +1,66 @@
|
|||
// Check that the signedness of class properties are handled correctly when
|
||||
// accessing the property on a class object.
|
||||
|
||||
module test;
|
||||
|
||||
bit failed = 1'b0;
|
||||
|
||||
`define check(x) \
|
||||
if (!(x)) begin \
|
||||
$display("FAILED(%0d): ", `__LINE__, `"x`"); \
|
||||
failed = 1'b1; \
|
||||
end
|
||||
|
||||
class C;
|
||||
shortint s = -1;
|
||||
bit [15:0] u = -1;
|
||||
endclass
|
||||
|
||||
C c;
|
||||
|
||||
int unsigned x = 10;
|
||||
int y = 10;
|
||||
int z;
|
||||
|
||||
initial begin
|
||||
c = new;
|
||||
|
||||
// These all evaluate as signed
|
||||
`check(c.s < 0)
|
||||
`check($signed(c.u) < 0)
|
||||
|
||||
// These all evaluate as unsigned
|
||||
`check(c.u > 0)
|
||||
`check({c.s} > 0)
|
||||
`check($unsigned(c.s) > 0)
|
||||
`check(c.s > 16'h0)
|
||||
|
||||
// In arithmetic expressions if one operand is unsigned all operands are
|
||||
// considered unsigned
|
||||
z = c.u + x;
|
||||
`check(z === 65545)
|
||||
z = c.u + y;
|
||||
`check(z === 65545)
|
||||
|
||||
z = c.s + x;
|
||||
`check(z === 65545)
|
||||
z = c.s + y;
|
||||
`check(z === 9)
|
||||
|
||||
// For ternary operators if one operand is unsigned the result is unsigend
|
||||
z = x ? c.u : x;
|
||||
`check(z === 65535)
|
||||
z = x ? c.u : y;
|
||||
`check(z === 65535)
|
||||
|
||||
z = x ? c.s : x;
|
||||
`check(z === 65535)
|
||||
z = x ? c.s : y;
|
||||
`check(z === -1)
|
||||
|
||||
if (!failed) begin
|
||||
$display("PASSED");
|
||||
end
|
||||
end
|
||||
|
||||
endmodule
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
// Check that the signedness of class properties are handled correctly when
|
||||
// accessing the property on a class object and passing it to a system function.
|
||||
|
||||
module test;
|
||||
|
||||
class C;
|
||||
shortint s = -1;
|
||||
bit [15:0] u = -1;
|
||||
endclass
|
||||
|
||||
C c;
|
||||
string s;
|
||||
|
||||
initial begin
|
||||
c = new;
|
||||
|
||||
s = $sformatf("%0d %0d", c.s, c.u);
|
||||
if (s == "-1 65535") begin
|
||||
$display("PASSED");
|
||||
end else begin
|
||||
$display("FAILED s=%s", s);
|
||||
end
|
||||
end
|
||||
|
||||
endmodule
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
// Check that the signedness of class properties are handled correctly when
|
||||
// accessing the property in a class method.
|
||||
|
||||
module test;
|
||||
|
||||
bit failed = 1'b0;
|
||||
|
||||
`define check(x) \
|
||||
if (!(x)) begin \
|
||||
$display("FAILED: ", `"x`", `__LINE__); \
|
||||
failed = 1'b1; \
|
||||
end
|
||||
|
||||
int unsigned x = 10;
|
||||
int y = 10;
|
||||
int z;
|
||||
|
||||
class C;
|
||||
shortint s = -1;
|
||||
bit [15:0] u = -1;
|
||||
|
||||
task test;
|
||||
|
||||
// These all evaluate as signed
|
||||
`check(s < 0)
|
||||
`check($signed(u) < 0)
|
||||
|
||||
// These all evaluate as unsigned
|
||||
`check(u > 0)
|
||||
`check({s} > 0)
|
||||
`check($unsigned(s) > 0)
|
||||
`check(s > 16'h0)
|
||||
|
||||
// In arithmetic expressions if one operand is unsigned all operands are
|
||||
// considered unsigned
|
||||
z = u + x;
|
||||
`check(z === 65545)
|
||||
z = u + y;
|
||||
`check(z === 65545)
|
||||
|
||||
z = s + x;
|
||||
`check(z === 65545)
|
||||
z = s + y;
|
||||
`check(z === 9)
|
||||
|
||||
// For ternary operators if one operand is unsigned the result is unsigend
|
||||
z = x ? u : x;
|
||||
`check(z === 65535)
|
||||
z = x ? u : y;
|
||||
`check(z === 65535)
|
||||
|
||||
z = x ? s : x;
|
||||
`check(z === 65535)
|
||||
z = x ? s : y;
|
||||
`check(z === -1)
|
||||
|
||||
if (!failed) begin
|
||||
$display("PASSED");
|
||||
end
|
||||
endtask
|
||||
|
||||
endclass
|
||||
|
||||
C c;
|
||||
|
||||
initial begin
|
||||
c = new;
|
||||
c.test();
|
||||
end
|
||||
|
||||
endmodule
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
// Check that the signedness of class properties are handled correctly when
|
||||
// accessing the property in a class method and passing it to a system function.
|
||||
|
||||
module test;
|
||||
|
||||
class C;
|
||||
shortint s = -1;
|
||||
bit [15:0] u = -1;
|
||||
|
||||
task test;
|
||||
string str;
|
||||
|
||||
str = $sformatf("%0d %0d", s, u);
|
||||
if (str == "-1 65535") begin
|
||||
$display("PASSED");
|
||||
end else begin
|
||||
$display("FAILED s=%s", s);
|
||||
end
|
||||
endtask
|
||||
|
||||
endclass
|
||||
|
||||
C c;
|
||||
|
||||
initial begin
|
||||
c = new;
|
||||
c.test();
|
||||
end
|
||||
|
||||
endmodule
|
||||
|
|
@ -494,6 +494,10 @@ sv_class_new_init normal,-g2009 ivltests
|
|||
sv_class_in_module_decl normal,-g2009 ivltests
|
||||
sv_class_method_signed1 normal,-g2009 ivltests
|
||||
sv_class_method_signed2 normal,-g2009 ivltests
|
||||
sv_class_property_signed1 normal,-g2009 ivltests
|
||||
sv_class_property_signed2 normal,-g2009 ivltests
|
||||
sv_class_property_signed3 normal,-g2009 ivltests
|
||||
sv_class_property_signed4 normal,-g2009 ivltests
|
||||
sv_class_static_prop1 normal,-g2009 ivltests
|
||||
sv_class_static_prop2 normal,-g2009 ivltests
|
||||
sv_class_static_prop3 normal,-g2009 ivltests
|
||||
|
|
|
|||
|
|
@ -386,6 +386,10 @@ sv_class_new_init CE,-g2009 ivltests
|
|||
sv_class_in_module_decl CE,-g2009 ivltests
|
||||
sv_class_method_signed1 CE,-g2009,-pallowsigned=1 ivltests
|
||||
sv_class_method_signed2 CE,-g2009,-pallowsigned=1 ivltests
|
||||
sv_class_property_signed1 CE,-g2009,-pallowsigned=1 ivltests
|
||||
sv_class_property_signed2 CE,-g2009,-pallowsigned=1 ivltests
|
||||
sv_class_property_signed3 CE,-g2009,-pallowsigned=1 ivltests
|
||||
sv_class_property_signed4 CE,-g2009,-pallowsigned=1 ivltests
|
||||
sv_class_static_prop1 CE,-g2009 ivltests
|
||||
sv_class_static_prop2 CE,-g2009 ivltests
|
||||
sv_class_static_prop3 CE,-g2009 ivltests
|
||||
|
|
|
|||
Loading…
Reference in New Issue