Skip to content

Commit

Permalink
Correct mis-indexed array in coverage model
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Ballance <matt.ballance@gmail.com>
  • Loading branch information
mballance committed Jul 2, 2020
1 parent 9b268db commit 2f6a5bd
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/vsc/coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,9 @@ def __init__(self, nbins, *args):


if isinstance(nbins,list):
if len(nbins) != 0 and len(nbins) != 1:
if len(nbins) not in (0,1):
raise Exception("Only 0 or 1 argument can be specified to the nbins argument")
self.nbins = -1 if len(nbins) == 0 else nbins[1]
self.nbins = -1 if len(nbins) == 0 else nbins[0]
else:
self.nbins = int(nbins)

Expand All @@ -299,7 +299,7 @@ def build_cov_model(self, parent, name):
else:
ret = CoverpointBinCollectionModel(name)
for r in self.range_l:
if isinstance(r, list):
if isinstance(r, (list,tuple)):
if len(r) != 2:
raise Exception("Expecting range \"" + str(r) + "\" to have two elements")
b = ret.add_bin(CoverpointBinArrayModel(name, r[0], r[1]))
Expand Down
2 changes: 1 addition & 1 deletion src/vsc/model/rangelist_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self, rl : List[List[int]]=None):

if rl is not None:
for r in rl:
if isinstance(r, list):
if isinstance(r, (list,tuple)):
if len(r) == 2:
self.range_l.append([r[0], r[1]])
else:
Expand Down
34 changes: 34 additions & 0 deletions ve/unit/test_coverpoint_bins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'''
Created on Jul 1, 2020
@author: ballance
'''
import vsc
from vsc_test_case import VscTestCase

class TestCoverpointBins(VscTestCase):

def test_bin_array_partition(self):

@vsc.covergroup
class my_cg(object):

def __init__(self):
self.with_sample(dict(
a=vsc.uint8_t()))
self.a_cp = vsc.coverpoint(
self.a, bins=dict(
a1=vsc.bin_array([4], (0,16))
))

cg = my_cg()
cg.sample(0)
cg.sample(3)
print("coverage: " + str(cg.a_cp.get_coverage()))
self.assertEqual(cg.a_cp.get_coverage(), 25)
cg.sample(4)
cg.sample(7)
print("coverage: " + str(cg.a_cp.get_coverage()))
self.assertEqual(cg.a_cp.get_coverage(), 50)


0 comments on commit 2f6a5bd

Please sign in to comment.