Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/vsc/model/coverpoint_bin_single_wildcard_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand All @@ -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())

Expand Down
48 changes: 48 additions & 0 deletions ve/unit/test_coverage_cross.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Loading