The Unified Approach
Day 12: Constraints. Days 13-15: Coverage measurement. Day 16: Combine them.
Instead of writing explicit tests, declare constraints and let coverage drive which random tests are needed.
Coverage-Driven Test Generation
class Coverage_Driven_Gen;
Monitor mon;
task run_until_covered(real target_cov = 95.0);
int num_tests = 0;
Packet pkt;
while(mon.get_coverage() < target_cov) begin
pkt = new();
if(pkt.randomize() with {
// Bias toward uncovered scenarios
pkt.cmd dist {
READ := 40, // If READ uncovered
WRITE := 40,
SPECIAL := 20
};
}) begin
apply_packet(pkt);
mon.sample();
num_tests++;
if(num_tests % 1000 == 0) begin
$display("Tests: %0d, Coverage: %0.2f%%",
num_tests, mon.get_coverage());
end
end
// Stop if too many tests
if(num_tests > 100000) begin
$display("Coverage closure failed: %0.2f%%",
mon.get_coverage());
break;
end
end
$display("Reached %0.2f%% in %0d tests",
mon.get_coverage(), num_tests);
endtask
endclassFeedback Loop
Workflow:
1. Define constraints + coverage goals
2. Generate random tests
3. Measure coverage
4. Identify gaps
5. Adjust constraints/distributions
6. Repeat until goal achieved
1. Define constraints + coverage goals
2. Generate random tests
3. Measure coverage
4. Identify gaps
5. Adjust constraints/distributions
6. Repeat until goal achieved
Key Takeaways
- ✅ Constraints + coverage = scalable test generation
- ✅ Let automation find the hard scenarios
- ✅ Fewer hand-written tests, better coverage
- ✅ Coverage goals ensure verification completeness
Phase 3 complete! Next: Assertions (Days 17-20).