fvutils / pyvsc

Python packages providing a library for Verification Stimulus and Coverage
https://fvutils.github.io/pyvsc
Apache License 2.0
113 stars 26 forks source link

Incorrect covergroup percentage #101

Closed shrujal20 closed 3 years ago

shrujal20 commented 3 years ago

Hi @mballance , I am trying one example related to coverage, but it seems that sometimes it is showing incorrect covergroup percentage. following is the code:

import vsc
from vsc import *

@vsc.randobj
class parent(object):
    def __init__(self):
        self.a = vsc.rand_bit_t(2)
        #self.b = vsc.rand_bit_t(8)

@vsc.covergroup
class my_covergroup(object):

    def __init__(self):
        self.with_sample(dict(it=parent()))
        self.cp1 = vsc.coverpoint(self.it.a, bins=dict(
            a_bin = bin(1,2,3)))
        self.c = vsc.coverpoint(self.it.a, bins=dict(
            a_bin1 = bin_array([], [0,3])))
        self.cp2 = vsc.coverpoint(self.it.a, bins=dict(
            b_bin = bin(2,3)))

pr = parent()
cover = my_covergroup()
for i in range(5):
    pr.randomize()
    print("a = ", pr.a)
    cover.sample(pr)
print("coverage: ", cover.get_coverage())

For this it is giving an output like following: image

As we can see here, coverage percentage of cp2 is showing 100% but here it is covering only one value(that is 3). So it should give coverage percentage of cp2 = 50%. Can you please take a look into this ?

mballance commented 3 years ago

Hi @shrujal20, If I'm reading this correctly:

Looking at c, it appears randomization produced a==3 four times and a==1 one time.

Based on that, it looks to me like having four hits in the single-bin [2,3] is correct.

Please let me know if I'm overlooking something.

Best Regards, Matthew

shrujal20 commented 3 years ago

Hi @mballance,

I was calculating in a different way. Thanks for the explanation.