Lab 04: The same testbench in UVM
In this lab you’ll finish our port of the Lab 03 testbench to UVM. We wrote it from our own solution to Lab 03. As shipped, it watches only output 0, as Lab 03’s testbench did, and it misses B06 and B13. You’ll add a second out_agent, so that the testbench watches output 1, and change the scoreboard so that it checks output 1’s beats. Then you’ll write a test that stalls one output at a time, and make the scoreboard track output 1’s level, which the new test needs. After that you’ll write a packet class that goes to a disabled route one time in four, and a factory override that puts it in place of router_pkt without any edit to the sequence that makes the packets. With those pieces in place the testbench catches both bugs. At the end you’ll count the lines in the port and in your Lab 03 testbench, and work out what the extra lines bought you.
Package: labs/lab-04-the-same-testbench-in-uvm/
Before you start
Finish Lab 02 and Lab 03 on the Course path. Keep your Lab 03 files, because Part 5 counts them.
Read The UVM skeleton, Sequences, sequencers and drivers, Monitors, analysis ports and scoreboards and The factory and config_db.
Keep the router’s specification open, or the router in one page. Parts 3 and 4 use the specification’s Routing section, which the one-page version covers under Packets and routing.
Copy this table into your notes and fill it in as you go:
Build time make check-allThe port as shipped (Part 1) After Part 2 After Part 3 After Part 4
Time: about 2 h 30 min. On the course’s 2 CPUs the first build took us 116 s, and the rebuilds after each part’s edits took 30 s and 31 s in Part 2, 105 s and 32 s in Part 3, and 105 s in Part 4.
Part 1: Build the port
Does the port do what the Lab 03 testbench did, and which of this lab’s bugs does it miss?
Go to the lab folder and start the build, because it’s the slowest step in the lab:
cd labs/lab-04-the-same-testbench-in-uvm make buildThe banner says a cold build takes 1.5 to 2.5 minutes on 2 CPUs, and ours took 116 s. It ends with:
- V e r i l a t i o n R e p o r t: Verilator 5.050 2026-07-01 rev v5.050 - Verilator: Built from 48.745 MB sources in 415 modules, into 26.168 MB in 2960 C++ files needing 156.586 MB - Verilator: Walltime 116.774 s (elab=0.822, cvt=3.289, bld=111.863); cpu 5.279 s on 2 threads; allocated 339.555 MBand then a line saying it built
build/simin 116 s, and a ccache line. Our ccache was empty (Hits: 0 / 38). Yours already holds the builds of Labs 01 to 03, so the counts on your ccache line will be higher. Write your build time in your table.While it builds, open the files in
tb/. Apart from the top module,router_tb_top.sv, every piece of the Lab 03 testbench is in one of these four files, and most of its classes are now UVM classes:File What’s in it router_ifs.svthe three interfaces, with a driver’s and a monitor’s clocking block each router_agents_pkg.svthe packet, router_pkt, which is Lab 03’srand_packetwith the same fields and the same constraints (c_dst,c_kind,c_len); an agent for the input, one for the APB port, and one output agent class,out_agent; the sequencesrouter_env_pkg.svthe scoreboard, which is Lab 03’s scoreboard and tracker in one class; the coverage, which is Lab 03’s cg_pktfrom our solution; androuter_env, which builds and connects everythingrouter_tests_pkg.svfill_plan; the base test, with the steps Lab 03’senvhad (write_routes,send_random,check_dropsand the rest) andclose_holes(); and the tests, which arerouter_class_test(Lab 02’s),router_rand_testandrouter_fill_test(Lab 03’s), and the two that this lab adds,router_stall_testandrouter_inject_testYour Lab 02 and Lab 03 testbenches watched only output 0, and so does the port.
router_envmakes only oneout_agent, the scoreboard queues only output 0’s beats, and the scoreboard’slevel()takes output 1’s level as 0, as Lab 03’s tracker did. Find theTODO (Part n)comments. There are four inrouter_env_pkg.svand three inrouter_tests_pkg.sv.Run Lab 02’s test, then the default test, then Lab 03’s test with more packets:
make run UVM_TESTNAME=router_class_test make run make run UVM_TESTNAME=router_rand_test PLUSARGS=+N=400The default is
router_inject_test, which for now does exactly whatrouter_rand_testdoes. You should see, from the first run:UVM_INFO labs/lab-04-the-same-testbench-in-uvm/tb/router_env_pkg.sv(220) @ 7185000: uvm_test_top.env.sb [SB] 100 packets in: 47 to output 0, 53 to output 1, 0 NOROUTE, 0 FULL; the highest level a header saw was 1 UVM_INFO labs/lab-04-the-same-testbench-in-uvm/tb/router_env_pkg.sv(222) @ 7185000: uvm_test_top.env.sb [SB] beats checked: 208 on output 0, 0 on output 1; 1 DROP_CNT reads checked UVM_INFO labs/lab-04-the-same-testbench-in-uvm/tb/router_env_pkg.sv(224) @ 7185000: uvm_test_top.env.sb [SB] 185 beats went to output 1, which nothing watches DD105: TEST PASSEDand from the second, Lab 03’s four phases and its
close_holes():UVM_INFO labs/lab-04-the-same-testbench-in-uvm/tb/router_tests_pkg.sv(273) @ 185000: uvm_test_top [PHASE] 1 of 4: routes 011-, 200 packets; output 0 ready 100%, output 1 ready 100% UVM_INFO labs/lab-04-the-same-testbench-in-uvm/tb/router_env_pkg.sv(196) @ 15295000: uvm_test_top.env.sb [DROP] DROP_CNT 00000000 as expected UVM_INFO labs/lab-04-the-same-testbench-in-uvm/tb/router_tests_pkg.sv(273) @ 15445000: uvm_test_top [PHASE] 2 of 4: routes -110, 200 packets; output 0 ready 100%, output 1 ready 100% UVM_INFO labs/lab-04-the-same-testbench-in-uvm/tb/router_env_pkg.sv(196) @ 29235000: uvm_test_top.env.sb [DROP] DROP_CNT 00000000 as expected UVM_INFO labs/lab-04-the-same-testbench-in-uvm/tb/router_tests_pkg.sv(273) @ 29385000: uvm_test_top [PHASE] 3 of 4: routes 01-0, 200 packets; output 0 ready 100%, output 1 ready 100% UVM_INFO labs/lab-04-the-same-testbench-in-uvm/tb/router_env_pkg.sv(196) @ 43715000: uvm_test_top.env.sb [DROP] DROP_CNT 00000000 as expected UVM_INFO labs/lab-04-the-same-testbench-in-uvm/tb/router_tests_pkg.sv(273) @ 43865000: uvm_test_top [PHASE] 4 of 4: routes 110-, 200 packets; output 0 ready 100%, output 1 ready 100% UVM_INFO labs/lab-04-the-same-testbench-in-uvm/tb/router_env_pkg.sv(196) @ 57015000: uvm_test_top.env.sb [DROP] DROP_CNT 00000000 as expected UVM_INFO labs/lab-04-the-same-testbench-in-uvm/tb/router_tests_pkg.sv(243) @ 57185000: uvm_test_top [HOLES] output 0 stalled and filled to 8 by packets of 3 4 1 beats, then 1 beats for DST 0 and 8 for DST 1 UVM_INFO labs/lab-04-the-same-testbench-in-uvm/tb/router_env_pkg.sv(196) @ 57655000: uvm_test_top.env.sb [DROP] DROP_CNT 00000001 as expected UVM_INFO labs/lab-04-the-same-testbench-in-uvm/tb/router_env_pkg.sv(220) @ 57655000: uvm_test_top.env.sb [SB] 805 packets in: 353 to output 0, 451 to output 1, 1 NOROUTE, 0 FULL; the highest level a header saw was 9 UVM_INFO labs/lab-04-the-same-testbench-in-uvm/tb/router_env_pkg.sv(222) @ 57655000: uvm_test_top.env.sb [SB] beats checked: 1434 on output 0, 0 on output 1; 5 DROP_CNT reads checked UVM_INFO labs/lab-04-the-same-testbench-in-uvm/tb/router_env_pkg.sv(224) @ 57655000: uvm_test_top.env.sb [SB] 1799 beats went to output 1, which nothing watchesending in
ok: 0 UVM_ERROR, 0 UVM_FATAL 1.48 s. The routes are written as in Lab 03, with one character per route:0or1for the output,-for disabled. The[DROP]lines come from Lab 03’sDROP_CNTcheck, which the scoreboard now does. It compares every read ofDROP_CNTwith the drops it predicted, and prints a line when they agree. Thatmake runtook us 1.6 s in all, because nothing was rebuilt.+UVM_TESTNAMEpicks the test when the simulator starts, and the simulator reads the other plusargs then too, so the third run, with+N=400packets in each phase, needed no rebuild either. It sent 1605 packets in 3.03 s.Look at the coverage of the runs you’ve made so far:
make covYou should see
covergroup : 58.5% (24/41), and41 covergroup bins, 24 hit at least once, followed by the 17 empty bins by name. They fall into four groups:- seven that no test can hit, as you found in Lab 03:
full_x_empty,full_x_low,full_x_at_8,out0_x_at_9,out0_x_high,out1_x_at_9andout1_x_high; cp_fate.full,full_x_at_9andfull_x_high: no packet was dropped as FULL;out1_x_lowandout1_x_at_8: the scoreboard takes output 1’s level as 0;cp_level.high,noroute_x_empty,noroute_x_low,noroute_x_at_8andnoroute_x_high: the only NOROUTE drops areclose_holes()’s packets for DST 1, one in each of the last two runs, and they met a level of 9.
Keep the second and third groups in mind for Part 3.
- seven that no test can hit, as you found in Lab 03:
The port should catch what your Lab 02 and Lab 03 testbenches caught. Write down which of B05, B07, B08 and B09 you expect it to catch, then check:
make check-all BUG_LIST="B05 B07 B08 B09"You should see
4 of 4 caught., with 50, 1, 2 and 50UVM_ERRORs.Now check this lab’s two bugs, B06 and B13:
make check-allYou should see:
ok the golden design 0 UVM_ERROR, 0 UVM_FATAL 1.5s ------------------------------------------------------------------------ MISSED tier 2 B06_disabled_route_forwards 0 UVM_ERROR, 0 UVM_FATAL 1.5s MISSED tier 5 B13_admission_checks_other_output 0 UVM_ERROR, 0 UVM_FATAL 1.5s ------------------------------------------------------------------------ 0 of 2 caught. Still hiding from this test: B06_disabled_route_forwards hides behind: never disabling a route B13_admission_checks_other_output hides behind: stalling both outputs together, or never letting one fillfollowed by a note and an error line from
make, because the verdict is a fail. B06 forwards a packet for a disabled route when its output has room. B13 judges whether an output has room from the level of the other output. Why does this test miss each of them?TipAnswerrouter_pkt’sc_dstconstraint sends random packets only to enabled routes. The only packet the test sends to a disabled route isclose_holes()’s packet for DST 1. It arrives when output 0 already holds 9 to 16 beats (9 on this seed: the fill of 3, 4 and 1 beats, then a 1-beat packet for DST 0), so there’s no room, and B06 drops it just as the golden router does.B13 changes a packet’s fate only when one output holds more than 8 beats and the other 8 or fewer. In the random phases both outputs are always ready, so neither holds more than a beat or two (Lab 02’s test reports a highest level of 1). In
close_holes()output 0 fills, but the packet for DST 0 arrives at exactly 8, which B13 admits too because output 1 is empty, and the last packet goes to a disabled route, which is a NOROUTE drop either way. No packet for an enabled route met an output holding more than 8 beats, which is also whycp_fate.fullwas never hit.
Check: 4 of 4 caught. for Lab 02’s and Lab 03’s bugs, and 0 of 2 caught. for this lab’s.
Part 2: Watch the second output
What does it take to watch output 1, when an output agent is a class you can make twice?
Read
out_agent,out_monitorandout_ready_driverinrouter_agents_pkg.sv. Nothing in them says which output they’re on. The monitor and the driver each get their interface ("vif") and their knobs (anout_cfg, withportandready_pct) fromconfig_db. The top module sets the interfaces foruvm_test_top.env.out0*anduvm_test_top.env.out1*, androuter_base_testsets anout_cfgfor each, so output 1’s interface andout_cfgare already set for an agent namedout1.In
router_env, do the two Part 2 TODOs: makeout[1]with the name"out1", and connect its monitor’saptosb.out_export, asout[0]is. Leave the scoreboard alone for now. Before you build, write down what you expectrouter_rand_testto report on the golden router.Rebuild and run:
make build make run UVM_TESTNAME=router_rand_testThe rebuild took us 30 s. The run should fail on the golden router, with 50 errors that start:
UVM_ERROR labs/lab-04-the-same-testbench-in-uvm/tb/router_env_pkg.sv(163) @ 225000: uvm_test_top.env.sb [OUT] output 1: got 80 in cycle 23, and no beat was expected UVM_ERROR labs/lab-04-the-same-testbench-in-uvm/tb/router_env_pkg.sv(163) @ 265000: uvm_test_top.env.sb [OUT] output 1: got 24 in cycle 27, and no beat was expected UVM_ERROR labs/lab-04-the-same-testbench-in-uvm/tb/router_env_pkg.sv(163) @ 275000: uvm_test_top.env.sb [OUT] output 1: got cf in cycle 28, and no beat was expectedand
DD105: TEST FAILED (50 UVM_ERROR, 0 UVM_FATAL). The run stops at 50 because the base test sets UVM’s quit count to 50. What is wrong, the router or the testbench?TipAnswerThe testbench. The new monitor reports every beat on output 1, but
write_instill queues only output 0’s beats (that’s the scoreboard’s Part 2 TODO), so the scoreboard has nothing to compare them with. When a check fires on the golden router, look for the bug in the check first.Do the Part 2 TODO in
router_scoreboard::write_in: queue every forwarded beat onexpected[in_port]. Rebuild (31 s for us) and runrouter_rand_testagain. You should see:UVM_INFO labs/lab-04-the-same-testbench-in-uvm/tb/router_env_pkg.sv(216) @ 57695000: uvm_test_top.env.sb [SB] 805 packets in: 353 to output 0, 451 to output 1, 1 NOROUTE, 0 FULL; the highest level a header saw was 9 UVM_INFO labs/lab-04-the-same-testbench-in-uvm/tb/router_env_pkg.sv(218) @ 57695000: uvm_test_top.env.sb [SB] beats checked: 1434 on output 0, 1799 on output 1; 5 DROP_CNT reads checkedand
ok. The 1799 beats that went unwatched in Part 1 are now checked. The number in parentheses after each file name is a line in that file, so yours can differ by a few lines if your edit kept the TODO comment or added lines.Predict whether
make check-allcatches B06 or B13 now, then run it.TipAnswerNeither.
make check-allsays0 of 2 caught.again. The scoreboard now sees both outputs, but the stimulus hasn’t changed, so the router never gets a packet that either bug would treat differently.
Check: router_rand_test passes with beats checked on both outputs, and make check-all still says 0 of 2 caught.
Part 3: Stall one output at a time
What does B13 need from the stimulus, and does the scoreboard know enough to judge the result?
Read the Routing section of the specification, and
level()andwrite_inin the scoreboard. Then write down the situation in which B13 does something different from the golden router, given that it judges an output’s room from the other output’s level.TipAnswerWhen a header arrives, one output has to hold more than 8 beats and the other 8 or fewer. A packet for the output with room is then dropped as FULL, because B13 looks at the full one, and a packet for the full output is admitted, because B13 looks at the one with room.
Do the Part 3 TODO in
router_tests_pkg.sv: inrouter_stall_test, overrideset_sinks(k)so that in phasekone output is ready in 5% of cycles and the other in 100%, output 0 stalling in phases 1 and 3 and output 1 in phases 2 and 4.router_rand_testcallsset_sinks(k)at the start of each phase, withkfrom 1 to 4. Setocfg[p].ready_pct. The test made thoseout_cfgobjects and kept the handles, and eachout_ready_driverreads itsready_pctagain every cycle, so a change takes effect at the next clock edge.ready_pctis Lab 03’ssink.stallgrown into a percentage, where 0 is a stall and 100 is a sink that is always ready.Rebuild with
make build. It took us 105 s, against 30 s and 31 s in Part 2, because the Part 2 edits were inside existing function bodies and this one adds a function to a class. That changes most of the C++ that Verilator generates, as adding members to a class did in Lab 01, Part 5. Before you run it, look atlevel()again. Phase 2 stalls output 1. What will the scoreboard predict for the packets routed there?Run the stall test on the golden router:
make run UVM_TESTNAME=router_stall_testYou should see phase 1 end with its
DROP_CNTcheck, and phase 2 fail:UVM_INFO labs/lab-04-the-same-testbench-in-uvm/tb/router_env_pkg.sv(192) @ 15395000: uvm_test_top.env.sb [DROP] DROP_CNT 00002500 as expected UVM_INFO labs/lab-04-the-same-testbench-in-uvm/tb/router_tests_pkg.sv(273) @ 15545000: uvm_test_top [PHASE] 2 of 4: routes -110, 200 packets; output 0 ready 100%, output 1 ready 5% UVM_ERROR labs/lab-04-the-same-testbench-in-uvm/tb/router_env_pkg.sv(165) @ 19275000: uvm_test_top.env.sb [OUT] output 1: got a1 in cycle 1928, expected 4d UVM_ERROR labs/lab-04-the-same-testbench-in-uvm/tb/router_env_pkg.sv(165) @ 19325000: uvm_test_top.env.sb [OUT] output 1: got 94 in cycle 1933, expected dbFULL_CNTis bits 15:8 ofDROP_CNT, so phase 1 dropped 0x25, or 37, packets as FULL, and the scoreboard predicted every one of them. The grader can’t use this test yet, because it fails on the golden router.make check BUG=B13 UVM_TESTNAME=router_stall_teststops after the golden run:FAIL the golden design 50 UVM_ERROR 0.8s UVM_ERROR [OUT] output 1: got a1 in cycle 1928, expected 4d UVM_ERROR [OUT] output 1: got 94 in cycle 1933, expected db UVM_ERROR [OUT] output 1: got 68 last in cycle 1936, expected 25 ------------------------------------------------------------------------ VERDICT: FAIL -- your test does not pass the GOLDEN design.TipAnswerlevel()returns 0 for output 1, a shortcut that was safe while output 1 was always ready, as it was in every test before this one. With output 1 ready in only 5% of cycles it fills past 8, and the router drops its next packets as FULL, as the specification says, but the scoreboard still expected them. The packet starting4d(DST1, routed to output 1 by-110) was dropped, so the next header to come out of output 1,a1(DST2, also routed to output 1), was compared with4d. Output 0’s level was right all along, which is why phase 1 passed.Do the Part 3 TODO in
level(), so it gives output 1’s level the way it gives output 0’s. Rebuild (32 s for us) and run the stall test again. You should see:UVM_INFO labs/lab-04-the-same-testbench-in-uvm/tb/router_env_pkg.sv(209) @ 58095000: uvm_test_top.env.sb [SB] 805 packets in: 190 to output 0, 241 to output 1, 1 NOROUTE, 373 FULL; the highest level a header saw was 16 UVM_INFO labs/lab-04-the-same-testbench-in-uvm/tb/router_env_pkg.sv(211) @ 58095000: uvm_test_top.env.sb [SB] beats checked: 753 on output 0, 988 on output 1; 5 DROP_CNT reads checkedand
ok, with 373 FULL drops where the random test had none. The four phases’DROP_CNTreads were00002500,00007700,00007e00and00005b00, which are 37, 119, 126 and 91 FULL drops, and the scoreboard predicted each one.Ask for the verdict on B13:
make check BUG=B13 UVM_TESTNAME=router_stall_testYou should see:
ok the golden design 0 UVM_ERROR, 0 UVM_FATAL 1.5s caught B13_admission_checks_other_output 50 UVM_ERROR 0.1s UVM_ERROR [OUT] output 0: got e5 in cycle 142, expected 3f UVM_ERROR [OUT] output 0: got 90 in cycle 172, expected 73 UVM_ERROR [OUT] output 0: got 28 in cycle 195, expected f6 ------------------------------------------------------------------------ VERDICT: PASSPhase 1 stalls output 0 and routes
DST1 and 2 to output 1 (011-). The first error is on output 0 in cycle 142, wheree5came out and the scoreboard expected3f. Which of B13’s two wrong decisions from step 1 puts a wrong beat on output 0?TipAnswerB13 admits a packet for output 0 while output 0 holds more than 8 beats, because it judges output 0’s room from output 1, which is nearly empty. In the waves of this run, the header
0d(DST0) arrived in cycle 114, when output 0 held 15 beats and output 1 none. The golden router dropped it as FULL. B13 admitted it and wrote its six beats into a buffer that holds 16 and already held 15, so they overran the buffer and wrote over beats that were still waiting in it.e5is the second beat of that packet.B13 had made the other wrong decision first. From cycle 100 on it dropped packets for output 1 as FULL (the first was
8a,DST2), because output 0 was above 8. Those packets never came out, and output 1 sent nothing else before cycle 142, so the first beat to disagree with the scoreboard was on output 0.
Check: router_stall_test passes on the golden router with 373 FULL drops, and make check BUG=B13 UVM_TESTNAME=router_stall_test prints VERDICT: PASS.
Part 4: A factory override for disabled routes
How do you make a test send some packets to disabled routes, without editing the sequence that makes them or the driver that sends them?
Read
router_rand_seqinrouter_agents_pkg.sv. It makes each packet withrouter_pkt::type_id::create("pkt"), which asks the factory for arouter_pkt. If a test has told the factory to substitute a subclass ofrouter_pkt, the sequence gets the subclass without knowing it. Then readrouter_pkt’sc_dstconstraint, which is Lab 03’s.Do the first Part 4 TODO: write
router_noroute_pkt, which extendsrouter_pktand sends one packet in four to a disabled route. Give it its own constraint namedc_dst. A constraint with the same name as one in the parent class replaces the parent’s, and Verilator 5.050 does that as the standard says. Decide which packets go to a disabled route with a non-random bit thatpre_randomize()sets with$urandom_range, not with adist. On this simulator adistdraws its value first, andrandomize()fails when another constraint rules that value out (Lab 03, Part 3, line 3 of the experiments, and Constrained random on Verilator). Every routing table thatrandom_routes()writes has at least one disabled route, so the constraint can always be met.Do the second Part 4 TODO: in
router_inject_test, add abuild_phasethat callsrouter_pkt::type_id::set_type_override(router_noroute_pkt::get_type())and thensuper.build_phase(phase). Nothing else in the test changes, so it’s still the stall test, with different packets.The override reaches every packet the factory makes, wherever it’s made.
close_holes()picks theDSTof its two random packets itself, and switchesc_dstoff for the one it sends toDST1, so it needs both to be plainrouter_pkts. It makes them withnew(), innew_packet(), where the override can’t reach them. When we made them through the factory instead,router_inject_testfailed on 4 of 5 seeds withUVM_FATAL [RAND]. The packet forDST1 was then arouter_noroute_pkt, and whenclose_holes()switchedc_dstoff through arouter_pkthandle, the subclass’sc_dststayed on.Write down what you expect the golden run’s
[SB]line to say about NOROUTE drops. Then rebuild (105 s for us) and run the default test:make build make runWith the reference solution you should see:
UVM_INFO labs/lab-04-the-same-testbench-in-uvm/tb/router_env_pkg.sv(209) @ 61465000: uvm_test_top.env.sb [SB] 805 packets in: 144 to output 0, 190 to output 1, 194 NOROUTE, 277 FULL; the highest level a header saw was 16 UVM_INFO labs/lab-04-the-same-testbench-in-uvm/tb/router_env_pkg.sv(211) @ 61465000: uvm_test_top.env.sb [SB] beats checked: 648 on output 0, 799 on output 1; 5 DROP_CNT reads checkedand
ok. You didn’t have to change the scoreboard for this. It was written from the specification’s Routing table, so it already predicts a NOROUTE drop for a packet to a disabled route; until now, no test had sent one while its output had room. Which packets go to disabled routes depends on how yourpre_randomize()draws its bit. A version of ours that wrote the constraint differently but drew the bit the same way gave the same counts, so if yours differ, compare your draw with the reference solution’s once step 5 says2 of 2 caught.Ask for the lab’s verdict:
make check-allYou should see:
ok the golden design 0 UVM_ERROR, 0 UVM_FATAL 1.6s ------------------------------------------------------------------------ caught tier 2 B06_disabled_route_forwards 50 UVM_ERROR 0.4s caught tier 5 B13_admission_checks_other_output 50 UVM_ERROR 0.1s ------------------------------------------------------------------------ 2 of 2 caught.You can also apply a factory override from the command line, without a test class. Apply yours to Lab 03’s test that way, on the golden router and then on B06, and time the first run:
time make run UVM_TESTNAME=router_rand_test PLUSARGS=+uvm_set_type_override=router_pkt,router_noroute_pkt make run UVM_TESTNAME=router_rand_test PLUSARGS=+uvm_set_type_override=router_pkt,router_noroute_pkt BUG=B06The first prints
[UVM_CMDLINE_PROC] Applying type override from the command line: +uvm_set_type_override=router_pkt,router_noroute_pkt, then194 NOROUTE, 0 FULLandok, in 1.70 s with no rebuild. The second fails, and its first error is:UVM_ERROR labs/lab-04-the-same-testbench-in-uvm/tb/router_env_pkg.sv(152) @ 705000: uvm_test_top.env.sb [OUT] output 0: got c6 in cycle 71, and no beat was expectedWithout the plusarg, the same test on B06 says
MISSED.Record both runs from step 6 and look at the first packet that B06 forwards:
make waves UVM_TESTNAME=router_rand_test PLUSARGS=+uvm_set_type_override=router_pkt,router_noroute_pkt make waves UVM_TESTNAME=router_rand_test PLUSARGS=+uvm_set_type_override=router_pkt,router_noroute_pkt BUG=B06 surfer build/runs/router_rand_test-s1/waves.fst & surfer build/runs/router_rand_test-s1-B06/waves.fst &Add
valid,ready,dataandlastfromin_sandout0, androute_en_q,status_qandcnt_noroute_qfromdut.u_regs, and look at 650 to 850 ns:The golden router. The header
c6(DST3) is accepted at the edge at 685 ns, whileroute_en_qis7(routes 0, 1 and 2 enabled).STATUS.NOROUTEandNOROUTE_CNTchange at that edge, andout0_validstays low.B06. The router counts the same NOROUTE drop, and then puts
c6 c8 8d e6 da 32 3fon output 0, starting in the cycle that ends at 705 ns. That’s two cycles after the header’s cycle, which is when rule O8 says a forwarded beat first appears on the output.Both pictures have the same input and the same register values, because the seed is the same and this is the first packet for a disabled route in the run, so B06 has changed nothing before it.
Run every test on five seeds and read the coverage:
make regress SEEDS="1 2 3 4 5"You should see
25 ok (25 runs)andcovergroup : 82.9% (34/41). The stall test’s FULL drops hit the three bins of Part 1’s second group:cp_fate.full,full_x_at_9andfull_x_high. The two bins of the third group,out1_x_lowandout1_x_at_8, are hit becauselevel()now gives output 1’s real level. The five bins of the fourth group are hit too, now thatrouter_inject_testsends packets to disabled routes while one output is stalled. The seven bins left empty are the seven that no test can hit, so this is as far as the percentage goes. Read the coverage thatmake regressprints, notmake cov’s.make regressreports only its own runs, whilemake covmerges every run inbuild/runs, and the runs you made before an edit moved the covergroup’s lines show each bin a second time.
Check: 2 of 2 caught. from make check-all, and cp_fate.full hit.
Part 5: Count what the port cost
Where did the lines go, compared with your Lab 03 testbench, and what did they buy you?
Count both testbenches.
FILEStakes the paths of your Lab 03 files, which are in Lab 03’stb/with the covergroup, the constraints and theclose_holes()you wrote:make loc FILES="../lab-03-constraints-and-coverage/tb/*.sv ../lab-03-constraints-and-coverage/tb/*.svh"With the reference solution’s edits, the UVM part prints:
This lab's UVM testbench: file lines code tb/router_ifs.sv 85 54 tb/router_agents_pkg.sv 495 359 tb/router_env_pkg.sv 305 214 tb/router_tests_pkg.sv 396 266 tb/router_tb_top.sv 64 49 total 1345 942As shipped it was 1330 lines and 921 code lines, so the reference solution’s edits added 21 code lines. With our Lab 03 solution in Lab 03’s
tb/, theFILES:part totals 1206 lines and 789 code lines. Write your two totals, for this lab’s testbench and for your Lab 03 testbench, in your notes.For each piece of your Lab 03 testbench, find the UVM piece that does its job, and write down whether its code moved across nearly unchanged or changed shape. Then list the UVM pieces that have no Lab 03 counterpart at all.
TipAnswerLab 03 Lab 04 What happened packetandrand_packetrouter_pktmoved: the fields and the constraints c_dst,c_kindandc_lenare the same; it gained`uvm_object_utilsand is made through the factorygeneratorand the mailbox to the driverrouter_rand_seqon the input agent’s sequencerchanged shape: start_item/finish_iteminstead of a mailboxputdriversrc_drivermoved: get_next_item/item_donereplace the mailboxget, and the idle gaps and the clocking-block drives are the samesinkand itsstallknobout_ready_driverandout_cfg.ready_pctmoved: the stall grew into a percentage, which the driver reads every cycle monitorand the mailboxes to the scoreboardsrc_monitor,out_monitorand their analysis portschanged shape: each beat goes to ap.write()as it moves, instead of a whole packet into a mailboxscoreboardandtracker, each with its ownrun()loopwrite_in,write_out,write_apb,level()changed shape: one class, which the monitors call, with no thread; it predicts FULL drops as well, from the tracker’s levels router_coverageandcg_pktrouter_coverageas a subscribermoved: the same covergroup, sampled from the scoreboard’s fate_apapb_masterwithwrite()andread()apb_agent,apb_rw_seq,write_reg,read_reggrew: a driver, a monitor and a sequence, and the monitor reports every transfer to the scoreboard envand its steps (write_routes,send_random,check_drops, …)router_env, and the steps as tasks ofrouter_base_testchanged shape: build_phaseandconnect_phaseinstead of a constructor that makes the mailboxesfill_planandclose_holes()the same, in router_tests_pkg.svmoved: the same steps in the same order, now sent through the agents’ sequences router_cfgand its plusargsplusargs read in the tests moved, except +SHOW, which is gone$errorandn_errors`uvm_errorchanged: UVM counts the errors and stops the run at 50 router_base_testand its three testsrouter_base_testand five testsmoved: the three tests’ body()s call the same steps, and two tests are new;+UVM_TESTNAMEpicks one at run time, as it did in Lab 03nothing the agent classes, out_cfgandconfig_db, the factory registration linesnew The code that touches the router (the drives, the sampling, the prediction) does the same work in both testbenches. UVM changed how the pieces find each other and pass data between them: through
config_dband the factory instead of the environment’s constructor, and through sequencers and analysis ports instead of mailboxes.Using Parts 2 to 4, what did the extra lines buy you in this lab?
TipAnswerWatching output 1 took two lines in
router_envand one in the scoreboard, which Lab 03 had written for output 0 alone. Two lines were enough inrouter_envbecause the output agent’s driver and monitor get fromconfig_dbeverything that differs between the two outputs. Stalling one output took a short function in a new test, which you pick at run time, and it works because the test holds theout_cfghandles that the drivers read. The factory override changed every packet that the sequence made, in every phase, without an edit to the sequence or the driver. You could apply it from a test class, or from the command line, where it took 1.70 s with no rebuild; any edit to the testbench cost 30 to 105 s of rebuilding. Lab 03’s testbench could have done each of these, but each would have meant editing the classes that already worked.
Check: your notes have a line count for both testbenches, and your table has a build time and a make check-all result for each part.
Finishing
You’re done when make check-all prints 2 of 2 caught. with the router_stall_test, router_noroute_pkt and router_inject_test you wrote.
Questions:
The first B13 error came in phase 1, where output 1 is always ready and the old
level()shortcut gave the right answer. Why did you still have to fixlevel()beforemake checkwould give a verdict on B13?TipAnswermake checkruns the golden router first and stops if your test fails it (Part 3, step 4), because a test that fails on a correct design tells you nothing about a broken one. The shortcut predicted the wrong fate for output 1’s packets in phases 2 and 4, where output 1 stalls, so the scoreboard reported errors on the golden router.In Part 4, step 7, why does the B06 run’s
NOROUTE_CNTagree with the golden run’s?TipAnswerB06 changes only whether the packet is written to its output, and the router still counts it as a NOROUTE drop. So at this point the counters agree, and the bug shows as beats on an output that should have stayed idle, which the scoreboard checks.
Submit: nothing for this lab.
Next on the Course path: the reading on assertions, reactive agents and virtual sequences, then Lab 05: Protocol rules and backpressure.

