H2.5 Memory Corruption Campaign

HardFixVerilator · serverReview the topic

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

SignalWidthRole
active_lanes3input of each check
memory_depth3input of each check
latency_a2input of each check
latency_b2input of each check
read_policy1input of each check
write_priority2input of each check
random_seed32input of each check
Full specification
The classes (keep these names and types)
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()
StepRequests
1Read both ends: A reads 0 and B reads depth - 1.
2For each address a: A writes 0x01010101 << a to a with all active strobes. Then A reads a and B reads (a + 1) mod depth.
3For each active lane k: A writes 0xaabbccdd and B writes 0x10203041, both to 0 with strobe 1 << k. Then both read 0.
4A writes 0x89abcdef with strobe 0x5 and B writes 0x76543211 with strobe 0xa, both to 0. Then both read 0.
5A writes 0x55aa55ab to 0 and B writes 0xa55aa55b to depth - 1, all active strobes. Then read both ends.
6A 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.
7A reads 0 while B writes 0xf00dcafe to 0. Then A writes 0x01234567 to 0 while B reads 0. Then three idle edges.
8Read both ends. One reset edge with both ports off. Three idle edges. Read both ends.
9Eight seeded edges, below.
10For 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 edgeRule
Statestate starts at the seed. Each update is state = 1664525 × state + 1013904223, modulo 2^32.
Per edgeThree updates give control, then A data, then B data.
Port Aen = control[0], wr = control[1], address = control[11:8] mod (depth + 1), strobe = control[19:16].
Port Ben = control[4], wr = control[5], address = control[15:12] mod (depth + 1), strobe = control[23:20].
FaultWhat is wrong with the RAM
0Nothing: the correct RAM.
1Bit 0 of every written word is stuck at 0.
2Bit 0 of the word address is ignored.
3Write bytes 0 and 1 trade places, when both exist.
4Shared-lane priority is reversed in modes 0 and 1.
5OLD and NEW are swapped.
6The response data register never updates.
7Every response comes one edge late.
8Reads on port B never respond.
9Reset does not cancel the reads in flight.
10Out-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 modelRule
Keyword_address × lanes + lane. Every byte of the memory has its own key.
WriteStore the byte under its key.
ReadUse the stored byte if its key exists. Otherwise use the byte of the start word. A read never adds a key.
ResetKeep every key.
allocated()The number of keys, so the number of different bytes ever written.
Step in sample()What it does
Reset edgeCancel 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. RetireTake every queued read whose due edge is this edge, for both ports.
2. CompareCheck A, then B. Expected but no response is MISSING. A response with nothing expected is EXTRA. Both present with different data is DATA.
3. WriteApply the accepted writes of this edge to your own memory model, with the lane and priority rules.
4. QueueQueue each accepted read with due = cycle + its port latency and a value captured now: the OLD or NEW word.
Error kindValue
MISSING1
EXTRA2
DATA4
RESET8
report() returns
K=<bad>:<first_cycle>:<first_port>:<first_kind>|E=<errors>|N=<accepted>,<retired>,<matched>,<canceled>,<pending>
Report fieldMeaning
badThe OR of every error kind seen so far.
first_cycle, first_port, first_kindThe first error. On one edge, A comes before B. Before any error they are ff, ff and 00.
errorsThe number of errors. Each port has at most one error per edge.
acceptedReads queued so far.
retiredReads that reached their due edge, right or wrong.
matchedRetired reads whose response came on time with equal data.
canceledReads removed by a reset.
pendingReads 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 bitHit when
0, 1A, or B, has an accepted read.
2An accepted write strobes some active lanes but not all.
3An accepted write has no active strobe bit.
4Both ports write different words on one edge.
5Two valid writes to one word share an active lane, even if refused.
6Two accepted writes to one word have non-empty masks that do not overlap.
7One port reads a word while the other writes it.
8An enabled port has an out-of-range address.
9A reset arrives while a read is in flight.
10One port has accepted reads on two edges in a row.
11Every valid address has been read.
The recorded result
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

Report a problem with this page

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

One Byte, One Word

Input
lanes = 1, depth = 1, latencies A = 1 and B = 3, OLD policy, mode 0, seed 1
Expected 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.

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

Verilator · server