Count the failures of conditional properties with a missing else or default, on traces where the condition is often false.
Hardware context: Conditional checks of a bus whose condition is often false. Count only real failures when a branch or a case item is missing.
Each question is one assertion and one short trace, run in the program of the specification. Write answer(q) so it returns the number of failures the run reports.
Questions 0 to 2 are worked examples. Questions 3 to 6 use if without else, case without default, and a chained else if; they are graded only by the full check.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
question | 4 | input of each check |
Full specification
module tb;
logic clk = 0;
always #5 clk = ~clk; // rising edges at 5, 15, 25, ...
logic sig = 0;
int fails = 0;
rule: assert property (@(posedge clk) <property>) else fails++;
// Row k of each table is the value sampled at edge k + 1.
logic sig_at [2] = '{0, 1};
initial begin
for (int k = 0; k < 2; k++) begin
sig = sig_at[k];
@(negedge clk);
end
$display("fails=%0d", fails);
$finish;
end
endmodule
q=0 (worked example): req |-> if (wr) ##1 ack else ##2 rdy
| Signal | edge 1 | edge 2 | edge 3 | edge 4 | edge 5 | edge 6 |
|---|---|---|---|---|---|---|
| req | 1 | 0 | 1 | 0 | 0 | 0 |
| wr | 1 | 0 | 0 | 0 | 0 | 0 |
| ack | 0 | 0 | 0 | 0 | 0 | 0 |
| rdy | 0 | 0 | 0 | 0 | 1 | 0 |
q=1 (worked example): v |-> case (sel) 2'd0: ##1 a; default: 1'b0; endcase
| Signal | edge 1 | edge 2 | edge 3 | edge 4 | edge 5 | edge 6 |
|---|---|---|---|---|---|---|
| v | 1 | 1 | 0 | 1 | 0 | 0 |
| sel | 0 | 2 | 0 | 3 | 0 | 0 |
| a | 0 | 1 | 0 | 0 | 0 | 0 |
q=2 (worked example): if (c) ##1 d else ##1 !d
| Signal | edge 1 | edge 2 | edge 3 | edge 4 | edge 5 | edge 6 |
|---|---|---|---|---|---|---|
| c | 1 | 0 | 0 | 1 | 0 | 0 |
| d | 0 | 1 | 1 | 0 | 0 | 0 |
q=3 (graded): if (wr) ##1 ack
| Signal | edge 1 | edge 2 | edge 3 | edge 4 | edge 5 | edge 6 | edge 7 | edge 8 |
|---|---|---|---|---|---|---|---|---|
| wr | 1 | 0 | 0 | 1 | 0 | 0 | 1 | 0 |
| ack | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
q=4 (graded): v |-> case (sel) 2'd0: ##1 a; 2'd1: ##2 a; endcase
| Signal | edge 1 | edge 2 | edge 3 | edge 4 | edge 5 | edge 6 | edge 7 | edge 8 |
|---|---|---|---|---|---|---|---|---|
| v | 1 | 1 | 1 | 0 | 1 | 1 | 0 | 0 |
| sel | 2 | 0 | 3 | 0 | 1 | 2 | 0 | 0 |
| a | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 |
q=5 (graded): req |-> if (wr) ##1 ack
| Signal | edge 1 | edge 2 | edge 3 | edge 4 | edge 5 | edge 6 | edge 7 | edge 8 |
|---|---|---|---|---|---|---|---|---|
| req | 1 | 1 | 0 | 1 | 1 | 0 | 0 | 0 |
| wr | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 0 |
| ack | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
q=6 (graded): if (a) ##1 b else if (c) ##1 d
| Signal | edge 1 | edge 2 | edge 3 | edge 4 | edge 5 | edge 6 | edge 7 | edge 8 |
|---|---|---|---|---|---|---|---|---|
| a | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 0 |
| b | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
| c | 0 | 1 | 0 | 1 | 1 | 0 | 0 | 0 |
| d | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 |
Examples
Example 1
Both Branches Checked- Input
answer(0)
- Output
fails = 1
The write at edge 1 has no ack at 2: a failure. The read at edge 3 gets rdy at 5. One failure.
Example 2
A Default That Fails- Input
answer(1)
- Output
fails = 2
Edge 1 (sel 0) gets a at 2. Edges 2 and 4 pick the default, 1'b0, which fails at once. Two failures.
Example 3
An Else That Checks the Opposite- Input
answer(2)
- Output
fails = 2
Edge 1 needs d at 2: yes. Edge 2 needs !d at 3: d is 1, a failure. Edge 3 needs !d at 4: yes. Edge 4 needs d at 5: no. Edges 5 and 6 need !d next: yes, and the last attempt is still open. Two failures.
Constraints and Contract
- Return one failure count per question from answer(q).
- Keep the function header.
Hints
Hint 1
An if without else checks nothing when its condition is false. Is that a failure?
Hint 2
A case without default checks nothing for a value with no item.
Hint 3
else if is checked only when the first condition is false.
What the grader checks: Seven constant answers, graded against failure counts measured on Verilator 5.052 (which runs if, else and case properties correctly).
7 checks on Verilator · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 2 steps and the final capstone