Coding for covergroup with coverpoint and cross

In reply to rgarcia07:

Now to make this covergroup usable for other similar testing,
I would like to make the coverpoints “enable” and “mode” to be passed to the covergroup
and these “enable” and “mode” are actually hierarchy paths to the design.

Could I modify the covergroup and usage to something like this ?

localparam e1 tb.i_chip.enable1;
localparam e2 tb.i_chip.enable2;

localparam mode1[8:0] tb.i_chip.i_reg1.mode[15:7];
localparam mode2[8:0] tb.i_chip.i_reg2.mode[15:7];

covergroup cg @(posedge clk) (ref logic enable, reg logic [8:0] mode );

enable_cp: coverpoint enable { 
  option.weight = 0;
  bins v = {1}; // you only care enable  = 1
}

one_hot_mode_cp: coverpoint mode { 
  option.weight = 0;
  bins one_hot[] = values;
}

cross enable_cp, one_hot_mode_cp;

endgroup

cg m_cg1 = new(e1, mode1);
cg m_cg2 = new(e2, mode2);