`timescale 1ns/1ps module host_watchdog_tb; reg clk = 1'b0; reg rst_n = 1'b0; reg enable = 1'b0; reg tick_500us = 1'b0; reg valid_set_all_commit = 1'b0; wire watchdog_active; wire timeout_event; always #1 clk = ~clk; initial begin #100000; $fatal(1, "watchdog production-boundary timeout count=%0d active=%b event=%b", dut.tick_count, watchdog_active, timeout_event); end // Boundary sim with compact timeout; production 60000 covered by params/unit. host_watchdog #(.TIMEOUT_TICKS(20000)) dut ( .clk(clk), .rst_n(rst_n), .enable(enable), .tick_500us(tick_500us), .valid_set_all_commit(valid_set_all_commit), .watchdog_active(watchdog_active), .timeout_event(timeout_event) ); task pulse_tick; begin @(negedge clk); tick_500us = 1'b1; @(negedge clk); tick_500us = 1'b0; end endtask initial begin repeat (2) @(posedge clk); if (dut.tick_count !== 0 || watchdog_active || timeout_event) $fatal(1, "watchdog reset state is not idle"); rst_n = 1'b1; // Disabled: ticks must not advance or trip repeat (8) pulse_tick(); if (dut.tick_count !== 0 || watchdog_active) $fatal(1, "disabled watchdog advanced"); @(negedge clk); enable = 1'b1; repeat (19999) pulse_tick(); if (dut.tick_count !== 19999 || watchdog_active || timeout_event) $fatal(1, "watchdog pre-timeout boundary mismatch count=%0d", dut.tick_count); pulse_tick(); if (!timeout_event || !watchdog_active) $fatal(1, "watchdog did not expire at timeout"); @(posedge clk); @(negedge clk); if (timeout_event) $fatal(1, "watchdog timeout event was not one cycle"); @(negedge clk); valid_set_all_commit = 1'b1; tick_500us = 1'b1; @(negedge clk); valid_set_all_commit = 1'b0; tick_500us = 1'b0; repeat (3) pulse_tick(); if (watchdog_active || timeout_event) $fatal(1, "valid commit did not reset watchdog"); // Clear enable then re-enable: counter restarts @(negedge clk); enable = 1'b0; @(negedge clk); enable = 1'b1; if (dut.tick_count !== 0 || watchdog_active) $fatal(1, "re-enable did not clear counter"); $display("host_watchdog_tb PASS"); $finish; end endmodule