Lab: a 50,000-cycle watchdog in seconds
The watchdog reloads a down-counter on every kick and raises bite when it reaches zero.
The requirement: bite is high exactly when there has been no kick (or reset) for TIMEOUT ticks. With
BUG = 1, the watchdog ignores kicks once it has bitten — a real mistake when "bite" is meant to be recoverable.
// watchdog.sv — down-counting watchdog
module watchdog #(
parameter int TIMEOUT = 50000,
parameter bit BUG = 1'b0
) (
input logic clk,
input logic rst,
input logic kick,
output logic bite,
output logic [$clog2(TIMEOUT+1)-1:0] remaining
);
localparam int CW = $clog2(TIMEOUT + 1);
// BUG: once bitten, kicks are ignored
wire reload = BUG ? (kick && !bite) : kick;
always_ff @(posedge clk)
if (rst || reload) remaining <= CW'(TIMEOUT);
else if (remaining != '0) remaining <= remaining - 1'b1;
assign bite = (remaining == '0);
endmodule// watchdog_fv.sv — spec model + inductive helper
module watchdog_fv #(
parameter int TIMEOUT = 50000,
parameter bit BUG = 1'b0
) (
input logic clk,
input logic rst,
input logic kick
);
localparam int CW = $clog2(TIMEOUT + 1);
logic bite;
logic [CW-1:0] remaining;
watchdog #(.TIMEOUT(TIMEOUT), .BUG(BUG)) dut (.*);
initial assume (rst);
default clocking cb @(posedge clk); endclocking
default disable iff (rst);
// spec model: ticks since the last kick or reset, saturating at TIMEOUT
logic [31:0] quiet;
always_ff @(posedge clk)
if (rst || kick) quiet <= '0;
else if (quiet != 32'(TIMEOUT)) quiet <= quiet + 1;
a_spec: assert property (bite == (quiet == 32'(TIMEOUT)));
a_kick_clears: assert property (kick |=> !bite);
`ifndef NO_HELPER
a_helper: assert property (32'(remaining) + quiet == 32'(TIMEOUT));
`endif
c_bite: cover property (bite);
c_recover: cover property (bite ##1 kick ##1 !bite);
c_kick_just_in_time: cover property (remaining == 1 && kick);
endmodule# watchdog.sby
[tasks]
prove
nohelper
cover
bug
[options]
prove: mode prove
prove: depth 3
nohelper: mode prove
nohelper: depth 3
cover: mode cover
cover: depth 20
bug: mode bmc
bug: depth 20
[engines]
smtbmc
[script]
nohelper: read -define NO_HELPER
read -formal watchdog.sv watchdog_fv.sv
cover: chparam -set TIMEOUT 6 watchdog_fv
bug: chparam -set TIMEOUT 6 -set BUG 1 watchdog_fv
prep -top watchdog_fv
[files]
watchdog.sv
watchdog_fv.svRun it and compare
| Task | TIMEOUT | Expected result | Lesson |
|---|---|---|---|
prove | 50,000 | PASS in seconds (k-induction, k = 3) | the helper makes the spec inductive |
nohelper | 50,000 | no proof: the induction step fails from an unreachable state | depth alone cannot help |
cover | 6 | all covers reached within 20 cycles | small parameters for reachability |
bug | 6 | FAIL: kick after a bite does not clear it | small parameters for bug hunting |
In the nohelper run, open the induction counterexample: it starts from a state such as
remaining = 7 with quiet = 3 — consistent with the spec for a few cycles, but impossible from reset.
That is exactly the unreachable state the helper rules out.