Tests: Reindent some tests. No functional change.

This commit is contained in:
Wilson Snyder 2025-11-12 19:40:59 -05:00
parent 59bc4cf66b
commit 03e5c3b2ff
16 changed files with 320 additions and 327 deletions

View File

@ -14,51 +14,51 @@
`define stop $stop
`define checkd(gotv,expv) do if ((gotv) !== (expv)) begin $write("%%Error: %s:%0d: got=%0d exp=%0d\n", `__FILE__,`__LINE__, (gotv), (expv)); `stop; end while(0);
module t ();
timeunit 10ns;
timeprecision 1ns;
module t;
timeunit 10ns;
timeprecision 1ns;
longint should_be_2, should_be_3;
real should_be_1p6, should_be_3p2;
longint should_be_2, should_be_3;
real should_be_1p6, should_be_3p2;
initial begin : initial_blk1
should_be_2 = 0;
should_be_3 = 0;
#(16ns);
$display("$time=%0t=%0d, $realtime=%g", $time(), $time(), $realtime());
should_be_2 = $time();
should_be_1p6 = $realtime();
#(16ns);
$display("$time=%0t=%0d, $realtime=%g", $time(), $time(), $realtime());
should_be_3 = $time();
should_be_3p2 = $realtime();
#(16ns);
$finish(1);
end
initial begin : initial_blk2
#(100ns);
$display("%%Error: We should not get here");
$stop;
initial begin : initial_blk1
should_be_2 = 0;
should_be_3 = 0;
#(16ns);
$display("$time=%0t=%0d, $realtime=%g", $time(), $time(), $realtime());
should_be_2 = $time();
should_be_1p6 = $realtime();
#(16ns);
$display("$time=%0t=%0d, $realtime=%g", $time(), $time(), $realtime());
should_be_3 = $time();
should_be_3p2 = $realtime();
#(16ns);
$finish(1);
end
function bit real_chk(input real tvar, input real evar);
real diff;
diff = tvar - evar;
return (diff < 1e-9) && (diff > -1e-9);
endfunction
initial begin : initial_blk2
#(100ns);
$display("%%Error: We should not get here");
$stop;
end
final begin : last_blk
$display("Info: should_be_2 = %0d", should_be_2);
$display("Info: should_be_3 = %0d", should_be_3);
`checkd(should_be_2, 2);
`checkd(should_be_3, 3);
function bit real_chk(input real tvar, input real evar);
real diff;
diff = tvar - evar;
return (diff < 1e-9) && (diff > -1e-9);
endfunction
chk_2 : assert(should_be_2 == 2);
chk_3 : assert(should_be_3 == 3);
chk_1p6 : assert(real_chk(should_be_1p6, 1.6));
chk_3p2 : assert(real_chk(should_be_3p2, 3.2));
$write("*-* All Finished *-*\n");
end
final begin : last_blk
$display("Info: should_be_2 = %0d", should_be_2);
$display("Info: should_be_3 = %0d", should_be_3);
`checkd(should_be_2, 2);
`checkd(should_be_3, 3);
chk_2 : assert(should_be_2 == 2);
chk_3 : assert(should_be_3 == 3);
chk_1p6 : assert(real_chk(should_be_1p6, 1.6));
chk_3p2 : assert(real_chk(should_be_3p2, 3.2));
$write("*-* All Finished *-*\n");
end
endmodule

View File

@ -10,24 +10,24 @@
`timescale 1ns/1ps
module t;
time t;
time t;
// realtime value scaled to timeunit, rounded to timeprecision
initial begin
// verilator lint_off REALCVT
t = 1s; `checkd(t, 64'd1000000000);
t = 2ms; `checkd(t, 2000000);
t = 1ms; `checkd(t, 1000000);
t = 1us; `checkd(t, 1000);
t = 1ns; `checkd(t, 1);
t = 1ps; `checkd(t, 0); // Below precision
t = 1fs; `checkd(t, 0);
// realtime value scaled to timeunit, rounded to timeprecision
initial begin
// verilator lint_off REALCVT
t = 1s; `checkd(t, 64'd1000000000);
t = 2ms; `checkd(t, 2000000);
t = 1ms; `checkd(t, 1000000);
t = 1us; `checkd(t, 1000);
t = 1ns; `checkd(t, 1);
t = 1ps; `checkd(t, 0); // Below precision
t = 1fs; `checkd(t, 0);
t = 2.3ps; `checkd(t, 0);
t = 2.4us; `checkd(t, 2400);
// verilator lint_on REALCVT
t = 2.3ps; `checkd(t, 0);
t = 2.4us; `checkd(t, 2400);
// verilator lint_on REALCVT
$write("*-* All Finished *-*\n");
$finish;
end
$write("*-* All Finished *-*\n");
$finish;
end
endmodule

View File

@ -4,36 +4,34 @@
// any use, without warranty, 2025 by Wilson Snyder.
// SPDX-License-Identifier: CC0-1.0
`timescale 1ns/1ps
`timescale 1ns / 1ps
module vip_snitch_cluster
#(parameter realtime ClkPeriod = 10ns)
(output logic clk_o);
module vip_snitch_cluster #(
parameter realtime ClkPeriod = 10ns
) (
output logic clk_o
);
initial begin
forever begin
clk_o = 1;
#(ClkPeriod/2);
clk_o = 0;
#(ClkPeriod/2);
end
end
initial begin
forever begin
clk_o = 1;
#(ClkPeriod / 2);
clk_o = 0;
#(ClkPeriod / 2);
end
end
initial begin
#(ClkPeriod*100);
$write("*-* All Finished *-*\n");
$finish;
end
initial begin
#(ClkPeriod * 100);
$write("*-* All Finished *-*\n");
$finish;
end
endmodule
module t;
logic clk;
logic clk;
vip_snitch_cluster #(
.ClkPeriod(1ns)
) vip (
.clk_o(clk)
);
vip_snitch_cluster #(.ClkPeriod(1ns)) vip (.clk_o(clk));
endmodule

View File

@ -4,61 +4,63 @@
// any use, without warranty, 2020 by Wilson Snyder.
// SPDX-License-Identifier: CC0-1.0
`timescale 1ns/1ps
module t (/*AUTOARG*/
// Inputs
clk
);
input clk;
`timescale 1ns / 1ps
module t ( /*AUTOARG*/
// Inputs
clk
);
input clk;
integer cyc = 0;
integer cyc = 0;
time in;
// verilator lint_off REALCVT
initial in = 5432109876.543210ns; // Will round to time units
// verilator lint_on REALCVT
time in;
// verilator lint_off REALCVT
initial in = 5432109876.543210ns; // Will round to time units
// verilator lint_on REALCVT
// This shows time changes when passed between modules with different units
// See also discussion in uvm_tlm2_time.svh
// This shows time changes when passed between modules with different units
// See also discussion in uvm_tlm2_time.svh
ps ps (.*);
ns ns (.*);
ps ps (.*);
ns ns (.*);
always @ (posedge clk) begin
cyc <= cyc + 1;
if (cyc == 60) begin
$write("*-* All Finished *-*\n");
$finish;
end
end
always @(posedge clk) begin
cyc <= cyc + 1;
if (cyc == 60) begin
$write("*-* All Finished *-*\n");
$finish;
end
end
endmodule
`timescale 1ps/1ps
`timescale 1ps / 1ps
module ps
(input clk,
input integer cyc,
input time in);
module ps (
input clk,
input integer cyc,
input time in
);
always @ (posedge clk) begin
if (cyc == 10) begin
$timeformat(-9, 6, "ns", 16);
$write("%m: Input time %t %d\n", in, in);
end
end
always @(posedge clk) begin
if (cyc == 10) begin
$timeformat(-9, 6, "ns", 16);
$write("%m: Input time %t %d\n", in, in);
end
end
endmodule
`timescale 1ns/1ps
`timescale 1ns / 1ps
module ns
(input clk,
input integer cyc,
input time in);
module ns (
input clk,
input integer cyc,
input time in
);
always @ (posedge clk) begin
if (cyc == 20) begin
$timeformat(-9, 6, "ns", 16);
$write("%m: Input time %t %d\n", in, in);
end
end
always @(posedge clk) begin
if (cyc == 20) begin
$timeformat(-9, 6, "ns", 16);
$write("%m: Input time %t %d\n", in, in);
end
end
endmodule

View File

@ -6,34 +6,33 @@
module t;
timeunit 1ns;
timeprecision 1ps;
timeunit 1ns; timeprecision 1ps;
time t;
time t;
initial begin
t = 10ns;
initial begin
t = 10ns;
$write("[%0t] In %m: Hi\n", $time);
$printtimescale;
$printtimescale();
$printtimescale(t);
$write("[%0t] In %m: Hi\n", $time);
$printtimescale;
$printtimescale();
$printtimescale(t);
$write("Time: '%t' 10ns=%0t\n", $time, t);
$timeformat(-3, 0, "-my-ms", 8);
$write("Time: '%t' 10ns=%0t\n", $time, t);
$timeformat(-3, 1, "-my-ms", 10);
$write("Time: '%t' 10ns=%0t\n", $time, t);
$timeformat(-6, 2, "-my-us", 12);
$write("Time: '%t' 10ns=%0t\n", $time, t);
$timeformat(-9, 3, "-my-ns", 13);
$write("Time: '%t' 10ns=%0t\n", $time, t);
$timeformat(-12, 3, "-my-ps", 13);
$write("Time: '%t' 10ns=%0t\n", $time, t);
$timeformat(-15, 4, "-my-fs", 14);
$write("Time: '%t' 10ns=%0t\n", $time, t);
$write("Time: '%t' 10ns=%0t\n", $time, t);
$timeformat(-3, 0, "-my-ms", 8);
$write("Time: '%t' 10ns=%0t\n", $time, t);
$timeformat(-3, 1, "-my-ms", 10);
$write("Time: '%t' 10ns=%0t\n", $time, t);
$timeformat(-6, 2, "-my-us", 12);
$write("Time: '%t' 10ns=%0t\n", $time, t);
$timeformat(-9, 3, "-my-ns", 13);
$write("Time: '%t' 10ns=%0t\n", $time, t);
$timeformat(-12, 3, "-my-ps", 13);
$write("Time: '%t' 10ns=%0t\n", $time, t);
$timeformat(-15, 4, "-my-fs", 14);
$write("Time: '%t' 10ns=%0t\n", $time, t);
$write("*-* All Finished *-*\n");
$finish;
end
$write("*-* All Finished *-*\n");
$finish;
end
endmodule

View File

@ -4,28 +4,26 @@
// any use, without warranty, 2020 by Wilson Snyder.
// SPDX-License-Identifier: CC0-1.0
module t (/*AUTOARG*/
// Inputs
clk
);
input clk;
module t (
input clk
);
integer cyc = 0;
integer cyc = 0;
time texpect = `TEST_EXPECT;
time texpect = `TEST_EXPECT;
always @ (posedge clk) begin
cyc <= cyc + 1;
if (cyc == 1) begin
$printtimescale;
$write("[%0t] In %m: Hi - expect this is %0t\n", $time, texpect);
if ($time != texpect) begin
$write("[%0t] delta = %d\n", $time, $time - texpect);
$stop;
end
$write("*-* All Finished *-*\n");
$finish;
always @(posedge clk) begin
cyc <= cyc + 1;
if (cyc == 1) begin
$printtimescale;
$write("[%0t] In %m: Hi - expect this is %0t\n", $time, texpect);
if ($time != texpect) begin
$write("[%0t] delta = %d\n", $time, $time - texpect);
$stop;
end
$write("*-* All Finished *-*\n");
$finish;
end
end
end
endmodule

View File

@ -4,22 +4,20 @@
// any use, without warranty, 2020 by Wilson Snyder.
// SPDX-License-Identifier: CC0-1.0
module t (/*AUTOARG*/
// Inputs
clk
);
input clk;
module t (
input clk
);
integer cyc = 0;
integer cyc = 0;
always @ (posedge clk) begin
cyc <= cyc + 1;
if (cyc == 1) begin
$write("[%0t] In %m: Hi\n", $time);
$printtimescale;
$write("*-* All Finished *-*\n");
$finish;
end
always @(posedge clk) begin
cyc <= cyc + 1;
if (cyc == 1) begin
$write("[%0t] In %m: Hi\n", $time);
$printtimescale;
$write("*-* All Finished *-*\n");
$finish;
end
end
end
endmodule

View File

@ -4,24 +4,25 @@
// any use, without warranty, 2022 by Wilson Snyder.
// SPDX-License-Identifier: CC0-1.0
// verilog_format: off
`define stop $stop
`define checkd(gotv,expv) do if ((gotv) !== (expv)) begin $write("%%Error: %s:%0d: got=%0d exp=%0d\n", `__FILE__,`__LINE__, (gotv), (expv)); `stop; end while(0);
// verilog_format: on
module t;
timeunit 1ns;
timeprecision 1ps;
timeunit 1ns; timeprecision 1ps;
initial begin
`checkd($timeunit, -9);
`checkd($timeunit(), -9);
`checkd($timeunit(t), -9);
initial begin
`checkd($timeunit, -9);
`checkd($timeunit(), -9);
`checkd($timeunit(t), -9);
`checkd($timeprecision, -12);
`checkd($timeprecision(), -12);
`checkd($timeprecision(t), -12);
`checkd($timeprecision, -12);
`checkd($timeprecision(), -12);
`checkd($timeprecision(t), -12);
$write("*-* All Finished *-*\n");
$finish;
end
$write("*-* All Finished *-*\n");
$finish;
end
endmodule

View File

@ -8,46 +8,44 @@
import "DPI-C" function void dpii_check();
module t (/*AUTOARG*/
// Inputs
clk
);
input clk;
module t (
input clk
);
integer cyc = 0;
// verilator lint_off REALCVT
time digits = 5432109876.543210ns; // Will round to time units
realtime rdigits = 5432109876.543210ns; // Will round to time precision
time high_acc = 64'd12345678901234567890; // Would lose accuracy if calculated in double
// verilator lint_on REALCVT
integer cyc = 0;
// verilator lint_off REALCVT
time digits = 5432109876.543210ns; // Will round to time units
realtime rdigits = 5432109876.543210ns; // Will round to time precision
time high_acc = 64'd12345678901234567890; // Would lose accuracy if calculated in double
// verilator lint_on REALCVT
always @ (posedge clk) begin
cyc <= cyc + 1;
always @ (posedge clk) begin
cyc <= cyc + 1;
`ifdef TEST_VERBOSE
$write("- [%0t] tick\n", $time);
$write("- [%0t] tick\n", $time);
`endif
if ($time >= 60) begin
$write(":: In %m\n");
$printtimescale;
$write("[%0t] time%%0d=%0d 123%%0t=%0t\n", $time, $time, 123);
$write(" dig%%0t=%0t dig%%0d=%0d\n", digits, digits);
$write(" rdig%%0t=%0t rdig%%0f=%0f\n", rdigits, rdigits);
$write(" acc%%0t=%0t acc%%0d=%0d\n", high_acc, high_acc);
$timeformat(-9, 6, "ns", 16);
$write("[%0t] time%%0d=%0d 123%%0t=%0t\n", $time, $time, 123);
$write(" dig%%0t=%0t dig%%0d=%0d\n", digits, digits);
$write(" rdig%%0t=%0t rdig%%0f=%0f\n", rdigits, rdigits);
$write(" acc%%0t=%0t acc%%0d=%0d\n", high_acc, high_acc);
$write("[%0t] stime%%0t=%0t stime%%0d=%0d stime%%0f=%0f\n",
$time, $stime, $stime, $stime);
// verilator lint_off REALCVT
$write("[%0t] rtime%%0t=%0t rtime%%0d=%0d rtime%%0f=%0f\n",
$time, $realtime, $realtime, $realtime);
// verilator lint_on REALCVT
dpii_check();
$write("*-* All Finished *-*\n");
$finish;
end
if ($time >= 60) begin
$write(":: In %m\n");
$printtimescale;
$write("[%0t] time%%0d=%0d 123%%0t=%0t\n", $time, $time, 123);
$write(" dig%%0t=%0t dig%%0d=%0d\n", digits, digits);
$write(" rdig%%0t=%0t rdig%%0f=%0f\n", rdigits, rdigits);
$write(" acc%%0t=%0t acc%%0d=%0d\n", high_acc, high_acc);
$timeformat(-9, 6, "ns", 16);
$write("[%0t] time%%0d=%0d 123%%0t=%0t\n", $time, $time, 123);
$write(" dig%%0t=%0t dig%%0d=%0d\n", digits, digits);
$write(" rdig%%0t=%0t rdig%%0f=%0f\n", rdigits, rdigits);
$write(" acc%%0t=%0t acc%%0d=%0d\n", high_acc, high_acc);
$write("[%0t] stime%%0t=%0t stime%%0d=%0d stime%%0f=%0f\n",
$time, $stime, $stime, $stime);
// verilator lint_off REALCVT
$write("[%0t] rtime%%0t=%0t rtime%%0d=%0d rtime%%0f=%0f\n",
$time, $realtime, $realtime, $realtime);
// verilator lint_on REALCVT
dpii_check();
$write("*-* All Finished *-*\n");
$finish;
end
end
end
endmodule

View File

@ -6,10 +6,10 @@
// Intentionally no timescale here, nor in driver file
module t;
initial begin
// Unspecified, but general consensus is 1s is default timeunit
$printtimescale;
$write("*-* All Finished *-*\n");
$finish;
end
initial begin
// Unspecified, but general consensus is 1s is default timeunit
$printtimescale;
$write("*-* All Finished *-*\n");
$finish;
end
endmodule

View File

@ -7,11 +7,11 @@
module pre_no_ts;
endmodule
`timescale 1ns/1ns
`timescale 1ns / 1ns
module t;
pre_no_ts pre_no_ts();
post_no_ts pst_no_ts();
pre_no_ts pre_no_ts ();
post_no_ts pst_no_ts ();
endmodule
module post_no_ts;

View File

@ -51,61 +51,61 @@ endmodule
module r0;
timeunit 10ns / 1ns;
task check; $write("%m %0t\n", $time); endtask
timeunit 10ns / 1ns;
task check; $write("%m %0t\n", $time); endtask
endmodule
module r1;
timeunit 10ns;
timeprecision 1ns;
task check; $write("%m %0t\n", $time); endtask
timeunit 10ns;
timeprecision 1ns;
task check; $write("%m %0t\n", $time); endtask
endmodule
module t;
sp2 sp2();
sp1 sp1();
sp0 sp0();
sm1 sm1();
sm2 sm2();
sm3 sm3();
sm4 sm4();
sm5 sm5();
sm6 sm6();
sm7 sm7();
sm8 sm8();
sm9 sm9();
sm10 sm10();
sm11 sm11();
sm12 sm12();
sm13 sm13();
sm14 sm14();
sm15 sm15();
sp2 sp2();
sp1 sp1();
sp0 sp0();
sm1 sm1();
sm2 sm2();
sm3 sm3();
sm4 sm4();
sm5 sm5();
sm6 sm6();
sm7 sm7();
sm8 sm8();
sm9 sm9();
sm10 sm10();
sm11 sm11();
sm12 sm12();
sm13 sm13();
sm14 sm14();
sm15 sm15();
r0 r0();
r1 r1();
r0 r0();
r1 r1();
final begin
sp2.check();
sp1.check();
sp0.check();
sm1.check();
sm2.check();
sm3.check();
sm4.check();
sm5.check();
sm6.check();
sm7.check();
sm8.check();
sm9.check();
sm10.check();
sm11.check();
sm12.check();
sm13.check();
sm14.check();
sm15.check();
r0.check();
r1.check();
$write("*-* All Finished *-*\n");
$finish;
end
final begin
sp2.check();
sp1.check();
sp0.check();
sm1.check();
sm2.check();
sm3.check();
sm4.check();
sm5.check();
sm6.check();
sm7.check();
sm8.check();
sm9.check();
sm10.check();
sm11.check();
sm12.check();
sm13.check();
sm14.check();
sm15.check();
r0.check();
r1.check();
$write("*-* All Finished *-*\n");
$finish;
end
endmodule

View File

@ -17,10 +17,10 @@
%Error: t/t_timescale_parse_bad.v:15:1: `timescale syntax error: ' 1ns / 1ps /extra'
15 | `timescale 1ns / 1ps /extra
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
%Error: t/t_timescale_parse_bad.v:18:13: timeunit illegal value
18 | timeunit 2ps;
| ^~~
%Error: t/t_timescale_parse_bad.v:19:18: timeprecision illegal value
19 | timeprecision 2ps;
| ^~~
%Error: t/t_timescale_parse_bad.v:18:12: timeunit illegal value
18 | timeunit 2ps;
| ^~~
%Error: t/t_timescale_parse_bad.v:19:17: timeprecision illegal value
19 | timeprecision 2ps;
| ^~~
%Error: Exiting due to

View File

@ -15,6 +15,6 @@
`timescale 1ns / 1ps /extra
module t;
timeunit 2ps; // Bad
timeprecision 2ps; // Bad
timeunit 2ps; // Bad
timeprecision 2ps; // Bad
endmodule

View File

@ -6,18 +6,18 @@
`timescale 1ns/1ns
module t;
p p ();
p p ();
// Also check not-found modules
localparam NOT = 0;
if (NOT) begin
NotFound not_found(.*);
end
// Also check not-found modules
localparam NOT = 0;
if (NOT) begin
NotFound not_found(.*);
end
initial begin
$write("*-* All Finished *-*\n");
$finish;
end
initial begin
$write("*-* All Finished *-*\n");
$finish;
end
endmodule
@ -34,10 +34,10 @@ input in;
reg out;
table
0 : 1;
1 : 0;
? : ?;
x : x;
0 : 1;
1 : 0;
? : ?;
x : x;
endtable
endprimitive
`endcelldefine

View File

@ -4,27 +4,26 @@
// any use, without warranty, 2021 by Wilson Snyder.
// SPDX-License-Identifier: CC0-1.0
timeunit 10ps;
timeprecision 10ps;
timeunit 10ps; timeprecision 10ps;
task show;
$printtimescale;
$printtimescale;
endtask
module from_unit;
task show;
$printtimescale;
endtask
task show;
$printtimescale;
endtask
endmodule
module t;
from_unit from_unit();
timeunit 100ps;
initial begin
show();
from_unit.show();
$printtimescale;
$write("*-* All Finished *-*\n");
$finish;
end
from_unit from_unit ();
timeunit 100ps;
initial begin
show();
from_unit.show();
$printtimescale;
$write("*-* All Finished *-*\n");
$finish;
end
endmodule