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.
- Write a class, a compound constraint, and a factory function from scratch
- Write three constraints from scratch, each with its own name
- Write three
insideconstraints from scratch, three different set shapes - Write two
distclauses from scratch: a fair coin, and a loaded die - Write two implication constraints from scratch
- Write a foreach constraint, and an inline randomize() with {} constraint
- Write a function that makes randomize() reproducible
- rand_mode(0) left on from a debug helper
- A subclass’s new constraint doesn’t replace the base class’s
- Write post_randomize() so a queue of objects isn’t full of nulls
- Write two
with-transformed array reduction constraints from scratch - uvm_config_db::get() works fine – nobody ever called set()
- Dropping an objection that was never raised is a fatal, not a no-op
- Creating a sequence isn’t the same as running it
SV SystemVerilog 12
Constraints, classes and state across calls, with several pieces working at once.
- Sorted isn’t the same as non-overlapping – unless you check the right pair
- Counting flipped bits with sum() with(), not $countones()
- Uniqueness scoped to the wrong dimension
- Three lifecycle pieces, one class
- One distinguished header, three different kinds of persistent state
- When a hazard happens, decide which register(s) it hits
- Three forwarding paths deep, not one
- Aggregate constraints on an array of structs: what with() can and can’t do here
- No sorting allowed: check every pair, not just neighbors
- Three techniques, one class, all of them have to actually work together
- Three sensible constraints that can never all hold – and nobody checks randomize()
- The link never deadlocks under everyday traffic – only a full-depth burst finds it
UVM UVM 8
Testbench bugs: the factory, config_db, objections, analysis ports and sequencers.
- The factory override runs clean, but the DUT’s parity checker never gets tested
- Five items, one bad, and the run dies on it – with a UVM_FATAL, not a check failure
- Four DMA channel agents, four configured ids, one wrong answer reported four times
- The test’s override compiles clean, runs clean, and still silently loses
- Every deferred transaction ends up showing the last one’s data, not its own
- Write a scoreboard that matches two transaction streams by id, not by arrival order
- Write coord_vseq::body() so channel B carries the tag channel A’s driver actually saw
- The scoreboard’s predictor calls the same CRC-8 function the “DUT” does – of course they agree
CSR Register model 6
The UVM register model: mirrors, predictors, hooks and access policies.
- Extend uvm_mem to catch an address-decode bug – the base class remembers nothing
- Override uvm_reg’s sample() hook – it runs before the mirror updates
- Catch a write that never reaches hardware – write()’s status and the mirror both say it did
- Wire up a uvm_reg_predictor – with explicit prediction, nothing else updates the mirror
- Enable a device through update() without clearing a pending interrupt in the same register
- confirm_write() checks the mirror right after the write that set it – of course it agrees