Add regression tests for null-byte handling when assigning to SV strings

Check that when assigning or casting a string literal or vector to a SV
string type that null-bytes are removed.

Also check that writing a null-byte to an element of a string variable is
ignored.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2023-01-02 10:09:34 -08:00
parent 4ddf234c32
commit 56baae11cc
4 changed files with 80 additions and 0 deletions

View File

@ -0,0 +1,43 @@
// Check that null-bytes are removed when converting to string type.
module test;
reg failed = 1'b0;
`define check(val, exp) \
if (val != exp) begin \
$display("FAILED(%0d): Expected '%0s', got '%0s'.", `__LINE__, exp, val); \
failed = 1'b1; \
end
string s;
reg [47:0] x;
initial begin
s = "\000a\000b\000";
`check(s, "ab");
s = string'("\000a\000b\000");
`check(s, "ab");
s = string'(48'h0061006200);
`check(s, "ab");
x = 48'h0061006200;
s = string'(x);
`check(s, "ab");
s = "cd";
s = {s, "\000a\000b\000"};
`check(s, "cdab");
s = "cd";
s = {"\000a\000b\000", s};
`check(s, "abcd");
if (!failed) begin
$display("PASSED");
end
end
endmodule

View File

@ -0,0 +1,33 @@
// Check that null-bytes are ignored when assigning to an element of a string
// type variable.
module test;
reg failed = 1'b0;
`define check(val, exp) \
if (val != exp) begin \
$display("FAILED(%0d): Expected '%0s', got '%0s'.", `__LINE__, exp, val); \
failed = 1'b1; \
end
string s;
byte x;
initial begin
s = "Test";
s[1] = 8'h00; // This should be ignored
`check(s, "Test");
s[1] = "\000"; // This should be ignored
`check(s, "Test");
x = 8'h00;
s[1] = x; // This should be ignored
`check(s, "Test");
if (!failed) begin
$display("PASSED");
end
end
endmodule

View File

@ -753,6 +753,8 @@ sv_string5 normal,-g2009 ivltests
sv_string6 normal,-g2009 ivltests
sv_string7 normal,-g2009 ivltests
sv_string7b normal,-g2009 ivltests
sv_string8 normal,-g2009 ivltests
sv_string9 normal,-g2009 ivltests
sv_timeunit_prec1 normal,-g2005-sv ivltests
sv_timeunit_prec2 normal,-g2009 ivltests
sv_timeunit_prec3a normal,-g2005-sv ivltests gold=sv_timeunit_prec3a.gold

View File

@ -309,6 +309,8 @@ sv_string5 CE,-g2009 ivltests
sv_string6 CE,-g2009,-pallowsigned=1 ivltests
sv_string7 CE,-g2009,-pallowsigned=1 ivltests
sv_string7b CE,-g2009,-pallowsigned=1 ivltests
sv_string8 CE,-g2009 ivltests
sv_string9 CE,-g2009 ivltests
sv_ps_function6 CE,-g2009,-pallowsigned=1 ivltests
sv_typedef_fwd_base CE,-g2009 ivltests
vhdl_string_lim CE,-g2005-sv,-pallowsigned=1,ivltests/vhdl_string_lim.vhd ivltests