host_watchdog_tb.v 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. `timescale 1ns/1ps
  2. module host_watchdog_tb;
  3. reg clk = 1'b0;
  4. reg rst_n = 1'b0;
  5. reg tick_500us = 1'b0;
  6. reg valid_set_all_commit = 1'b0;
  7. wire watchdog_active;
  8. wire timeout_event;
  9. always #1 clk = ~clk;
  10. initial begin
  11. #100000;
  12. $fatal(1, "watchdog production-boundary timeout count=%0d active=%b event=%b",
  13. dut.tick_count, watchdog_active, timeout_event);
  14. end
  15. // Production-boundary simulation. Formal proves the same ordering with a
  16. // small timeout parameter to keep the proof reachable.
  17. host_watchdog #(.TIMEOUT_TICKS(20000)) dut (
  18. .clk(clk), .rst_n(rst_n), .tick_500us(tick_500us),
  19. .valid_set_all_commit(valid_set_all_commit), .watchdog_active(watchdog_active),
  20. .timeout_event(timeout_event)
  21. );
  22. task pulse_tick;
  23. begin
  24. @(negedge clk);
  25. tick_500us = 1'b1;
  26. @(negedge clk);
  27. tick_500us = 1'b0;
  28. end
  29. endtask
  30. initial begin
  31. repeat (2) @(posedge clk);
  32. if (dut.tick_count !== 0 || watchdog_active || timeout_event)
  33. $fatal(1, "watchdog reset state is not idle");
  34. rst_n = 1'b1;
  35. repeat (19999) pulse_tick();
  36. if (dut.tick_count !== 19999 || watchdog_active || timeout_event)
  37. $fatal(1, "watchdog pre-timeout boundary mismatch count=%0d", dut.tick_count);
  38. pulse_tick();
  39. if (!timeout_event || !watchdog_active) $fatal(1, "watchdog did not expire at timeout");
  40. @(posedge clk);
  41. @(negedge clk);
  42. if (timeout_event) $fatal(1, "watchdog timeout event was not one cycle");
  43. @(negedge clk);
  44. valid_set_all_commit = 1'b1;
  45. tick_500us = 1'b1;
  46. @(negedge clk);
  47. valid_set_all_commit = 1'b0;
  48. tick_500us = 1'b0;
  49. repeat (3) pulse_tick();
  50. if (watchdog_active || timeout_event) $fatal(1, "valid commit did not reset watchdog");
  51. $display("host_watchdog_tb PASS");
  52. $finish;
  53. end
  54. endmodule