`timescale 1ns/1ps module prod2u_por_tb; reg sys_clk; wire sys_rst_n; integer cycle_count; prod2u_por #( .POR_CYCLES(1024) ) dut ( .sys_clk(sys_clk), .sys_rst_n(sys_rst_n) ); initial begin sys_clk = 1'b0; forever #20 sys_clk = ~sys_clk; end always @(sys_rst_n) begin if (sys_rst_n === 1'b1 && ($time % 40) !== 20) begin $display("POR release was not synchronous time=%0t", $time); $fatal; end end initial begin cycle_count = 0; if (sys_rst_n !== 1'b0) begin $display("POR did not initialize asserted"); $fatal; end repeat (1023) begin @(posedge sys_clk); #1; cycle_count = cycle_count + 1; if (sys_rst_n !== 1'b0) begin $display("POR released early at cycle=%0d", cycle_count); $fatal; end end @(posedge sys_clk); #1; cycle_count = cycle_count + 1; if (cycle_count !== 1024 || sys_rst_n !== 1'b1) begin $display("POR release mismatch cycles=%0d rst_n=%b", cycle_count, sys_rst_n); $fatal; end @(negedge sys_clk); if (sys_rst_n !== 1'b1) begin $display("POR release did not remain asserted after synchronous release"); $fatal; end $display("PASS: prod2u_por_tb"); $finish; end endmodule