Skip to content

Override uvm_reg’s sample() hook – it runs before the mirror updates

write-from-scratch / coverage / mirrorUVM · runs take about 2 minutes

This exercise has a walk: One frontdoor write, in time order. It plays step by step beside the code.

uvm_reg::sample() is called from the base class’s do_write()/do_read() once a map has auto- prediction on (set_auto_predict(1), done in the test), and its default body is empty. A register-model generator normally wires it to a covergroup; by hand, nothing is sampled until you override it.

The obvious body asks the field for val.get_mirrored_value(). That’s wrong: sample() gets the access’s own data before do_predict() runs, on every access, so the mirror still holds what the previous access left.

RequirementsOverriding sample(uvm_reg_data_t data, uvm_reg_data_t byte_en, bit is_read, uvm_reg_map map) on cov_reg with whatever state it needs

  1. Every access to this register is recorded.
  2. What’s recorded is the value this access carried, not the field’s mirror.

expected_q holds what each access carries, in order, filled before each access fires. Compare sample()’s value with its front: match_count++ if they agree, mismatch_count++ if not.

Right nowmatch_count=0, want 5. The stub touches neither counter.

Done whenAfter the four writes and one read in the test, match_count is 5 and mismatch_count is 0. Reading the mirror gets every write wrong and the read right only by luck (match_count=1, mismatch_count=4).

Source on GitHub

sample_fires_before_the_mirror_updates.sv