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

getting an error with "iff" parameter in coverage #60

Closed ShraddhaDevaiya closed 3 years ago

ShraddhaDevaiya commented 3 years ago

Hello @mballance , I was trying to run one example using iff parameter in coverpoint. Following is the code for it:

import vsc

@vsc.covergroup
class my_cg(object):
    def __init__(self):
        self.with_sample(dict( a=vsc.uint8_t(),b=vsc.uint8_t()))
        self.cp1 = vsc.coverpoint(self.a, iff=self.b, bins={ "a" : vsc.bin_array([], 1, 2, 4), "b" : vsc.bin_array([4], [8,16])})

my_cg_1 = my_cg()

for i in range(8):
    my_cg_1.sample(i, 0)

str_report = vsc.get_coverage_report(details=True)
print("Report:\n" + str_report)

It is giving an error like this:

Traceback (most recent call last):
  File "1ex.py", line 9, in <module>
    my_cg_1 = my_cg()
  File "/home/shraddha/.local/lib/python3.6/site-packages/vsc/coverage.py", line 260, in __init__
    self.build_model()
  File "/home/shraddha/.local/lib/python3.6/site-packages/vsc/coverage.py", line 161, in build_model
    cp_m = b.build_cov_model(cg_i.model, obj_name_m[b])
  File "/home/shraddha/.local/lib/python3.6/site-packages/vsc/coverage.py", line 477, in build_cov_model
    bin_m = bin_spec.build_cov_model(self.model, bin_name)
  File "/home/shraddha/.local/lib/python3.6/site-packages/vsc/coverage.py", line 326, in build_cov_model
    raise Exception("Single-value bins unimplemented")
Exception: Single-value bins unimplemented

I am not able to understand the error. It seems that I am missing something with iff usage. Can you please help?

mballance commented 3 years ago

Hi @ShraddhaDevaiya, I believe this issue was fixed in a previous release (either 0.2.9 or 0.3.0). Can you try updating? I tried out your testcase with the latest release and it works for me.

Thanks and Best Regards, Matthew

ShraddhaDevaiya commented 3 years ago

Hello @mballance , It is working with the latest version of pyvsc. I was trying this example with another small modification. In iff parameter, I have provided one conditon like following:

import vsc

@vsc.covergroup
class my_cg(object):
    def __init__(self):
        self.with_sample(dict( a=vsc.uint8_t(),b=vsc.uint8_t()))
        self.cp1 = vsc.coverpoint(self.a, iff=(self.b == 9), bins={ "a" : vsc.bin_array([], 1, 2, 4), "b" : vsc.bin_array([4], [8,16])})

my_cg_1 = my_cg()

for i in range(8):
    my_cg_1.sample(i, 0)

str_report = vsc.get_coverage_report(details=True)
print("Report:\n" + str_report)

and output is like this:

Report:
TYPE my_cg : 42.860000%
    CVP cp1 : 42.860000%
    Bins:
        a[0] : 1
        a[1] : 1
        a[2] : 1
        b[0] : 0
        b[1] : 0
        b[2] : 0
        b[3] : 0
    INST my_cg : 42.860000%
        CVP cp1 : 42.860000%
        Bins:
            a[0] : 1
            a[1] : 1
            a[2] : 1
            b[0] : 0
            b[1] : 0
            b[2] : 0
            b[3] : 0

means according to this condtion, if b value is equal to 9, then and then only it should sample the value of a. Here, we are giving b = 0 in this : my_cg_1.sample(i, 0) , but it is giving same output for any condition. Or is there any other way to provide condition with iff? Can you please take a look into this?

ShraddhaDevaiya commented 3 years ago

Hello @mballance ,

Have you got a chance to look into this?

Thanks & Regards, Shraddha Devaiya.

mballance commented 3 years ago

My apologies, @ShraddhaDevaiya, I had overlooked this. I've looked into 'iff' conditions on coverpoints and crosses, corrected issues, and added tests. Your testcase now behaves as expected. The updated code is available on GitHub, and has been released with version 0.3.2. Please update and retry, and confirm that the fixes resolve your issue.

Best Regards, Matthew

ShraddhaDevaiya commented 3 years ago

Hello @mballance , yes now it is working as expected. Thanks for helping.