Fix a RAM test campaign whose scoreboard never compares read data, so most memory faults go unseen.
Hardware context: Single-clock dual-port byte-enabled RAM. Detect address, data-bit, byte-lane and collision-policy faults in the RAM.
A memory regression reported a stuck data bit, an address alias and swapped bytes as undetected. The traffic did reach those faults. The scoreboard simply never compared the data it read back.
The code has two classes. ram_campaign builds a fixed list of requests: a directed part, then eight edges from a seeded generator, then a final read sweep. ram_scoreboard is the sparse-byte scoreboard.
The tests play the same list on eleven RAMs: one correct and ten with a planted fault. They run everything twice and check that both runs agree. The report shows which faults were detected, the coverage reached and each final scoreboard report.
A fault counts as detected when the scoreboard reports any error. A fault that the configuration cannot show must stay clean.
Find the bug and fix it. The full request list is in the specification.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
active_lanes | 3 | input of each check |
memory_depth | 3 | input of each check |
latency_a | 2 | input of each check |
latency_b | 2 | input of each check |
read_policy | 1 | input of each check |
write_priority | 2 | input of each check |
random_seed | 32 | input of each check |
Full specification
class ram_campaign;
ram_op ops[$]; // the requests, in order
bit [31:0] state; // the generator state, final value after new()
function new(input int depth, lanes, input bit [31:0] seed);
endclass
// ram_scoreboard: the sparse-byte scoreboard, with allocated()
| Step | Requests |
|---|---|
| 1 | Read both ends: A reads 0 and B reads depth - 1. |
| 2 | For each address a: A writes 0x01010101 << a to a with all active strobes. Then A reads a and B reads (a + 1) mod depth. |
| 3 | For each active lane k: A writes 0xaabbccdd and B writes 0x10203041, both to 0 with strobe 1 << k. Then both read 0. |
| 4 | A writes 0x89abcdef with strobe 0x5 and B writes 0x76543211 with strobe 0xa, both to 0. Then both read 0. |
| 5 | A writes 0x55aa55ab to 0 and B writes 0xa55aa55b to depth - 1, all active strobes. Then read both ends. |
| 6 | A writes depth - 1 with strobe 0 and data 0. B writes 0xdeadbeef to address depth, which is out of range, with all active strobes. Then read both ends. |
| 7 | A reads 0 while B writes 0xf00dcafe to 0. Then A writes 0x01234567 to 0 while B reads 0. Then three idle edges. |
| 8 | Read both ends. One reset edge with both ports off. Three idle edges. Read both ends. |
| 9 | Eight seeded edges, below. |
| 10 | For each address a: A reads a and B reads depth - 1 - a. Then three idle edges. |
Every directed read uses strobe 0xf and data 0. All active strobes means (1 << lanes) - 1. Idle and reset edges have every field 0.
| Seeded edge | Rule |
|---|---|
| State | state starts at the seed. Each update is state = 1664525 × state + 1013904223, modulo 2^32. |
| Per edge | Three updates give control, then A data, then B data. |
| Port A | en = control[0], wr = control[1], address = control[11:8] mod (depth + 1), strobe = control[19:16]. |
| Port B | en = control[4], wr = control[5], address = control[15:12] mod (depth + 1), strobe = control[23:20]. |
| Fault | What is wrong with the RAM |
|---|---|
| 0 | Nothing: the correct RAM. |
| 1 | Bit 0 of every written word is stuck at 0. |
| 2 | Bit 0 of the word address is ignored. |
| 3 | Write bytes 0 and 1 trade places, when both exist. |
| 4 | Shared-lane priority is reversed in modes 0 and 1. |
| 5 | OLD and NEW are swapped. |
| 6 | The response data register never updates. |
| 7 | Every response comes one edge late. |
| 8 | Reads on port B never respond. |
| 9 | Reset does not cancel the reads in flight. |
| 10 | Out-of-range addresses wrap into memory. |
Some faults cannot show in some configurations. An address alias needs more than one word. A byte swap needs two lanes. Reversed priority does nothing in mode 2.
| Sparse model | Rule |
|---|---|
| Key | word_address × lanes + lane. Every byte of the memory has its own key. |
| Write | Store the byte under its key. |
| Read | Use the stored byte if its key exists. Otherwise use the byte of the start word. A read never adds a key. |
| Reset | Keep every key. |
| allocated() | The number of keys, so the number of different bytes ever written. |
| Step in sample() | What it does |
|---|---|
| Reset edge | Cancel every read in flight, even one due on this edge. A valid response on either port is a RESET error. Accept no request, and stop. |
| 1. Retire | Take every queued read whose due edge is this edge, for both ports. |
| 2. Compare | Check A, then B. Expected but no response is MISSING. A response with nothing expected is EXTRA. Both present with different data is DATA. |
| 3. Write | Apply the accepted writes of this edge to your own memory model, with the lane and priority rules. |
| 4. Queue | Queue each accepted read with due = cycle + its port latency and a value captured now: the OLD or NEW word. |
| Error kind | Value |
|---|---|
| MISSING | 1 |
| EXTRA | 2 |
| DATA | 4 |
| RESET | 8 |
K=<bad>:<first_cycle>:<first_port>:<first_kind>|E=<errors>|N=<accepted>,<retired>,<matched>,<canceled>,<pending>
| Report field | Meaning |
|---|---|
| bad | The OR of every error kind seen so far. |
| first_cycle, first_port, first_kind | The first error. On one edge, A comes before B. Before any error they are ff, ff and 00. |
| errors | The number of errors. Each port has at most one error per edge. |
| accepted | Reads queued so far. |
| retired | Reads that reached their due edge, right or wrong. |
| matched | Retired reads whose response came on time with equal data. |
| canceled | Reads removed by a reset. |
| pending | Reads still queued. accepted = retired + canceled + pending after every edge. |
The tests measure coverage from your traffic on each RAM. Steps 1 to 8 must reach every bin the configuration allows. Bins 2 and 6 need more than one lane, and bin 4 needs more than one word.
| Coverage bit | Hit when |
|---|---|
| 0, 1 | A, or B, has an accepted read. |
| 2 | An accepted write strobes some active lanes but not all. |
| 3 | An accepted write has no active strobe bit. |
| 4 | Both ports write different words on one edge. |
| 5 | Two valid writes to one word share an active lane, even if refused. |
| 6 | Two accepted writes to one word have non-empty masks that do not overlap. |
| 7 | One port reads a word while the other writes it. |
| 8 | An enabled port has an out-of-range address. |
| 9 | A reset arrives while a read is in flight. |
| 10 | One port has accepted reads on two edges in a row. |
| 11 | Every valid address has been read. |
REPLAY=<1 when both runs agree>|OPS=<requests>|STATE=<final state>|DETECTED=<bit f for fault f>|TRAFFIC=<every request>|MATRIX=<one entry per fault>
// one matrix entry: F<f>|C=<coverage>|AR=<addresses read>|<report()>|S=<allocated>|ALLOC=<allocated after each edge>|EVENTS=<edges where errors grew>/
Each RAM run lasts 64 edges, padded with idle edges. Final pending must be 0. The result gives both trace lengths and whether the traces match exactly.
Examples
Example 1
One Byte, One Word- Input
lanes = 1, depth = 1, latencies A = 1 and B = 3, OLD policy, mode 0, seed 1
- Output
trace_length = 5705, expected_length = 5705, trace_matches = yes
The list has 34 requests. Faults 2 and 3 cannot show: there is no other word and no second byte. Every other fault is caught, so DETECTED is 0x7f2. Fault 1, the stuck bit, raises only DATA errors.
Example 2
Full Width at Depth 3- Input
lanes = 4, depth = 3, latencies A = 2 and B = 1, NEW policy, mode 1, seed 0x12345678
- Output
trace_length = 9555, expected_length = 9555, trace_matches = yes
The list has 46 requests and hits all twelve coverage bins, so C is 0xfff. All ten faults are caught, so DETECTED is 0x7fe.
Example 3
Reject Mode Hides the Priority Fault- Input
lanes = 2, depth = 5, latencies A = 3 and B = 2, OLD policy, mode 2, seed 0xffffffff
- Output
trace_length = 9171, expected_length = 9171, trace_matches = yes
In mode 2, writes that share a lane are refused, so reversed priority changes nothing. Fault 4 stays clean, and DETECTED is 0x7ee. The list has 48 requests.
Constraints and Contract
- The nine tests cover 1, 2 and 4 lanes and depths 1, 3 and 5. They use latencies 1 to 3, both policies and all three modes. Each uses a fixed seed.
- Build the same list for the same seed every time. Never look at which fault is running.
- Keep the class names, the ops and state fields, and the method signatures.
Hints
Hint 1
A fault is detected only when the scoreboard reports an error. Ask which kind of error each fault can cause.
Hint 2
A stuck bit or swapped bytes still answer on time, with wrong data. Which error kind catches that? Does the code ever raise it?
Hint 3
Look at the compare step in sample(). When a response is expected and present, it counts a match without comparing the data.
What the grader checks: The campaign runs on eleven real dual-port RAMs, one correct and ten faulty, in nine configurations. An independent model checks the traffic, every report and the detection mask. This shows that these faults are found by this traffic. It does not prove every data pattern or a real SRAM macro.
9 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 7 steps and the final capstone