其他分享
首页 > 其他分享> > SystemVerilog(7):覆盖率

SystemVerilog(7):覆盖率

作者:互联网

1、覆盖率类型

1.1 概述

1.2 覆盖率反馈电路

1.3 代码覆盖率

1.4 断言覆盖率

1.5 漏洞率曲线

1.6 功能覆盖率

2、功能覆盖策略

2.1 收集信息而非数据

2.2 只测量需要的内容

2.3 验证的完备性

3、覆盖组

3.1 概述

3.2 covergroup的采样触发

class Transactor;
    Transaction tr;
    mailbox mbx_in;

    covergroup CovPort;       //覆盖组
        coverpoint tr.port;   //采样变量
    endgroup

    function new(mailbox mbx_in);
        covPort = new(); //也可以写成:covPort cg1=new();
        this.mbx_in = mbx_in;
    endfunction

    task main;
        forever begin
            tr =mbx_in.get;
            ifc.cb.port <= tr.port;
            ifc.cb.data <= tr.data;
            CovPort.sample(); //采样
        end
    endtask
endclass

3.3 使用事件触发

event trans_ready;
covergroup CovPort @(trans_ready);
    coverpoint ifc.cb.port;
endgroup

与直接调用 sample( ) 相比,使用事件触发的好处在于你能够借助已有的事件。

4、数据采样

4.1 概述

4.2 coverpoint和bin

4.3 bin的创建和应用

covergroup covPort;
    options.auto_bin_max = 8;    //所有coverpoint auto_bin数量=8
    coverpoint tr.port
    { options.auto_bin_max = 2; }//特定coverpoint auto_bin数量=2
endgroup

4.4 命名coverpoint和bin

covergroup CovKind;
    coverpoint tr.kind {
        bins zero = { 0 };    //1个仓代表kind==0
        bins lo = { [1:3],5 };//1个仓代表1:3和5
        bins hi[] = { [8:$]}; //8个独立的仓代表8:15
        bins misc = default;  //1个仓代表剩余的所有值
    }//没有分号
endgroup

注意coverpoint定义使用{}而不是begin. . .end。大括号的结尾没有带分号,这和end一样。

4.5 条件覆盖率

covergroup coverPort;
    coverpoint port iff //采样时必须保证已经复位了
        (!bus_if.reset);//复位
endgroup

initial begin
    CovPort ck=new();
    #1ns;
    ck.stop();
    bus_if.reset = 1;
    #100ns
    bus_if.reset = 0;
    ck .start();
    ...
end

4.6 翻转覆盖率

covergroup coverPort;
    coverpoint port { //0跳到1,0跳到2,0跳到3
        bins t1 = (0 => 1), (0 => 2), (0 => 3);
endgroup

4.7 wildcard覆盖率

bit [2:0] port;
    covergroup CoverPort;
        coverpoint port {
            wildcard bins even = { 3'b??0 };
            wildcard bins odd  = { 3'b??1 };
        }
endgroup

4.8 忽略的bin

bit [2:0]1ow _ports_0_5; //只使用数值0-5

covergroup coverPort;
    coverpoint low _ports_o_5 {
        ignore_bins hi = { [6,7] }; //忽略数值6-7
    }
endgroup

4.9 非法的bin

bit [2:0] low_ports_0_5; //只是用数值0-5

covergroup coverPort;
    coverpoint low_ports_0_5 {
        illegal_bins hi = { [6,7] }; //如果出现6-7便报错
    }
endgroup

4.10 交叉覆盖率

class Transaction ;
    rand bit [3:0] kind;
    rand bit [2:0] port;
endclass

Transaction tr;

covergroup CovPort;
    kind: coverpoint tr.kind;
    port: coverpoint tr.port;
    cross kind, port;
endgroup

4.11 排除部分cross bin

covergroup covport;
    port: coverpoint tr.port{
        bins port[] = { [O:$] };
    }
    kind: coverpoint tr.kind{
        bins zero = { 0 };
        bins lo = { [1:3] };
        bins hi[] = { [8:$] };
        bins misc = default;
    }
    cross kind, port{
        ignore_bins hi = binsof(port)intersect { 7 };
        ignore_bins md = binsof(port)intersect { 0 } &&
                         binsof(kind) intersect { [ 9:11] };
        ignore_bins lo = binsof(kind.lo);
    }
endgroup

4.12 精细的交叉覆盖率指定

class Transaction;
    rand bit a, b;
endclass

covergroup CrossBinNames;
    a : coverpoint tr.a
    {bins a0 = { 0 };
     bins a1 = { 1 };
     option.weight=0;} //不计算覆盖率
    b: coverpoint tr.b
    {bins b0 = { 0 };
     bins b1 = { 1 };
     option.weight=0;} //不计算覆盖率
    ab: cross a, b
    {bins a0b0 = binsof( a.a0) && binsof ( b.b0 );
     bins a1b0 = binsof( a.a1) && binsof ( b.b0 );
     bins b1 = binsof( b.b1 );}
endgroup
class Transaction;
    rand bit a, b;
endclass

covergroup CrossBinsofintersect;
    a : coverpoint tr.a
    { option.weight=0 ; }//Do not count this coverpoint
    b: coverpoint tr.b
    { option.weight=0; } //Do not count this coverpoint
    ab : cross a, b
    { bins a0b0 = binsof(a) intersect{0} && binsof(b) intersect{0};
      bins alb0 = binsof(a) intersect{1} && binsof(b) intersect{0};
      bins b1 = binsof(b) intersect{1};
    }
endgroup

5、覆盖选项

5.1 单个实例的覆盖率

如果对一个covergroup例化多次,那么默认情况下SV会将所有实例的覆盖率合并到一起。如果需要单独列出每个covergroup实例的覆盖率,需要设置覆盖选项。

covergroup coverLength;
    coverpoint tr.length;
    option.per_instance = 1;
endgroup

5.2 注释

如果有多个covergroup实例,可以通过参数来对每一个实例传入单独的注释。这些注释最终会显示在覆盖率数据的总结报告中。

covergroup CoverPort(int lo ,hi, string comment);
    option.comment = comment;
    option.per_instance = 1;
    coverpoint port{
        bins range = { [lo: hi] };
    }
endgroup
...
coverport cp_lo = new ( 0 ,3, "Low port numbers " );
coverport cp_hi = new ( 4 ,7,"High port numbers " );

5.3 覆盖次数

5.4 覆盖率目标

covergroup coverPort;
    coverpoint port;
    option.goal = 90;
endgroup

5.5 covergroup方法

6、数据分析

 

 

 

参考资料:

[1] 路科验证V2教程

[2] 绿皮书:《SystemVerilog验证 测试平台编写指南》第2版

标签:bin,覆盖率,coverpoint,SystemVerilog,covergroup,port,bins
来源: https://www.cnblogs.com/xianyufpga/p/16488770.html