At SoC level, the same register can legitimately be programmed two different ways: a C test running on the CPU can write it directly, or an SV virtual sequence can write it through the register model. Both are real options, both compile, and both can pass a review - but picking the wrong one for what the scenario is actually trying to prove, or forgetting that the register model doesn't automatically know what the C test just did, is one of the more common sources of a confusing false failure at this level.
10 min read | Intermediate Level
What You'll Learn
- What decides whether a scenario should have the C test or an SV sequence program a given register
- Why a register the C test writes can leave the SV environment's register model holding a stale value
- The concrete ways a stale mirror causes a test to fail, or pass, for the wrong reason
- How to keep C-driven and SV-driven register access from quietly stepping on each other in the same test
Two Legitimate Ways to Program the Same Register
A C test only ever reaches a register the way real firmware would - a load or store instruction over the actual bus. An SV virtual sequence has a choice: it can drive the same kind of bus transaction through the register model's frontdoor, or it can reach past the bus entirely and deposit the value straight into the DUT's storage through a backdoor path.
Neither option is more "correct" in the abstract - which one belongs in a given test depends entirely on what that test is trying to prove, and who would realistically be setting that register in the system this chip ships in.
A frontdoor write needs an active sequencer driving a real bus port, but most bus agents at SoC level are passive - the CPU and DMA already have real RTL masters driving those ports, and an SV sequence can't add a second driver to the same one. The register model's frontdoor adapter and sequencer are bound instead to whichever port is deliberately kept active for this purpose: commonly a debug or test-access port - a JTAG-based bridge or a dedicated verification master on the interconnect - that exists precisely so software-independent register access has somewhere legal to go.
When the C Test Should Own It
Any scenario built around proving that real software, driving real hardware, produces the right result needs the C test to be the one doing the driving. That covers more ground than it first sounds like: bring-up and boot-sequence style configuration, a peripheral's driver-accurate register-programming order, or any test whose actual point is whether firmware's access pattern - not just the final register value - produces correct DUT behavior.
If an SV sequence pre-programmed that same register instead, the test would no longer be checking what it claims to check; it would be checking whether the hardware behaves correctly when configured by the testbench, not by software.
When the SV Sequence Should Own It
Plenty of register-level testing has nothing to do with software at all, and forcing a C test into that role adds extra setup work without proving anything new. Reserved-bit behavior, reset-value checks, illegal or out-of-range field values no real driver would ever write, and error-injection scenarios that no legitimate firmware path could produce, are all naturally SV-sequence territory - an SV sequence can drive exactly the value a test needs, including values a C test physically couldn't construct through a driver that was written to behave correctly.
The same is true for fast setup that isn't itself the point of the test: reaching a starting configuration quickly, so the scenario under test can begin from there, is a job for the register model, not for spending C-test execution time walking through it.
Early in a block's SoC integration, before its driver exists or before it's trustworthy enough to build a test around, an SV sequence programming its registers directly is often the only way to test the hardware at all. That's a legitimate reason on its own, independent of whatever the test is checking.
The Stale Mirror Problem
The register model's mirror - its own record of what it believes each register currently holds - only updates when the model itself initiates the access, or when a predictor is connected and watching the bus that access travelled over.
A C test's write goes straight to the DUT over the real bus, entirely outside the register model's own write() call. If nothing is watching that bus on the register model's behalf, the mirror simply doesn't know the write happened - it still shows whatever value was there before.
That gap causes real, specific failures, not just an abstract inconsistency:
- An SV sequence's read-modify-write silently reverts the C test's configuration. A sequence that changes one field of a register by reading the mirror, calling
set()on the field, and writing the whole register back, reconstructs the other fields from whatever the mirror currently believes - which, if it's stale, is not what the C test actually programmed. The write that goes out clobbers bits the C test set moments earlier, and the DUT ends up in a state neither side intended. - A checker built around
get_mirrored_value()reports the wrong verdict. A checker that trusts the mirror as a stand-in for the DUT's real state, without confirming a predictor is actually watching every path that can write that register, can report a mismatch that isn't real - or worse, miss a real one, because it never saw the value the C test put there. - Coverage sampled from the mirror never sees what software actually programmed. A covergroup wired to sample on the register model's own write or predict callback records what the SV side wrote or observed - if the C test's write never reached the model, the exact values software is most likely to configure in practice are the ones the coverage model is least likely to have ever seen.
Keeping the Mirror Honest
The fix is the same one the register model needs for any bus master outside the SV sequence's control: a predictor connected to a passive monitor on the interface the C test's writes actually travel over, translating each observed transaction into a mirror update automatically.
Where a predictor genuinely isn't practical for a given interface, an explicit backdoor peek() immediately before the SV side needs to trust the mirror re-synchronizes it for that one check, without committing the whole environment to watching that bus continuously.
The simplest fix is often ownership discipline rather than more plumbing: if a specific register only ever needs one side to touch it within a given test, the staleness problem doesn't come up at all. Reserving genuinely shared registers - the ones both a C test and an SV sequence might reasonably write within the same scenario - for the cases in the earlier sections that actually call for it keeps the rest of the environment simple.
Common Mistakes
Mistake: Letting an SV sequence read-modify-write a register the C test also programs, without checking the mirror is current.
A read-modify-write is only as correct as the value it started from. If there's any chance the C test touched that register more recently than the register model's mirror was last updated, the sequence needs to confirm the mirror is current - or read the field backdoor immediately beforehand - before building a new value on top of it.
Mistake: Trusting get_mirrored_value() in a checker without confirming a predictor actually covers every writer of that register.
A predictor wired to one bus agent doesn't help a register that a different bus master, on a different interface, can also write. A checker that assumes the mirror is authoritative needs that assumption verified against every path capable of writing the register it's checking, not just the path the checker's author had in mind.
Mistake: Splitting ownership of the same register between the C test and an SV sequence within one test, without a specific reason tied to what the test proves.
Sharing a register between both sides adds exactly the staleness risk described above, for no benefit, when a test could just as easily give one side sole ownership of it. Shared ownership is worth the complexity only when the scenario itself is specifically about the interaction between software's access and the SV environment's - not as a default.
Summary
In this article, you learned:
- A C test should own programming a register whenever the test is checking real software's access pattern, not just the resulting value; an SV sequence should own it for reserved-bit, reset-value, illegal-value, and fast-setup cases no legitimate driver would produce
- A C test's write reaches the DUT entirely outside the register model's own
write()call, so the mirror only reflects it if a predictor is watching that bus, or the mirror is explicitly refreshed - A stale mirror causes concrete failures - a read-modify-write that reverts software's configuration, a checker that trusts a value the model never actually observed, and coverage that never sees what software really programmed
- A predictor on the right interface, an explicit backdoor refresh where a predictor isn't practical, or simply giving one side sole ownership of a register within a test, all close the same gap