Can we sample coverpoints which are design parameters?

Hi:

I have a parameterized design, and I want to create a coverage database on the design parameters. My question is: Is it possible to sample covergroups whose coverpoints are static design parameters?

For example:
module dut #(
mode = 1,
type = fast
)
(
);

I have a coverage model with all the parameters defined as coverpoints (in above example coverpoints will be mode and type). Can I sample these ? Is there a way I can refer/reference these design parameters? Or I was thinking of creating an Interface to reference paramters.

Please help me here.

Thanks,
Karma

In reply to Karmapanchal:

You can define parameter as cover point. You can refer to parameter with module instance path. Here are two ways to do this - one to implement the coverage model in the dut, one is to implement the coverage model in test bench.


typedef enum int {fast, slow, med} dutT;

module tb ();
  
  dut #(2, slow) dut1();
  dut #(3, med)  dut2();
  dut #(4, fast) dut3();

  //way 1
  covergroup cg_param with function sample (int mode, dutT dut_type);
    option.per_instance = 1;
    coverpoint mode;
    coverpoint dut_type;
  endgroup

  cg_param cg_param_inst=new;
  
  initial begin
    $display("dut1.mode=%0d, dut1.dut_type=%0s",dut1.mode, dut1.dut_type.name());
    $display("dut2.mode=%0d, dut2.dut_type=%0s",dut2.mode, dut2.dut_type.name());        
    $display("dut3.mode=%0d, dut3.dut_type=%0s",dut3.mode, dut3.dut_type.name());
    
    //way 1  define the covergroup in tb
    cg_param_inst.sample(dut1.mode, dut1.dut_type);
    cg_param_inst.sample(dut2.mode, dut2.dut_type);
    cg_param_inst.sample(dut3.mode, dut3.dut_type);
    
    //way 2 define the covergroup in the dut
    dut1.cg_param_inst.sample();
    dut2.cg_param_inst.sample();
    dut3.cg_param_inst.sample();
  end
    
endmodule

module dut #(parameter int mode = 1, dutT dut_type = fast) ();
   covergroup cg_param;
    option.per_instance = 1;
    coverpoint mode;
    coverpoint dut_type;
   endgroup

   cg_param cg_param_inst=new;
endmodule

Log printed:
dut1.mode=2, dut1.dut_type=slow
dut2.mode=3, dut2.dut_type=med
dut3.mode=4, dut3.dut_type=fast

In reply to Lina.Lin:

Hi Lina:

Thank you for the options. I am planning to implement my covergroup’s in TB. In my case the parameterized design lies down in the hierarchy of design. So, can I bind the sample function hierarchical? For example:

Instead of
//way 1 define the covergroup in tb
cg_param_inst.sample(dut1.mode, dut1.dut_type);

Is it legal to do below ?:
cg_param_inst.sample(dut1.dut_inst1.dut_inst.mode, dut1.dut_inst1.dut_inst.dut_type);

Thanks,
Karma

In reply to Karmapanchal:

it is okay. covergroup cg_param is implemented with overridden sample function which accepts two arguments “mode” and “dut_type”. These two arguments can be passed with any type-compatible variables or parameters down to your design hierarchy.


covergroup cg_param with function sample (int mode, dutT dut_type);
..
endgroup

In reply to Lina.Lin:

Thank You. This helps! :)

In reply to Karmapanchal:

Hi:

Can a string type coverpoint be covered? ? Is it legal?

As some of the parameters in the design are string type and others are int.

So when I override sample function, I can do it as below:

covergroup cg_param with function sample (string mode, string something_else);

Thanks,
Karma

In reply to Karmapanchal:

String type variable can’t be used as cover point.

Variable of type other than integral/real is illegal for specifying as coverpoint/cross expression.

The term integral refers to the data types that can represent a single basic integer data type, packed array, packed structure, packed union, enum variable, or time variable.

In reply to Lina.Lin:

You can sample a string as part of your covergroup, but your coverpoint expression must resolve to an integral value that becomes a bin selection.

covergroup cg with function sample(string s);
      cp: coverpoint s=="one" {
			      bins A = {1};
			      }
	endgroup : cg
   cg gg = new;
   initial begin
      gg.sample("one");
   end

In reply to dave_59:

Hi Dave:

Thanks you for the solution. I have a parameter named channel_mode.
with all the possible values as below:
duplex
rx
tx

My configurable design which contains these parameter passes the value as string. For example:

parameter channel_mode = “duplex”
or
parameter channel_mode = “rx” or “tx”

Now, if I want to develop coverage model for this parameter as a cover point. How should I do it?

Should I do it as below:

covergroup cg with function sample(string channel_mode);
cp: coverpoint channel_mode == “duplex” {
bins duplex = {1};
}

// How should I put the bins for other two values i.e. “tx” and “rx” ?
endgroup

Thanks,
Karma

In reply to Karmapanchal:

You could create a coverpoint for each string value — as you did for “duplex”.

Or, you could convert your string into a fixed sized integral with a maximum size, like

covergroup cg with function sample(bit [8*8:1] channel_mode); // maximum 8 chars
  cp: coverpoint channel_mode {
    bins duplex = {"duplex");
    bins half_duplex = {"rx", "tx");
  }
endgroup

You will need to cast your string parameter to an integral

In reply to dave_59:

Thanks Dave. Agree with the solution.

In reply to Lina.Lin:

Hi Dave & Lina:

Got it. I see the solution. Thanks a ton for the help here ! :)

-Karma

In reply to Karmapanchal:

Hi Dave,

Regarding the same level implementation on string:
The requirement is passing test key string from the command line and wanted to write a covergroup when test is PASSED with that test key.

Could you please suggest.
regards,
nivas.

In reply to nivas:

There are several ways of getting the name of the test string passed in with +UVM_TESTNAME, including uvm_cmdline_proc.get_arg_value(), then you can proceed as above.

Note that you should not have to do this as any tool following the UCIS standard for collecting coverage data has mechanisms for mapping requirements to many different types of coverage metrics. Mapping a requirement to the passing of a test is one of them.

In reply to dave_59:

Hi Thanks for you response.
Actually the requirement is “Set of (Test passed + test_key used) → feature covered bin = 1”

I am doing in the same way as you explaned.

In my coverage_collector component, test_key is getting using this code:
uvm_cmdline_processor cmdline_processor = uvm_cmdline_processor::get_inst();

function void connect_phase(uvm_phase phase);
string data_key;
if (cmdline_processor.get_arg_value(“+TEST=”, data_key) != “”) begin
end
endfunction: connect_phase

And in report phase i am sample when that particular test is passed.
if(srvr.get_severity_count(UVM_FATAL) + srvr.get_severity_count(UVM_ERROR) == 0) begin
test_results_cg.sample(“data_key”);

And covergroup is:
covergroup test_results_cg with function sample(string test_key);
cp_dir_key_p : coverpoint test_key==“data_key” {
bins covered_test_p = {1};
}
endgroup: test_results_cg

So not getting how to pass test_key to covergroup on every test provided. Is this something i am doing wrong for this requirement?, could you please suggest.

waiting for your response.
nivas.