Files
verilator/test_regress/t/t_display_pattern_format.v
T

60 lines
1.9 KiB
Systemverilog

// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain.
// SPDX-FileCopyrightText: 2026 Wilson Snyder
// SPDX-License-Identifier: CC0-1.0
// verilog_format: off
`define stop $stop
`define checks(gotv,expv) do if ((gotv) != (expv)) begin $write("%%Error: %s:%0d: got='%s' exp='%s'\n", `__FILE__,`__LINE__, (gotv), (expv)); `stop; end while(0);
// verilog_format: on
module t;
bit clk = 0;
always #5 clk = ~clk;
int cyc = 0;
typedef string text_t;
localparam text_t TEXT_PARAM = "quote=\" slash=\\ bell=\a form=\f vert=\v ctrl=\001";
localparam string ESCAPED_PARAM_STRING = $sformatf("%p", TEXT_PARAM);
initial begin
`ifdef QUESTA
// Questa 2025.2 does not escape strings as required by IEEE 1800-2012 21.2.1.7.
`checks(ESCAPED_PARAM_STRING, {"\"", TEXT_PARAM, "\""});
`else
`checks(ESCAPED_PARAM_STRING,
"\"quote=\\\" slash=\\\\ bell=\\007 form=\\014 vert=\\013 ctrl=\\001\"");
`endif
end
always @(posedge clk) begin
text_t plain;
string escaped;
string escaped_expected;
string fmt;
plain = $sformatf("round %0d", cyc);
escaped = {"quote=\" slash=\\ line=\n cr=\r tab=\t bell=\a form=\f vert=\v ctrl=\001 ", plain};
`ifdef QUESTA
escaped_expected = {"\"", escaped, "\""};
`else
escaped_expected = {"\"quote=\\\" slash=\\\\ line=\\n cr=\\r tab=\\t bell=\\007 ",
"form=\\014 vert=\\013 ctrl=\\001 ", plain, "\""};
`endif
`checks($sformatf("%p", plain), {"\"", plain, "\""});
`checks($sformatf("%p", escaped), escaped_expected);
`checks($sformatf("%s", escaped), escaped);
fmt = cyc[0] ? "%p" : "%P";
`checks($sformatf(fmt, escaped), escaped_expected);
plain = "";
`checks($sformatf("%p", plain), "\"\"");
cyc <= cyc + 1;
if (cyc == 3) begin
$write("*-* All Finished *-*\n");
$finish;
end
end
endmodule