Home › Practice › Formal Verification › Cover: can the queue ever fill up?

Cover: can the queue ever fill up?

EasyFormalcoversequential

Asserts say what must never go wrong. They cannot say that anything useful can happen. A design that does nothing at all passes every assert. Cover closes that gap.

Concept first. cover(condition) asks the tool: "show me a run where this condition happens". If it finds one, you get the run, and you know the state is reachable. If it finds none, the state may be unreachable, which often means a bug (or an assume that ruled out too much). Example with other numbers: a traffic light. cover(light == GREEN) shows the light can turn green.

The design counts how many items sit in a small queue (0 to 3). push adds one, pop removes one, and it ignores a push when full and a pop when empty. A queue that can never fill up is a bug, even though it never breaks a rule.

module dut(input clk, input rst, input push, input pop, output reg [2:0] count);
  initial count = 3'd0;
  always @(posedge clk) begin
    if (rst) count <= 3'd0;
    else if (push && !pop && count < 3'd3) count <= count + 3'd1;
    else if (pop && !push && count > 3'd0) count <= count - 3'd1;
  end
endmodule
Solve in your browser →

No install and no sign-up needed. You write your answer in the editor and Nishkam checks it.

More in this track

← A clocked rule: the counter never passes 9Proof or only a short search? Help the induction →