这是SystemVerilog的一个示例,用于验证--学习Testbench语言特性指南。在类驱动程序中,如果是drop==0
,事务将丢失。为什么drop = ($urandom_range(0,99) == 0)
可以在其注释中随机删除每100个事务中的1个?我认为这是一个概率为1%的随机下降。
//Test using a callback for error injection
class Driver_cbs_drop extends Driver_cbs;
virtual task pre_tx(ref Transaction tr, ref bit drop);
// Randomly drop 1 out of every 100 transactions
drop = ($urandom_range(0,99) == 0);
endtask
endclass
program automatic test;
Environment env;
initial begin
env = new();
env.gen_cfg();
env.build();
begin // Create error injection callback
Driver_cbs_drop dcd = new();
env.drv.cbs.push_back(dcd); // Put into driverÕs Q
end
env.run();
env.wrap_up();
end
endprogram
//Driver class with callbacks
class Driver;
Driver_cbs cbs[$];
task run();
bit drop;
Transaction tr;
forever begin
drop = 0;
agt2drv.get(tr);
foreach (cbs[i]) cbs[i].pre_tx(tr, drop);
if (!drop) continue;
transmit(tr);
foreach (cbs[i]) cbs[i].post_tx(tr);
end
endtask
endclass
// Base callback class
virtual class Driver_cbs; // Driver callbacks
virtual task pre_tx(ref Transaction tr, ref bit drop);
// By default, callback does nothing
endtask
virtual task post_tx(ref Transaction tr);
// By default, callback does nothing
endtask
endclass
发布于 2022-05-16 01:32:37
$urandom_range是一个概率分布函数,它不是周期性的。要么注释的措辞不精确,要么代码没有正确实现。
https://stackoverflow.com/questions/72255723
复制相似问题