Tests: Change default indent to 2 spaces (match edaplayground). No functional change.

This commit is contained in:
Wilson Snyder 2025-07-03 20:43:13 -04:00
parent f77af4e6f6
commit 26c7f1adb6
11 changed files with 230 additions and 230 deletions

View File

@ -7,12 +7,12 @@
module sub module sub
#(parameter type TYPE_t = logic) #(parameter type TYPE_t = logic)
( (
input TYPE_t in, input TYPE_t in,
output TYPE_t out output TYPE_t out
); );
// Some simple logic // Some simple logic
always_comb out = ~in; always_comb out = ~in;
endmodule endmodule

View File

@ -7,8 +7,8 @@
// See also https://verilator.org/guide/latest/examples.html" // See also https://verilator.org/guide/latest/examples.html"
module top; module top;
initial begin initial begin
$display("Hello World!"); $display("Hello World!");
$finish; $finish;
end end
endmodule endmodule

View File

@ -7,8 +7,8 @@
// See also https://verilator.org/guide/latest/examples.html" // See also https://verilator.org/guide/latest/examples.html"
module top; module top;
initial begin initial begin
$display("Hello World!"); $display("Hello World!");
$finish; $finish;
end end
endmodule endmodule

View File

@ -7,8 +7,8 @@
// See also https://verilator.org/guide/latest/examples.html" // See also https://verilator.org/guide/latest/examples.html"
module top; module top;
initial begin initial begin
$display("Hello World!"); $display("Hello World!");
$finish; $finish;
end end
endmodule endmodule

View File

@ -9,29 +9,29 @@
module secret_impl module secret_impl
( (
input [31:0] a, input [31:0] a,
input [31:0] b, input [31:0] b,
output logic [31:0] x, output logic [31:0] x,
input clk, input clk,
input reset_l); input reset_l);
logic [31:0] accum_q; logic [31:0] accum_q;
logic [31:0] secret_value; logic [31:0] secret_value;
initial $display("[%0t] %m: initialized", $time); initial $display("[%0t] %m: initialized", $time);
always @(posedge clk) begin always @(posedge clk) begin
if (!reset_l) begin if (!reset_l) begin
accum_q <= 0; accum_q <= 0;
secret_value <= 9; secret_value <= 9;
end end
else begin else begin
accum_q <= accum_q + a; accum_q <= accum_q + a;
if (accum_q > 10) if (accum_q > 10)
x <= b; x <= b;
else else
x <= a + b + secret_value; x <= a + b + secret_value;
end end
end end
endmodule endmodule

View File

@ -8,39 +8,39 @@
module top (input clk); module top (input clk);
int cyc; int cyc;
logic reset_l; logic reset_l;
logic [31:0] a; logic [31:0] a;
logic [31:0] b; logic [31:0] b;
logic [31:0] x; logic [31:0] x;
verilated_secret secret (.a, .b, .x, .clk, .reset_l); verilated_secret secret (.a, .b, .x, .clk, .reset_l);
always @(posedge clk) begin always @(posedge clk) begin
$display("[%0t] cyc=%0d a=%0d b=%0d x=%0d", $time, cyc, a, b, x); $display("[%0t] cyc=%0d a=%0d b=%0d x=%0d", $time, cyc, a, b, x);
cyc <= cyc + 1; cyc <= cyc + 1;
if (cyc == 0) begin if (cyc == 0) begin
reset_l <= 0; reset_l <= 0;
a <= 0; a <= 0;
b <= 0; b <= 0;
end end
else if (cyc == 1) begin else if (cyc == 1) begin
reset_l <= 1; reset_l <= 1;
a <= 5; a <= 5;
b <= 7; b <= 7;
end end
else if (cyc == 2) begin else if (cyc == 2) begin
a <= 6; a <= 6;
b <= 2; b <= 2;
end end
else if (cyc == 3) begin else if (cyc == 3) begin
a <= 1; a <= 1;
b <= 9; b <= 9;
end end
else if (cyc > 4) begin else if (cyc > 4) begin
$display("Done"); $display("Done");
$finish; $finish;
end end
end end
endmodule endmodule

View File

@ -11,32 +11,32 @@ module sub
input reset_l input reset_l
); );
// Example counter/flop // Example counter/flop
reg [31:0] count_c; reg [31:0] count_c;
always_ff @(posedge clk) begin always_ff @(posedge clk) begin
if (!reset_l) begin if (!reset_l) begin
/*AUTORESET*/ /*AUTORESET*/
// Beginning of autoreset for uninitialized flops // Beginning of autoreset for uninitialized flops
count_c <= 32'h0; count_c <= 32'h0;
// End of automatics // End of automatics
end
else begin
count_c <= count_c + 1;
if (count_c >= 3) begin
// This write is a magic value the Makefile uses to make sure the
// test completes successfully.
$write("*-* All Finished *-*\n");
$finish;
end end
else begin end
count_c <= count_c + 1; end
if (count_c >= 3) begin
// This write is a magic value the Makefile uses to make sure the
// test completes successfully.
$write("*-* All Finished *-*\n");
$finish;
end
end
end
// An example assertion // An example assertion
always_ff @(posedge clk) begin always_ff @(posedge clk) begin
AssertionExample : assert (!reset_l || count_c < 100); AssertionExample : assert (!reset_l || count_c < 100);
end end
// And example coverage analysis // And example coverage analysis
cover property (@(posedge clk) count_c == 3); cover property (@(posedge clk) count_c == 3);
endmodule endmodule

View File

@ -11,36 +11,36 @@
module top module top
( (
// Declare some signals so we can see how I/O works // Declare some signals so we can see how I/O works
input clk, input clk,
input reset_l, input reset_l,
output wire [1:0] out_small, output wire [1:0] out_small,
output wire [39:0] out_quad, output wire [39:0] out_quad,
output wire [69:0] out_wide, output wire [69:0] out_wide,
input [1:0] in_small, input [1:0] in_small,
input [39:0] in_quad, input [39:0] in_quad,
input [69:0] in_wide input [69:0] in_wide
); );
// Connect up the outputs, using some trivial logic // Connect up the outputs, using some trivial logic
assign out_small = ~reset_l ? '0 : (in_small + 2'b1); assign out_small = ~reset_l ? '0 : (in_small + 2'b1);
assign out_quad = ~reset_l ? '0 : (in_quad + 40'b1); assign out_quad = ~reset_l ? '0 : (in_quad + 40'b1);
assign out_wide = ~reset_l ? '0 : (in_wide + 70'b1); assign out_wide = ~reset_l ? '0 : (in_wide + 70'b1);
// And an example sub module. The submodule will print stuff. // And an example sub module. The submodule will print stuff.
sub sub (/*AUTOINST*/ sub sub (/*AUTOINST*/
// Inputs // Inputs
.clk (clk), .clk (clk),
.reset_l (reset_l)); .reset_l (reset_l));
// Print some stuff as an example // Print some stuff as an example
initial begin initial begin
if ($test$plusargs("trace") != 0) begin if ($test$plusargs("trace") != 0) begin
$display("[%0t] Tracing to logs/vlt_dump.vcd...\n", $time); $display("[%0t] Tracing to logs/vlt_dump.vcd...\n", $time);
$dumpfile("logs/vlt_dump.vcd"); $dumpfile("logs/vlt_dump.vcd");
$dumpvars(); $dumpvars();
end end
$display("[%0t] Model running...\n", $time); $display("[%0t] Model running...\n", $time);
end end
endmodule endmodule

View File

@ -12,47 +12,47 @@ module sub
input reset_l input reset_l
); );
// Example counter/flop // Example counter/flop
reg [31:0] count_f; reg [31:0] count_f;
always_ff @(posedge fastclk) begin always_ff @(posedge fastclk) begin
if (!reset_l) begin if (!reset_l) begin
/*AUTORESET*/ /*AUTORESET*/
// Beginning of autoreset for uninitialized flops // Beginning of autoreset for uninitialized flops
count_f <= 32'h0; count_f <= 32'h0;
// End of automatics // End of automatics
end end
else begin else begin
count_f <= count_f + 1; count_f <= count_f + 1;
end end
end end
// Another example flop // Another example flop
reg [31:0] count_c; reg [31:0] count_c;
always_ff @(posedge clk) begin always_ff @(posedge clk) begin
if (!reset_l) begin if (!reset_l) begin
/*AUTORESET*/ /*AUTORESET*/
// Beginning of autoreset for uninitialized flops // Beginning of autoreset for uninitialized flops
count_c <= 32'h0; count_c <= 32'h0;
// End of automatics // End of automatics
end
else begin
count_c <= count_c + 1;
if (count_c >= 3) begin
$display("[%0t] fastclk is %0d times faster than clk\n", $time, count_f / count_c);
// This write is a magic value the Makefile uses to make sure the
// test completes successfully.
$write("*-* All Finished *-*\n");
$finish;
end end
else begin end
count_c <= count_c + 1; end
if (count_c >= 3) begin
$display("[%0t] fastclk is %0d times faster than clk\n", $time, count_f / count_c);
// This write is a magic value the Makefile uses to make sure the
// test completes successfully.
$write("*-* All Finished *-*\n");
$finish;
end
end
end
// An example assertion // An example assertion
always_ff @(posedge clk) begin always_ff @(posedge clk) begin
AssertionExample : assert (!reset_l || count_c < 100); AssertionExample : assert (!reset_l || count_c < 100);
end end
// And example coverage analysis // And example coverage analysis
cover property (@(posedge clk) count_c == 3); cover property (@(posedge clk) count_c == 3);
endmodule endmodule

View File

@ -23,21 +23,21 @@ module top
input [69:0] in_wide input [69:0] in_wide
); );
// Connect up the outputs, using some trivial logic // Connect up the outputs, using some trivial logic
assign out_small = ~reset_l ? '0 : (in_small + 2'b1); assign out_small = ~reset_l ? '0 : (in_small + 2'b1);
assign out_quad = ~reset_l ? '0 : (in_quad + 40'b1); assign out_quad = ~reset_l ? '0 : (in_quad + 40'b1);
assign out_wide = ~reset_l ? '0 : (in_wide + 70'b1); assign out_wide = ~reset_l ? '0 : (in_wide + 70'b1);
// And an example sub module. The submodule will print stuff. // And an example sub module. The submodule will print stuff.
sub sub (/*AUTOINST*/ sub sub (/*AUTOINST*/
// Inputs // Inputs
.clk (clk), .clk (clk),
.fastclk (fastclk), .fastclk (fastclk),
.reset_l (reset_l)); .reset_l (reset_l));
// Print some stuff as an example // Print some stuff as an example
initial begin initial begin
$display("[%0t] Model running...\n", $time); $display("[%0t] Model running...\n", $time);
end end
endmodule endmodule

View File

@ -21,80 +21,80 @@
`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); `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);
module t(/*AUTOARG*/ module t(/*AUTOARG*/
// Inputs // Inputs
clk clk
); );
input clk; input clk;
int cyc; int cyc;
reg [63:0] crc; reg [63:0] crc;
reg [63:0] sum; reg [63:0] sum;
// Take CRC data and apply to testblock inputs // Take CRC data and apply to testblock inputs
wire [31:0] in = crc[31:0]; wire [31:0] in = crc[31:0];
/*AUTOWIRE*/ /*AUTOWIRE*/
// Beginning of automatic wires (for undeclared instantiated-module outputs) // Beginning of automatic wires (for undeclared instantiated-module outputs)
wire [31:0] out; // From test of Test.v wire [31:0] out; // From test of Test.v
// End of automatics // End of automatics
Test test(/*AUTOINST*/ Test test(/*AUTOINST*/
// Outputs // Outputs
.out (out[31:0]), .out (out[31:0]),
// Inputs // Inputs
.clk (clk), .clk (clk),
.in (in[31:0])); .in (in[31:0]));
// Aggregate outputs into a single result vector // Aggregate outputs into a single result vector
wire [63:0] result = {32'h0, out}; wire [63:0] result = {32'h0, out};
// Test loop // Test loop
always @(posedge clk) begin always @(posedge clk) begin
`ifdef TEST_VERBOSE `ifdef TEST_VERBOSE
$write("[%0t] cyc==%0d crc=%x result=%x\n", $time, cyc, crc, result); $write("[%0t] cyc==%0d crc=%x result=%x\n", $time, cyc, crc, result);
`endif `endif
cyc <= cyc + 1; cyc <= cyc + 1;
crc <= {crc[62:0], crc[63] ^ crc[2] ^ crc[0]}; crc <= {crc[62:0], crc[63] ^ crc[2] ^ crc[0]};
sum <= result ^ {sum[62:0], sum[63] ^ sum[2] ^ sum[0]}; sum <= result ^ {sum[62:0], sum[63] ^ sum[2] ^ sum[0]};
if (cyc == 0) begin if (cyc == 0) begin
// Setup // Setup
crc <= 64'h5aef0c8d_d70a4497; crc <= 64'h5aef0c8d_d70a4497;
sum <= '0; sum <= '0;
end end
else if (cyc < 10) begin else if (cyc < 10) begin
sum <= '0; sum <= '0;
end end
else if (cyc < 90) begin else if (cyc < 90) begin
end end
else if (cyc == 99) begin else if (cyc == 99) begin
$write("[%0t] cyc==%0d crc=%x sum=%x\n", $time, cyc, crc, sum); $write("[%0t] cyc==%0d crc=%x sum=%x\n", $time, cyc, crc, sum);
`checkh(crc, 64'hc77bb9b3784ea091); `checkh(crc, 64'hc77bb9b3784ea091);
// What checksum will we end up with (above print should match) // What checksum will we end up with (above print should match)
`checkh(sum, 64'h4afe43fb79d7b71e); `checkh(sum, 64'h4afe43fb79d7b71e);
$write("*-* All Finished *-*\n"); $write("*-* All Finished *-*\n");
$finish; $finish;
end end
end end
endmodule endmodule
module Test(/*AUTOARG*/ module Test(/*AUTOARG*/
// Outputs // Outputs
out, out,
// Inputs // Inputs
clk, in clk, in
); );
// Replace this module with the device under test. // Replace this module with the device under test.
// //
// Change the code in the t module to apply values to the inputs and // Change the code in the t module to apply values to the inputs and
// merge the output values into the result vector. // merge the output values into the result vector.
input clk; input clk;
input [31:0] in; input [31:0] in;
output reg [31:0] out; output reg [31:0] out;
always @(posedge clk) begin always @(posedge clk) begin
out <= in; out <= in;
end end
endmodule endmodule