diff --git a/src/vsc/model/coverpoint_bin_single_wildcard_model.py b/src/vsc/model/coverpoint_bin_single_wildcard_model.py index aac47fa..34613f5 100644 --- a/src/vsc/model/coverpoint_bin_single_wildcard_model.py +++ b/src/vsc/model/coverpoint_bin_single_wildcard_model.py @@ -5,6 +5,7 @@ ''' from vsc.model.coverpoint_bin_model_base import CoverpointBinModelBase from vsc.model.wildcard_binspec import WildcardBinspec +from vsc.impl.wildcard_bin_factory import WildcardBinFactory class CoverpointBinSingleWildcardModel(CoverpointBinModelBase): @@ -23,7 +24,13 @@ def get_bin_expr(self, bin_idx): def get_bin_name(self, bin_idx): return self.name - + + def get_bin_range(self, bin_idx): + ranges = [] + for spec in self.wildcard_binspec.specs: + ranges.extend(WildcardBinFactory.valmask2binlist(spec[0], spec[1])) + return tuple(ranges) + def sample(self): val = int(self.cp.get_val()) diff --git a/ve/unit/test_coverage_cross.py b/ve/unit/test_coverage_cross.py index 05d854c..135eac3 100644 --- a/ve/unit/test_coverage_cross.py +++ b/ve/unit/test_coverage_cross.py @@ -213,3 +213,51 @@ def __init__(self): for i in range(3): self.assertEqual(cg.cross_abc_nested.target_l[i], cg.cross_abc_flat.target_l[i]) + + def test_cross_with_wildcard_bins(self): + """Test that a cross containing a coverpoint with wildcard bins can be constructed""" + + @vsc.randobj + class Item(object): + def __init__(self): + self.x = vsc.rand_uint8_t() + self.y = vsc.rand_uint8_t() + + @vsc.covergroup + class Cg(object): + def __init__(self): + self.with_sample(dict(it=Item())) + + self.wildcard_cp = vsc.coverpoint( + self.it.x, + bins={ + "low": vsc.wildcard_bin("0b0???????"), + "high": vsc.wildcard_bin("0b1???????") + } + ) + + self.plain_cp = vsc.coverpoint( + self.it.y, + bins={ + "a": vsc.bin([0, 127]), + "b": vsc.bin([128, 255]) + } + ) + + self.cross = vsc.cross([self.wildcard_cp, self.plain_cp]) + + # Should not raise NotImplementedError + cg = Cg() + + it = Item() + # Sample values to exercise both bins + it.x = 10 # low bin (0b0???????) + it.y = 50 # a bin [0, 127] + cg.sample(it) + + it.x = 200 # high bin (0b1???????) + it.y = 200 # b bin [128, 255] + cg.sample(it) + + # Cross should have 4 bins (2 wildcard x 2 plain) + self.assertEqual(cg.cross.model.get_n_bins(), 4)