Module 1: UVM RAL Mastery | Advanced UVM

Mirror and Desired Values

A practical, step-by-step lesson for building reliable and reusable UVM verification environments.

Learning objectives

  • Distinguish a field's desired value from its mirrored DUT value.
  • Use mirror(), update(), and prediction without hiding divergence.
  • Handle volatile and side-effect fields with an explicit check policy.

Step 1: Understand the concept

The desired value is what the test wants the register to contain. The mirror is what the model believes the DUT contains after prediction. They may differ intentionally between set() and update().

mirror() reads the DUT and compares or updates model state. Volatile and side-effect fields need an explicit policy rather than a blind equality check.

Step 2: Study the example

Read the example from top to bottom. Identify the UVM class or communication point first, then trace the transaction or configuration value through it.

reg_model.ctrl.enable.set(1'b1);
if (reg_model.ctrl.enable.get() != 1'b1)
    `uvm_error("RAL_STATE", "Desired value was not stored")

reg_model.ctrl.update(status, UVM_FRONTDOOR);
reg_model.ctrl.mirror(status, UVM_CHECK, UVM_FRONTDOOR);
if (status != UVM_IS_OK)
    `uvm_error("RAL_STATE", "Mirror check failed")

The first get() checks model intent; mirror() checks synchronization with the DUT. Those are different claims and should produce different diagnostics.

Step 3: Build it in small pieces

  1. Draw the desired, mirrored, and DUT values before each operation.
  2. Test set() without update(), then update and mirror-check.
  3. Mark volatile and side-effect fields with a separate comparison policy.
  4. Preserve the first divergence instead of calling predict() from the test.
Common failure: a matching desired value is mistaken for proof that the DUT was programmed. Require a successful access and a mirror or readback result.

Try it yourself

Acceptance criteria: the test demonstrates a desired/mirror divergence, resolves it through a frontdoor update, detects a forced DUT mismatch with UVM_CHECK, and documents volatile-field handling.

Architecture review for Mirror and Desired Values

Apply the module's working contract to this topic: address, width, reset, access policy, volatility, side effects, byte enables, and the bus path. Identify the component that owns the behavior and the independent observer that can prove it. The implementation is not complete until both sides are named.

Review dimensionQuestion to answerEvidence to keep
OwnershipWhich UVM object creates, configures, and controls this behavior?build/connect/run trace
CorrectnessWhat expected result is compared with the observed result?checker, assertion, or status
FailureWhat is the first useful symptom if the behavior is wrong?context-rich report and transaction
ReuseWhat changes when the interface, test, or configuration changes?portable scenario or documented limitation

Implementation walkthrough

  1. Convert the topic into one requirement with a measurable expected outcome.
  2. Declare the configuration and transaction types at the ownership boundary instead of using hidden globals.
  3. Construct objects in build_phase, connect TLM paths in connect_phase, and perform scenario timing in sequences or run phases.
  4. Attach an independent monitor, checker, coverage collector, or report consumer before adding random stimulus.
  5. Run the smallest positive case, then a boundary and negative case, and preserve the first failure.
function void report_result(string operation,
                            string expected, string actual);
  `uvm_info("EVIDENCE", $sformatf(
    "operation=%s expected=%s actual=%s",
    operation, expected, actual), UVM_LOW)
endfunction

Use structured evidence instead of a vague pass message. A report should tell a reviewer which operation ran, what was expected, what was observed, and where to look next.

Failure-driven exercise

Break one part of the implementation deliberately: remove a TLM connection, change a boundary value, delay an event, or provide an invalid configuration. Predict the symptom before running the test, then compare that prediction with the actual log.

  • Record the test name, seed, configuration, phase, and transaction identity.
  • Identify the first incorrect observation, not only the final cascade of errors.
  • Repair the responsible owner and rerun the same reproducer.
  • Explain what review or assertion would prevent the defect returning.

Architecture review for Mirror and Desired Values

Apply the module's working contract to this topic: address, width, reset, access policy, volatility, side effects, byte enables, and the bus path. Identify the component that owns the behavior and the independent observer that can prove it. The implementation is not complete until both sides are named.

Review dimensionQuestion to answerEvidence to keep
OwnershipWhich UVM object creates, configures, and controls this behavior?build/connect/run trace
CorrectnessWhat expected result is compared with the observed result?checker, assertion, or status
FailureWhat is the first useful symptom if the behavior is wrong?context-rich report and transaction
ReuseWhat changes when the interface, test, or configuration changes?portable scenario or documented limitation

Implementation walkthrough

  1. Convert the topic into one requirement with a measurable expected outcome.
  2. Declare the configuration and transaction types at the ownership boundary instead of using hidden globals.
  3. Construct objects in build_phase, connect TLM paths in connect_phase, and perform scenario timing in sequences or run phases.
  4. Attach an independent monitor, checker, coverage collector, or report consumer before adding random stimulus.
  5. Run the smallest positive case, then a boundary and negative case, and preserve the first failure.
function void report_result(string operation,
                            string expected, string actual);
  `uvm_info("EVIDENCE", $sformatf(
    "operation=%s expected=%s actual=%s",
    operation, expected, actual), UVM_LOW)
endfunction

Use structured evidence instead of a vague pass message. A report should tell a reviewer which operation ran, what was expected, what was observed, and where to look next.

Failure-driven exercise

Break one part of the implementation deliberately: remove a TLM connection, change a boundary value, delay an event, or provide an invalid configuration. Predict the symptom before running the test, then compare that prediction with the actual log.

  • Record the test name, seed, configuration, phase, and transaction identity.
  • Identify the first incorrect observation, not only the final cascade of errors.
  • Repair the responsible owner and rerun the same reproducer.
  • Explain what review or assertion would prevent the defect returning.

Technical deep review: Mirror and Desired Values

Evaluate mirror and desired values using the module contract: address, width, reset, access policy, volatility, side effects, byte enables, and the bus path. Do not stop at whether the API call completes. Identify the state transition, the independent observation, the failure report, and the evidence that another engineer can audit.

DimensionQuestionEvidence
SemanticsWhat does the operation mean before and after execution?state table or transaction trace
OwnershipWhich component is allowed to change or check the state?build/connect/run design
FailureWhat is the first incorrect observation?context-rich report
ReuseWhat can vary without changing the scenario?configuration or extension contract

Technical implementation checklist

  1. State the requirement, preconditions, expected result, and failure policy.
  2. Declare typed configuration and transaction boundaries instead of hidden global state.
  3. Construct objects in build_phase and connect communication in connect_phase.
  4. Attach an independent monitor, checker, assertion, or coverage consumer.
  5. Run nominal, boundary, negative, reset, and repeated cases where applicable.
  6. Preserve seed, phase, transaction ID, expected value, actual value, and first failure.
`uvm_info("EVIDENCE", $sformatf(
  "component=%s phase=%s expected=%s actual=%s",
  get_full_name(), phase_name, expected, actual), UVM_LOW)

Failure-driven lab and review rubric

Introduce one controlled defect in mirror and desired values: remove a connection, change a boundary, delay an event, or alter configuration. Predict the symptom, run the smallest reproducer, and repair the responsible layer.

  • Pass: deterministic positive behavior is checked independently.
  • Pass: a boundary and negative case produce intentional outcomes.
  • Pass: the injected defect is detected with useful context.
  • Pass: the remaining limitation and prevention action are documented.

Learn: Mirror and Desired Values

In this lesson, focus on how to distinguish model intent from the model's belief about DUT state. This matters because the register model must agree with the software-visible specification and with observed bus activity. Start with one requirement and one expected result before adding randomization or additional components.

// Topic: Mirror and Desired Values
// Primary API or artifact: set(), get(), update(), mirror(UVM_CHECK)
// Expected evidence: one observable result tied to the requirement

What to notice: set(), get(), update(), mirror(UVM_CHECK) is the subject of this lesson. It is not enough for the call or artifact to exist; the testbench must observe the resulting transaction, state change, checker result, coverage sample, or review decision.

Expected behavior: the normal case produces the documented result, the boundary case is deliberate, and the failure case identifies the responsible owner instead of hiding the symptom.

Common mistake: treating the topic as an isolated API exercise. Connect it to the UVM lifecycle, an independent observation path, and a diagnostic that preserves the first useful evidence.

Try it: Mirror and Desired Values

  1. Write the requirement, preconditions, expected result, and failure policy.
  2. Implement the smallest example that uses set(), get(), update(), mirror(UVM_CHECK).
  3. Run a nominal case, a boundary case, and a controlled failure.
  4. Record the seed or configuration, transaction identity, expected result, actual result, and first incorrect observation.
  5. show the desired and mirrored values before and after a write.

Check your work: another engineer should be able to understand what was tested, reproduce the result, and identify what remains unverified.

Learn the idea in plain language

Mirror and Desired Values means that you must distinguish model intent from the model's belief about DUT state. In practical verification, this matters because the register model must agree with the software-visible specification and with observed bus activity. Start with a small, deterministic example. Once the example works, add error cases, concurrency, and randomization.

There are three questions to ask before writing UVM code:

  1. What requirement or risk does this topic address?
  2. Which object owns the behavior, and which object observes the result independently?
  3. What exact evidence proves success or exposes the first failure?
Remember: UVM gives you reusable structure, but it does not decide what correct behavior means. The verification plan and the DUT specification define correctness.

Key terms

TermMeaningWhy it matters here
requirementBehavior the design must providedefines what the test must prove
ownerUVM object responsible for a behaviorprevents duplicated or hidden responsibilities
observationIndependent evidence of what happenedprevents stimulus from validating itself
boundaryMinimum, maximum, transition, or exceptional casefinds defects that nominal traffic misses
diagnosticContext preserved when behavior failsreduces debug time in regressions

Use the vocabulary consistently in code reviews. Saying “the test failed” is incomplete. Say which requirement failed, which observation was wrong, which owner produced it, and which evidence should be inspected next.

Example 1: the smallest useful pattern

// Topic: Mirror and Desired Values
// Primary API: set(), get(), update(), mirror(UVM_CHECK)

function void check_result(string expected, string actual);
  if (expected != actual)
    `uvm_error("TOPIC", $sformatf(
      "expected=%s actual=%s", expected, actual))
  else
    `uvm_info("TOPIC", "observable result is correct", UVM_LOW)
endfunction

This small pattern has an owner, an expected result, an actual result, and a report. It is not a complete environment, but it demonstrates the minimum contract that every advanced component should expose.

What each part does

  1. check_result receives data rather than reaching into another component's private state.
  2. expected represents the verification plan or reference model.
  3. actual comes from a monitor, response, assertion, or measured artifact.
  4. uvm_error preserves a failure in the report stream instead of silently returning.
  5. uvm_info records successful evidence at a controlled verbosity.

Expected result: a passing case reports the operation as correct; a failing case names both values and allows the test to be reproduced.

Example 2: connect the pattern to UVM phases

class topic_component extends uvm_component;
  `uvm_component_utils(topic_component)

  topic_config cfg;
  uvm_analysis_imp #(topic_item, topic_component) input_export;

  function void build_phase(uvm_phase phase);
    super.build_phase(phase);
    input_export = new("input_export", this);
    if (!uvm_config_db#(topic_config)::get(this, "", "cfg", cfg))
      `uvm_fatal("CFG", "missing topic configuration")
  endfunction

  function void connect_phase(uvm_phase phase);
    super.connect_phase(phase);
    // Connect the monitor or producer to input_export.
  endfunction

  function void write(topic_item item);
    // Apply the topic rule and publish evidence.
  endfunction
endclass

This example shows where the topic belongs in a real UVM component. Construction and configuration happen in build_phase. TLM connectivity happens in connect_phase. The observed transaction is processed by write().

Do not move all behavior into the test just because the test is easy to edit. Tests choose scenarios; reusable components implement and observe the mechanism.

Step-by-step implementation

  1. Write the requirement in one sentence and identify the failure risk.
  2. List the input type, output type, configuration, and lifecycle phase.
  3. Choose the independent monitor, checker, assertion, coverage collector, or review artifact.
  4. Implement a nominal case with a known expected result.
  5. Add the smallest boundary case that could expose an off-by-one or ordering defect.
  6. Add an invalid or failure case and define whether it should error, reject, ignore, or recover.
  7. Record seed, configuration, component path, transaction ID, expected value, actual value, and first failure.
  8. Only after these checks pass, add random stimulus or broader concurrency.

This order is deliberately conservative. It gives each later test a trustworthy foundation and prevents a large regression from hiding a small wiring mistake.

Decision table

SituationPreferred choiceReason
One reusable protocol behavioragent, driver, monitor, or sequencekeeps protocol mechanics reusable
Several interfaces must coordinatevirtual sequence and typed handleskeeps scenario intent above protocol details
Observed behavior must be comparedscoreboard, predictor, or assertionprovides independent correctness evidence
A test needs controlled variationconfiguration or factory extensionavoids editing shared code
A risk has not occurredtargeted sequence and coverage pointconnects stimulus to a measurable gap

The correct choice depends on lifetime, ownership, timing, and evidence. Familiarity alone is not an architecture decision.

Expected behavior and output

UVM_INFO @ 0: reporter [BUILD] topic configuration accepted
UVM_INFO @ 120ns: env.monitor [OBSERVE] id=7 operation completed
UVM_INFO @ 120ns: env.checker [CHECK] expected=result_7 actual=result_7
UVM_ERROR @ 240ns: env.checker [CHECK] id=8 expected=result_8 actual=result_6

The successful messages establish that construction, observation, and checking occurred. The error identifies an actual mismatch and includes the transaction identity. In a real project, include the address, phase, reset state, configuration, or coverage bin that is specific to the topic.

A report without context creates a second debugging problem. A report with too much low-value data makes the first failure hard to find. Keep high-signal fields at low verbosity and enable detailed traces for a minimized reproducer.

Common mistakes

MistakeWhy it is dangerousBetter approach
Checking the driver requestthe test can pass even when the DUT rejects itcheck the monitor response
Using hidden global statetests influence each other and reuse becomes unclearuse typed configuration and explicit connections
Testing only nominal trafficboundary and recovery defects remain invisibleadd boundary, negative, reset, and repeated cases
Weakening a checker after a failurethe environment becomes falsely greenpreserve the failure and fix its owner
Adding randomization too earlymany failures obscure the first wiring defectprove a deterministic vertical slice first
Claiming coverage from API callsan API call does not prove DUT behaviorsample observable results tied to requirements

Mini quiz

  1. What requirement does Mirror and Desired Values verify?
  2. Which component owns the behavior?
  3. Where does the independent actual result come from?
  4. What boundary case would be most valuable?
  5. What information must appear in the first failure report?

Answer guide: use the specific contract for this lesson, name one UVM owner, identify an observation path, choose a realistic edge condition, and include enough context to reproduce the failure.

Practice exercise

show the desired and mirrored values before and after a write Extend the task with a short design note containing the requirement, assumptions, component owner, positive case, boundary case, negative case, expected evidence, and remaining risk.

  1. Implement the smallest example and run it with a fixed seed or fixed configuration.
  2. Capture the expected and actual result in the report.
  3. Introduce one controlled defect related to mirror and desired values.
  4. Diagnose the first incorrect observation without disabling checks.
  5. Restore the implementation and rerun the same reproducer.

Guided walkthrough: from requirement to evidence

Use this four-pass method for Mirror and Desired Values. First write what must be true. Next identify the UVM owner and interface. Then implement the smallest path that can produce evidence. Finally challenge the path with a boundary and a controlled defect.

  1. Pass 1 - describe: write one requirement, one precondition, and one expected result.
  2. Pass 2 - design: decide whether the owner is a sequence, component, monitor, checker, coverage collector, service, or review artifact.
  3. Pass 3 - implement: use set(), get(), update(), mirror(UVM_CHECK) and connect it through the normal UVM lifecycle.
  4. Pass 4 - prove: capture an observation that demonstrates the register model must agree with the software-visible specification and with observed bus activity.

This method prevents a common advanced-level mistake: writing a large amount of testbench code before deciding what the code must prove.

Guided example: make the boundary visible

class topic_checker extends uvm_component;
  `uvm_component_utils(topic_checker)

  function void check(topic_item actual);
    topic_item expected;
    expected = model.predict(actual);

    if (!actual.compare(expected))
      `uvm_error("TOPIC_CHECK", $sformatf(
        "path=%s id=%0d expected=%s actual=%s",
        get_full_name(), actual.id,
        expected.sprint(), actual.sprint()))
  endfunction
endclass

The checker is deliberately independent from the driver. It receives an actual observation, creates or obtains an expectation, and reports a comparison. Adapt the same boundary to the API in this lesson.

Read the example in order

  1. The component is created by the environment and has a stable name.
  2. The check() method receives observed behavior.
  3. The expectation is produced by a model or reference policy.
  4. The comparison preserves the path and transaction ID.
  5. The failure is actionable without opening every waveform by default.

API checklist

CheckQuestionResult to record
DeclarationIs the type or API strongly typed and created by the correct owner?class path and factory type
ConfigurationAre defaults validated and can the test override them deliberately?resolved configuration print
ConnectionDoes the input arrive from the intended monitor or producer?TLM topology or connection log
TimingIs the operation legal in the current phase and reset state?phase and timestamp
CheckingIs actual behavior compared against an independent expectation?pass/fail report with values
RecoveryWhat happens after timeout, reset, error, or duplicate activity?defined recovery result
ReuseCan another test or interface use this without editing internals?public API and limitation

What should happen in each phase?

Phase or activityExpected workDo not do this
build_phasecreate components, objects, and configurationwait for clock events or drive protocol activity
connect_phaseconnect TLM ports, exports, and analysis pathsstart sequences or depend on DUT responses
end_of_elaborationprint topology and validate required handlessilently accept null sequencers or missing exports
run_phaseexecute timed stimulus and wait for observable completionfinish on sequence completion before checking drain
report_phasesummarize errors, coverage, and residual riskclaim success from a single status bit

The exact phase details vary by topic, but ownership remains stable. Put construction, communication, timing, and reporting in the phase where another engineer would expect to find them.

Troubleshooting playbook

SymptomAsk firstUseful next action
No transaction or resultWas the object created and connected?print topology and resolved configuration
Wrong expected valueIs the reference model independent and current?compare expected state before and after the event
Only boundary failsIs the limit inclusive, exclusive, or transformed?write a directed boundary test and inspect fields
Only random test failsWhich seed and ordering produced the first error?rerun the exact command and reduce stimulus
Test hangsWhich objection, wait, or queue is not completing?add timeout and report outstanding work
High coverage, low confidenceDid the checker prove the covered behavior?trace the bin to a requirement and assertion/check

Debug from the first incorrect observation forward. Later errors are often consequences. Preserve the original seed, configuration, phase, transaction ID, and time before changing the test.

Knowledge check

  1. State the single most important requirement for Mirror and Desired Values.
  2. Name the UVM object that owns its implementation.
  3. Name the independent object or artifact that proves the result.
  4. Choose one boundary case and explain why it is valuable.
  5. Choose one failure injection and predict its first symptom.
  6. List the minimum information needed to reproduce that failure.

Self-check: your answers should identify a specific requirement, one owner, one observation, one realistic edge, one predicted symptom, and enough metadata to repeat the result. Answers such as “test everything” do not define an executable verification plan.

Lesson submission rubric

  • Concept: the learner explains the topic in plain language and uses the correct UVM vocabulary.
  • Implementation: the example is placed in the correct component and phase with explicit configuration and connections.
  • Evidence: a monitor, checker, assertion, coverage result, report, or decision record independently supports the claim.
  • Debug: one controlled failure is reproduced, diagnosed, repaired, and prevented or documented.
  • Quality: assumptions, limitations, and residual risk are written down for the next engineer.

show the desired and mirrored values before and after a write The final artifact should be a small working example plus a short explanation of what it proves and what it does not prove.

Practice: build the smallest working example

Now apply the lesson to one small verification target. The target is to distinguish model intent from the model's belief about DUT state using set(), get(), update(), mirror(UVM_CHECK). Keep the first version deliberately small: one interface, one transaction or state change, one expected result, and one independent observation.

Write these four lines before coding:

Requirement: the DUT must provide the documented behavior.
    Stimulus: one legal operation reaches the DUT.
    Observation: the monitor or checker sees what actually happened.
    Evidence: expected and actual results are compared with context.

Replace the placeholders with the real requirement for this lesson. This habit makes advanced verification work readable to someone who did not write the original test.

Practice: read the code line by line

function void process_observation(topic_item actual);
  string expected;
  string actual_text;

  expected = reference_model.predict(actual);
  actual_text = actual.convert2string();

  `uvm_info("TOPIC", $sformatf(
    "id=%0d expected=%s actual=%s",
    actual.id, expected, actual_text), UVM_LOW)

  if (actual_text != expected)
    `uvm_error("TOPIC", "verification result does not match")
endfunction
  1. The method receives an observation, so it is not coupled to the driver request.
  2. The reference model creates the expectation independently.
  3. The report records the identity and both sides of the comparison.
  4. The error is emitted only after the evidence has been captured.

For the real topic, replace the generic comparison with the appropriate register comparison, protocol rule, coverage sample, performance measurement, or architecture decision. Keep the same discipline: input, rule, observation, evidence.

Practice: positive, boundary, and failure cases

CaseQuestionExpected result
PositiveDoes a valid operation work?checker passes and evidence is recorded
BoundaryWhat happens at the smallest, largest, last, or transition value?documented boundary behavior
FailureWhat happens when the owner, input, timing, or configuration is wrong?intentional error or recovery
ResetWhat state is retained, cleared, or reinitialized?model and DUT agree after reset
RepeatDoes the result remain correct across repeated or concurrent activity?ordering and correlation remain valid

Do not call a case “negative” merely because it fails. A negative test is successful when the environment detects the prohibited behavior and reports it at the correct severity with enough information to debug it.

Practice: debug the first mismatch

When the exercise fails, stop at the first incorrect observation. Use this order:

  1. Confirm the test name, seed, configuration, reset state, and phase.
  2. Compare the stimulus that was intended with the transaction the driver issued.
  3. Compare the driver transaction with the monitor observation.
  4. Check the reference model, predictor, checker, or coverage sampler that consumed the observation.
  5. Only then inspect the DUT response and decide whether the defect is in RTL or the testbench.

Practice: explain your result

Complete this short report after implementing the exercise:

Report itemYour answer
RequirementWhat exact behavior was verified?
OwnerWhich UVM object implements the behavior?
ObservationWhich monitor, checker, assertion, or artifact supplied actual behavior?
Positive evidenceWhat passing result was captured?
Boundary evidenceWhat edge case was exercised?
Failure evidenceWhat controlled defect was detected?
Residual riskWhat remains unverified?

show the desired and mirrored values before and after a write The work is complete only when the code and this report agree about what the test proves.

Key takeaways

  • Desired state expresses intent; mirrored state expresses the model's belief about the DUT.
  • mirror() is a synchronization and checking operation, not a generic read shortcut.
  • Volatile and side-effect fields need explicit comparison policy.