System Verilog - Coverage

1, Coverage type

  • Code coverage
  • assertion coverage
  • Functional coverage

2, Function coverage strategy

  • If the function coverage is high but the code coverage is low, it indicates that the verification plan is incomplete and the test does not execute all the designed code.
  • If the code rate is high but the function coverage is low, it means that even if the test platform has executed all the code of the design well, the test still does not locate the design in all the interested States.
  • The goal is to drive high code coverage and function coverage at the same time.

3, Coverage group

1. General

  • Coverage groups are similar to classes. They can be instantiated multiple times after being defined once.
  • covergroup can contain one or more coverpoint s, all of which are collected at the same time.
  • covergroup can be defined in class, interface or module.
  • covergroup can sample any visible variable, such as program variables, interface signals, or design interfaces.
  • When there are multiple independent covergroups, each covergroup can be enabled or disabled as needed.
  • Each covergroup can define a separate trigger sampling event, allowing data to be collected from multiple sources.

Define functional coverage in the class.

class Transaction;
	Transaction tr;
	mailbox mbx_in;
	covergroup CovPort;
		coverpoint tr.point;
	function new(mailbox mbx_in);
		CovPort = new();//Instantiate override group
		this.mbx_in = mbx_in;

	task main;
		forever begin
			tr = mbx_in.get;//Get next transaction
			ifc.cb.port <= tr.port;//Send to the design to be tested <=;
			CovPort.sample();//Collection coverage

2. Trigger of covergroup

  • Sampling trigger of covergroup:
  1. covergroup consists of sampled data and the time when the data is sampled.
  2. When these two conditions are ready, the test platform will trigger covergroup.
  3. This process can be accomplished by directly using the sample() function, or by sampling blocking expressions in covergroup to block events.
  4. If you want to explicitly trigger covergroup sampling in the code, or there is no signal or event at the sampling time, or a covergroup is instantiated into multiple instances and needs to be triggered separately, you can use sample().
  5. If you want to trigger covergroup with existing events or signals, you can use blocking statements in the covergroup declaration.
  • Use event trigger:
event trans_ready;
covergroup CovPort@(trans_ready);
	coverpoint ifc.cb.port;//Measurement coverage

4, Data sampling

1. General

  • When you specify to sample a variable or expression in the coverpoint, SV will create many "bins" to record the number of times each value is captured. These bins are the basic unit of content function coverage.
  • Multiple coverpoints can be defined in the covergroup, and multiple cover bin can be customized in the coverpoint.
  • Each time covergroup samples, SV will leave a mark in one or more cover bin to record the value of the variable and the matched cover bin during sampling.

2.coverpoint and bin

  • In order to calculate the coverage on a coverpoint, we first need to determine the number of possible values, which is also called domain.
  • Coverage is the number of sampled values divided by the number of bins. For example, the domain of a 3-bit variable is 0:7. Normally, 8 bins will be automatically allocated. If seven values are sampled in the simulation process, the coverage of the final coverpoint is 7 / 8.
  • The coverage of all coverpoint s ultimately constitutes the coverage of a covergroup.
  • The coverage of all covergroup s ultimately constitutes the overall functional coverage.

Creation and application of bin:

  1. SV will create a bin for a covergroup by default. You can also define the sampling domain of the bin yourself.
  2. If the domain range of the sampling variable is too large and no bin is specified, the system will allocate 64 bin by default and evenly allocate the value domain range to these 64 bin.
  3. Users can select auto through the option of covergroup_ bin_ Max to specify the maximum number of automatically created bins.
  4. In practice, the method of automatically creating bin is not practical. It is recommended that users define bin by themselves or reduce auto_ bin_ The value of max.
covergroup CovPort;
	options.auto_bin_max = 8;//All coverpoint s, auto_bin_max is 8
	coverpoint tr.port
		{options.auto_bin_max = 2;}//Specific coverpoint, auto_bin_max is 2

Name coverpoint and bin:

covergroup CovPort;
	coverpoint tr.kind{
		bins zero = {0};//1 bin represents kind = 0
		bins lo = {[1:3], 5};//One bin represents the values of 1:3 and 5
		bins hi[] = {[8:$]};//8 independent warehouses: 8 fifteen
		bins misc = default;//One bin represents all the remaining values

Note that the covergroup definition uses {} instead of begin... End, and there is no semicolon at the end of braces.

3. Conditional coverage

  • You can use the keyword iff to add conditions to the coverpoint.
  • This practice is often used to turn off the override during reset to ignore unreasonable condition triggering.
  • You can also use the start and stop functions to control individual instances of covergroup.
covergroup CovPort;
	//Do not collect coverage data when reset == 1
	coverpoint port iff(!bus_if.reset);

initial begin
	CovPort ck = new();//Instantiate override group
	//Stop collecting coverage data during reset
	# 1ns ck.stop();
	bus_if.reset = 1;
	# 100ns bus_if.reset = 0;// Reset end

4. Flip coverage

coverpoint can also be used to record the jump of variables from A value to B value, and can also determine the number of flips of any length.

covergroup CovPort;
	coverpoint port{
		bins t1 = (0 => 1),(0 => 2),(0 => 3);

5.wildcard coverage

You can use the keyword wildcard to create multiple states or flips. In the expression, any x, z or? Will be treated as a wildcard of 0 or 1.

covergroup CovPort;
	coverpoint port{
		wildcard bins even = {3'b?? 0};
		wildcard bins odd = {3'b?? 1};

6. Ignored bin and illegal bin

  • Ignored bin

In some coverpoints, you may never get all the value ranges. For those value ranges that do not calculate functions, you can use ignore_bins is excluded. In the end, they will not be included in the coverage of coverpoint.

bit[2:0]low_ports_0_5;//Use only values 0-5
coverpoint CovPort;
	coverpoint low_ports_0_5{
		ignore_bins hi = {[6:7]};//Ignore the last two bins
  • Illegal bin
    Some sampling values should not only be ignored, but also be reported as errors if they occur. This situation can be monitored in the test platform or illegal can be used_ Bins represents a specific bin.
bit[2:0]low_ports_0_5;//Use only values 0-5
coverpoint CovPort;
	coverpoint low_ports_0_5{
		illegal_bins hi = {[6:7]};//If there is an error, it will be reported

7. Cross coverage

  1. A coverpoint is an observation that records a single variable or expression.
  2. If you want to record the combination of values among multiple variables at a certain time, you need to use cross coverage.
  3. cross statements are only allowed with coverpoint or simple variable names.
class Transacton;
	rand bit[3:0]kind;
	rand bit[2:0]port;

Transaction tr;

covergroup CovPort;
	kind:coverpoint tr.kind;//Create overlay point kind
	port:coverpoint tr.port;//Create overlay point
	cross kind,port;//Cross kind and port
  • Exclude some cross bin
    By using ignore_bins, binsof and intersect specify the value range and coverpoint respectively, which can clear many cross bin s that you don't care about.
covergroup CovPort;
	port:coverpoint tr.port
		{bins port[] = {[0:$]};
	kind:coverpoint tr.kind{
		bins zero = {0};//One bin represents kind == 0
		bins lo = {[1:3]};//A bin represents a value of 1:3
		bins hi[] = {[8:$]};//8 independent warehouses
		bins misc = default;//One bin represents all the remaining values
	cross kind,port{
		ignore_bins hi = binsof(port)intersect{7};
		ignore_bins md = binsof(port)intersect{0}&&
		ignore_bins lo = binsof(kind.lo);

Note that binsof uses parentheses (), while intersect specifies a range, so braces {} are used.

  • Indicates the weight of the cross coverage
covergroup CovPort;
	kind:coverpoint tr.kind
		{bins zero = {0};
		 bins lo = {[1:3]};
		 bins hi[] = {[8:$]};
		 bins misc = default;
		 option.weight = 5;//Share in the total
	port:coverpoint tr.port
		{bins port[] = {[0:$]};
		 option.weight = 0;//It does not account for any component in the whole
	cross kind,port
		{option.weight = 10;}//Give the crossover a higher weight

5, Override options

1. Coverage of a single instance

If a covergroup is instantiated multiple times, SV will merge the coverage of all instances by default. If you need to list the coverage of each covergroup instance separately, you need to set the coverage option.

covergroup CoverLength;
	coverpoint tr.length;
	option.per_instance = 1;

2. Notes

If there are multiple covergroup instances, you can pass in separate comments for each instance through parameters. These comments will eventually appear in the summary report of the coverage data.

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

3. Limit of coverage times

  1. By default, the value sampled once can be included in the valid bin. You can modify at_least to modify the value of each bin and the minimum number of samples if it is lower than at_ The least value will not be included in bin.
  2. option. at_ The least can be declared in the covergroup to affect all the coverpoints, or it can be declared in the coverpoint to affect only all the bin under the coverpoint.

4. Coverage target

The goal of a covergroup or a coverpoint is 100% coverage, or it can be set to less than 100%. This option will only affect the coverage report.

covergroup CovPort;
	coverpoint port;
	option.goal = 90;//Only partial coverage is required

5.covergroup method

  1. sample(): Sample
  2. get_coverage()/ get_inst_coverage(): get the coverage and return the real value of 0-100.
  3. set_inst_name(string): sets the name of the covergroup.
  4. start()/stop(): enable or close the collection of coverage.

Keywords: systemverilog

Added by kev wood on Fri, 25 Feb 2022 06:22:26 +0200