Coverage class - how to best pass in the variable being covered

Hi, Thanks in advance for your insights and recommendations.

Overview:
I have several tests that I’d like to use to collect coverage on. E.g., let’s say I wanted to collect address coverage to a memory that I randomize in the test.
I intended on creating an address_coverage class. However, the ‘address’ attribute is set in my test, not in that class.

Question:
If using a coverage class, is there a preferred way to pass it the attribute that is to be covered? Some thoughts:

  1. I could copy the value to the class attribute before calling .sample(); this works but…
  2. I was hoping I could pass the attribute in my sample command, like …sample(memory_address) but I don’t see anything suggesting it can be done.
  3. Is there a clever way of using a reference link to assign the class’s attribute to my test attribute so I don’t have to manually every time I sample? E.g., in ‘C’ I could change the address of a variable.

Thanks for your suggestions,
Brian

p.s., I’m familiar with using subscribers to do this with TLM style transactions, but not using them here.

covergroup cg_pixel(string name) with function sample(pixel_t item, stage_enum_t stage, color_enum_t color):
   option.per_instance = 1;
   option.name = name;
   ср_с: coverpoint item.pixel__color[stage][color];
   cp_x:coverpoint item.pixel_x[stage] ;
   ср_у: coverpoint item.pixel_y[stage];
   cp_z: coverpoint item.pixel_z[stage];
   cp_t:coverpoint item.pixel_texture[stage];
   cp_f: coverpoint item.pixel_feature|stage];
   cp_v: coverpoint item. pixel _visibility[stage];

   // Simple cross with simple logical ignore_bin
   cx_tfv: cross cp_t, cp_f, cp_v {
   ignore_bins not_visible = cx_tfv with (cp_v = DISABLE || cp_t = TEXNONE || cp_f == OFF);
   }
endgroup // cg pixel

This approach shows cover group “with function sample(…” as a way to pass things to the sample. I this what you were looking for? Please see my example Building Sparse Cross Coverage Bins for arrays of enum'ed datatypes

TomT…