Skip to content

brokenbench

brokenbench is a set of SystemVerilog, UVM and register-model exercises built around the bugs that compile, run, and still get the answer wrong. Each one gives you a spec and some code, either a stub to finish or working code with a real bug in it, and a checker that decides whether you got it right. Not whether it compiled: whether it does what the spec says.

Every exercise runs in your browser on a real Verilator build. The register-model exercises come with step-by-step walks of the mechanism each bug lives in. All of it is open source, so you can also clone the repository and run the same exercises on your own machine.

40 exercises in 4 tracks

LEARN Learn 14

Start here. One language feature at a time, mostly written from scratch.

  1. Write a class, a compound constraint, and a factory function from scratch write-from-scratch
  2. Write three constraints from scratch, each with its own name write-from-scratch
  3. Write three inside constraints from scratch, three different set shapes write-from-scratch
  4. Write two dist clauses from scratch: a fair coin, and a loaded die write-from-scratch / statistical
  5. Write two implication constraints from scratch write-from-scratch
  6. Write a foreach constraint, and an inline randomize() with {} constraint write-from-scratch
  7. Write a function that makes randomize() reproducible write-from-scratch / best-practice
  8. rand_mode(0) left on from a debug helper lifecycle-hook
  9. A subclass’s new constraint doesn’t replace the base class’s write-from-scratch / inheritance / lifecycle-hook
  10. Write post_randomize() so a queue of objects isn’t full of nulls write-from-scratch / lifecycle-hook / array
  11. Write two with-transformed array reduction constraints from scratch write-from-scratch / array
  12. uvm_config_db::get() works fine – nobody ever called set() config-db
  13. Dropping an objection that was never raised is a fatal, not a no-op objections
  14. Creating a sequence isn’t the same as running it sequence-start

SV SystemVerilog 12

Constraints, classes and state across calls, with several pieces working at once.

  1. Sorted isn’t the same as non-overlapping – unless you check the right pair Difficulty: write-from-scratch / multi-constraint / array
  2. Counting flipped bits with sum() with(), not $countones() Difficulty: write-from-scratch / multi-constraint / cross-call-state / array
  3. Uniqueness scoped to the wrong dimension Difficulty: write-from-scratch / multi-constraint / array / tool-limitation
  4. Three lifecycle pieces, one class Difficulty: write-from-scratch / multi-constraint / lifecycle-hook / array
  5. One distinguished header, three different kinds of persistent state Difficulty: write-from-scratch / cross-call-state / lifecycle-hook / multi-constraint
  6. When a hazard happens, decide which register(s) it hits Difficulty: write-from-scratch / statistical / cross-call-state / multi-constraint
  7. Three forwarding paths deep, not one Difficulty: write-from-scratch / statistical / cross-call-state / multi-constraint / tool-limitation
  8. Aggregate constraints on an array of structs: what with() can and can’t do here Difficulty: write-from-scratch / tool-limitation / multi-constraint / array / statistical
  9. No sorting allowed: check every pair, not just neighbors Difficulty: write-from-scratch / multi-constraint / array
  10. Three techniques, one class, all of them have to actually work together Difficulty: tool-limitation / write-from-scratch / requires-patched-verilator / array / multi-constraint / statistical
  11. Three sensible constraints that can never all hold – and nobody checks randomize() Difficulty: best-practice / multi-constraint / plausible-pass
  12. The link never deadlocks under everyday traffic – only a full-depth burst finds it Difficulty: best-practice / plausible-pass

UVM UVM 8

Testbench bugs: the factory, config_db, objections, analysis ports and sequencers.

  1. The factory override runs clean, but the DUT’s parity checker never gets tested Difficulty: factory-override / phase-ordering
  2. Five items, one bad, and the run dies on it – with a UVM_FATAL, not a check failure Difficulty: objections / phase-ending / error-path
  3. Four DMA channel agents, four configured ids, one wrong answer reported four times Difficulty: config-db / multi-instance / fork-join
  4. The test’s override compiles clean, runs clean, and still silently loses Difficulty: config-db / precedence
  5. Every deferred transaction ends up showing the last one’s data, not its own Difficulty: analysis-port / clone / do_copy
  6. Write a scoreboard that matches two transaction streams by id, not by arrival order Difficulty: write-from-scratch / scoreboard / analysis-port
  7. Write coord_vseq::body() so channel B carries the tag channel A’s driver actually saw Difficulty: write-from-scratch / virtual-sequencer / fork-join
  8. The scoreboard’s predictor calls the same CRC-8 function the “DUT” does – of course they agree Difficulty: scoreboard / plausible-pass

CSR Register model 6

The UVM register model: mirrors, predictors, hooks and access policies.

  1. Extend uvm_mem to catch an address-decode bug – the base class remembers nothing Difficulty: write-from-scratch / mem-model
  2. Override uvm_reg’s sample() hook – it runs before the mirror updates Difficulty: walk write-from-scratch / coverage / mirror
  3. Catch a write that never reaches hardware – write()’s status and the mirror both say it did Difficulty: write-from-scratch / mirror / best-practice
  4. Wire up a uvm_reg_predictor – with explicit prediction, nothing else updates the mirror Difficulty: walk predictor / mirror / analysis-port
  5. Enable a device through update() without clearing a pending interrupt in the same register Difficulty: walk write-from-scratch / w1c / access-policy
  6. confirm_write() checks the mirror right after the write that set it – of course it agrees Difficulty: predictor / access-policy / plausible-pass