B3.5.2 Every Branch Ran

MediumDebug25 minIcarus · browser samples / server checksReview the topic

A crossing light visits every state and takes every move in its test, so every line of its code runs. The test still fails. Find the first bad cycle, name the bug, and fix the light.

Hardware context: A saturating up/down counter and a pedestrian crossing light. Spotting a rule the design forgot.

The light lets cars go until someone presses the button. Then it slows the cars for two clocks and stops them for three, with walk on. A press at any time must be remembered until the walk it asks for begins.

The bench presses the button three times and compares the light with its own model every clock. It also counts the clocks in each state, the moves between states and the presses in each state. Every count is above zero, so every line of walk_light ran. The test still fails.

Step 1: find the first cycle where state, walk or pending is not what the specification says, and name the signal. Step 2: choose the cause. Step 3, optional: fix walk_light; the fix is graded by the normal rows.

Signals in the Timeline

SignalWidthRole
scenario8input of each check
Full specification
The ports
// walk_light: cars GO until someone presses btn; then SLOW for 2 clocks, then STOP (walk = 1) for 3 clocks.
// GO lasts at least 4 clocks. A press at any time is remembered until the walk it asks for begins.
module walk_light (input logic clk, rst, btn, output logic [1:0] state, output logic walk);
  ...
endmodule
StateCodewalkLeaves when
GO00it has lasted 4 clocks and a press is waiting (or arrives now)
SLOW10after 2 clocks
STOP21after 3 clocks

pending is 1 from a press until the clock STOP begins. A press in the very clock STOP begins, or during STOP, asks for the next walk. Cycle N is the stretch after the N-th rising edge.

Diagnose the Failing Run

The test below runs the buggy design. Read its log, then find where it first goes wrong in the waveform.

Log

Waveform

Click a signal at a cycle to select it. Or focus the waveform and use the arrow keys: Left and Right move one cycle, Up and Down one signal.

Step 1 · The first bad cycle and signal
Step 2 · The cause

Step 3 is optional: fix the code in the editor, then run the tests.

Examples

Example 1

One Early Press, Then Nothing
Input
presses at clock 0
Output
walk_clocks = 3, states_by_clock = 0x16a000000000000

The result lists the state after each of 32 clocks, two bits each, first clock at the top. It also counts the clocks with walk on. One early press: GO lasts 4 clocks, then SLOW for 2, STOP for 3, and GO again.

Example 2

A Press During SLOW Asks for a Second Walk
Input
presses at clocks 4 and 8
Output
walk_clocks = 6, states_by_clock = 0x5a8016a0000000

The press during SLOW is remembered, so after STOP and four clocks of GO the light slows again.

Example 3

A Press During STOP Asks for the Next Walk
Input
presses at clocks 4 and 11
Output
walk_clocks = 6, states_by_clock = 0x5a8016a0000000

The press during STOP asks for the next walk, in the same way.

Constraints and Contract

  • Keep the module name, the ports and the state codes.
  • Reset is synchronous and active high.

Hints

Hint 1

Line up the three presses with the state the light was in at each.

Hint 2

Each cause shows first in a different cycle or on a different signal: watch pending as well as state and walk.

Hint 3

Ask which presses the design remembers, and which it should.

What the grader checks: The failing run is simulated live with the shipped light. The fix is graded on seven scripts of presses, each after two clocks of reset. Each row compares the state in the middle of 32 clocks with the specification.

7 checks on Icarus · browser samples / server checks. 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 problems on this path

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

One Early Press, Then Nothing

Input
presses at clock 0
Expected output
walk_clocks = 3, states_by_clock = 0x16a000000000000

The result lists the state after each of 32 clocks, two bits each, first clock at the top. It also counts the clocks with walk on. One early press: GO lasts 4 clocks, then SLOW for 2, STOP for 3, and GO again.

Run samples executes all 3 public checks. Check all tests runs 7 checks on the server.

Icarus · browser samples / server checks