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
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).
One working answer: brokenbench's own fix for this exercise. Try a few runs first.
What changes, against the code you started with:
write() on the register. Everything until the driver takes the item happens at zero simulation time.
UVM RAL Fundamentalsset() stages the value as desired, ‘h005.pre_write callbacks run, fields first. Any of them can cancel the write.
Register Callbacks in Depthreg2bus() builds the APB item.finish_item.item_done and the monitor’s write to the predictor land in the same time step.bus2reg() reads the status off the item; the predictor’s bus2reg() reads the address and data, and finds CTRL at ‘h10.post_write callbacks run, the register’s and then the fields'.
Register Callbacks in Depthwrite() returns to the sequence with UVM_IS_OK.docker run --pull always --rm -p 127.0.0.1:8787:8787 ghcr.io/adibis/brokenbench-runnerLooking for a runner on this computer…
The first start downloads about 250 MB; after that it starts in seconds and only downloads again when there's an update. Your code goes to the runner on your computer, not to chipdv.io.