10.10.2 Break-It: Scenarios That Miss the Bug

MediumBreak ItVerilator · server4 hidden designsReview the topic

Choose three bus scenarios that expose four broken copies of a bus model, three of which need a pattern over time.

Hardware context: Memory controller that collects write bursts while reads arrive. Choose bus scenarios that expose bugs which need interleaving, an abort or length.

A bus model collects a three-write burst and commits it when all three slots have arrived. Reads see committed data only, and an abort drops the burst collected so far. The correct model is in the specification. Four copies each hide one bug.

In the task stimulus, build a scenario with op(kind, slot) and hand it to try_scenario, at most three times. The correct model and every broken copy run each scenario. A copy is caught when its signature differs from the correct one on at least one scenario.

Single operations catch only one of the four bugs. The other three need the right operations in the right order. This is why tests generate scenarios, and why a generator needs interleaving, aborts and length.

Signals in the Timeline

SignalWidthRole
hidden_bug8input of each check
Full specification
The correct bus model
// Run one scenario on the bus model and return a signature of everything it read.
// ops holds n operations, 4 bits each; the first operation is ops[3:0].
//   {2'b01, slot} write a slot    {2'b10, slot} read a slot    4'b1100 abort    4'b0000 idle
function automatic bit [15:0] run_bus(input bit [47:0] ops, input int n);
  bit [7:0]  mem [3];      // committed words
  bit [7:0]  hold [3];     // the write burst being collected
  bit [2:0]  have;         // which slots of the burst have arrived
  bit [7:0]  next_data;
  bit [15:0] sig;
  bit [1:0]  kind, slot;
  mem[0] = 8'hA0; mem[1] = 8'hA1; mem[2] = 8'hA2;
  have = 0; next_data = 8'h01; sig = 0;
  for (int k = 0; k < n; k++) begin
    kind = ops[4*k+2 +: 2];
    slot = ops[4*k +: 2];
    if (kind == 2'b01 && slot < 3) begin
      // A write is held back until all three slots of the burst have arrived.
      hold[slot] = next_data;
      next_data++;
      have[slot] = 1;
      if (have == 3'b111) begin
        mem[0] = hold[0]; mem[1] = hold[1]; mem[2] = hold[2];
        have = 0;
      end
    end else if (kind == 2'b10 && slot < 3) begin
      // A read sees committed data only.
      sig = 16'(sig * 31 + mem[slot] + 1);
    end else if (kind == 2'b11) begin
      // An abort drops the burst collected so far.
      have = 0;
    end
  end
  return sig;
endfunction
What you write
task automatic stimulus();
  begin_scenario();
  op(WR, 0); op(WR, 1); op(WR, 2); op(RD, 0);
  try_scenario(sc_ops, sc_len);
endtask
CallOperation
op(WR, slot)write the next data value to slot 0, 1 or 2 of the open burst
op(RD, slot)read slot 0, 1 or 2; the value goes into the signature
op(AB, 0)abort: drop the open burst

Rules for your scenarios: at most 3 scenarios, each with 1 to 12 operations.

Examples

Run samples checks your input rules and any explicitly public sample faults. Submit runs every hidden faulty copy on the server. The worked bug examples below describe Submit results.

Example 1

Your Scenarios Follow the Rules
Input
stimulus() hands over 3 scenarios of 7, 7 and 10 operations
Output
inputs_legal = yes

Three scenarios is the limit, and each has between 1 and 12 operations.

Example 2

A Read Inside an Open Burst
Input
W0 R0 W1 W2 R0 R1 R2
Output
caught = yes

The first read comes while the burst holds only slot 0. The correct model returns the old word A0. The copy that forwards held data returns 01, and is caught.

Example 3

An Abort in the Middle of a Burst
Input
W0 W1 abort W2 R0 R1 R2
Output
caught = yes

After the abort, the write to slot 2 starts a new burst, so nothing commits and the reads return the old words. The copy that keeps the burst commits it, and is caught.

Constraints and Contract

  • Call try_scenario at most 3 times inside stimulus.
  • Each scenario has 1 to 12 operations.
  • Do not call run_bus yourself.

Hints

Hint 1

For each sentence of the model's description, ask how a copy could get it wrong. Then ask which operations, in which order, make that mistake change a value that a later read returns.

Hint 2

A bug in the held-back burst shows only while a burst is open. What has to happen between the first and the last write of a burst?

Hint 3

One of the bugs depends on how long the scenario is, not on what it contains. Does any of your scenarios go past eight operations, with a read after that point?

What the grader checks: Your scenarios run on the correct model and on four copies with one bug each. Passing shows these scenarios separate these four bugs from the correct model, not that they would catch every bug.

5 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

Report a problem with this page

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

Your Scenarios Follow the Rules

Input
stimulus() hands over 3 scenarios of 7, 7 and 10 operations
Expected output
inputs_legal = yes

Three scenarios is the limit, and each has between 1 and 12 operations.

Run samples executes all 1 public checks. Check all tests runs 5 checks on the server.

Verilator · server