Add regression tests for assignment operators on class properties

Check that assignment operators are supported for class properties.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2025-01-03 12:42:43 -08:00
parent 43c138fdd3
commit 7c970e91b9
5 changed files with 128 additions and 0 deletions

View File

@ -0,0 +1,58 @@
// Check that assignment operators are supported on class properties.
module test;
bit failed = 1'b0;
`define check(val, exp) do \
if (val !== exp) begin \
$display("FAILED(%0d). '%s' expected %0d, got %0d", `__LINE__, `"val`", exp, val); \
failed = 1'b1; \
end \
while(0)
class C;
integer x;
endclass
integer i;
C c;
initial begin
c = new;
c.x = 1;
c.x += 5;
`check(c.x, 6);
c.x -= 2;
`check(c.x, 4);
c.x *= 25;
`check(c.x, 100);
c.x /= 5;
`check(c.x, 20);
c.x %= 3;
`check(c.x, 2);
c.x = 'haa;
c.x &= 'h33;
`check(c.x, 'h22);
c.x |= 'h11;
`check(c.x, 'h33);
c.x ^= 'h22;
`check(c.x, 'h11);
c.x <<= 3;
`check(c.x, 'h88);
c.x <<<= 1;
`check(c.x, 'h110);
c.x >>= 2;
`check(c.x, 'h44);
c.x >>>= 1;
`check(c.x, 'h22);
if (!failed) begin
$display("PASSED");
end
end
endmodule

View File

@ -0,0 +1,58 @@
// Check that assignment operators are supported on static class properties.
module test;
bit failed = 1'b0;
`define check(val, exp) do \
if (val !== exp) begin \
$display("FAILED(%0d). '%s' expected %0d, got %0d", `__LINE__, `"val`", exp, val); \
failed = 1'b1; \
end \
while(0)
class C;
static integer x;
endclass
integer i;
C c;
initial begin
c = new;
c.x = 1;
c.x += 5;
`check(c.x, 6);
c.x -= 2;
`check(c.x, 4);
c.x *= 25;
`check(c.x, 100);
c.x /= 5;
`check(c.x, 20);
c.x %= 3;
`check(c.x, 2);
c.x = 'haa;
c.x &= 'h33;
`check(c.x, 'h22);
c.x |= 'h11;
`check(c.x, 'h33);
c.x ^= 'h22;
`check(c.x, 'h11);
c.x <<= 3;
`check(c.x, 'h88);
c.x <<<= 1;
`check(c.x, 'h110);
c.x >>= 2;
`check(c.x, 'h44);
c.x >>>= 1;
`check(c.x, 'h22);
if (!failed) begin
$display("PASSED");
end
end
endmodule

View File

@ -222,6 +222,8 @@ sv_chained_constructor2 vvp_tests/sv_chained_constructor2.json
sv_chained_constructor3 vvp_tests/sv_chained_constructor3.json sv_chained_constructor3 vvp_tests/sv_chained_constructor3.json
sv_chained_constructor4 vvp_tests/sv_chained_constructor4.json sv_chained_constructor4 vvp_tests/sv_chained_constructor4.json
sv_chained_constructor5 vvp_tests/sv_chained_constructor5.json sv_chained_constructor5 vvp_tests/sv_chained_constructor5.json
sv_class_prop_assign_op1 vvp_tests/sv_class_prop_assign_op1.json
sv_class_prop_assign_op2 vvp_tests/sv_class_prop_assign_op2.json
sv_class_prop_logic vvp_tests/sv_class_prop_logic.json sv_class_prop_logic vvp_tests/sv_class_prop_logic.json
sv_const1 vvp_tests/sv_const1.json sv_const1 vvp_tests/sv_const1.json
sv_const2 vvp_tests/sv_const2.json sv_const2 vvp_tests/sv_const2.json

View File

@ -0,0 +1,5 @@
{
"type" : "normal",
"source" : "sv_class_prop_assign_op1.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "normal",
"source" : "sv_class_prop_assign_op2.v",
"iverilog-args" : [ "-g2005-sv" ]
}