Skip to content

iff condition with bitwise operations between comparison expressions raises TypeError during sample() #268

Description

@BanuAdrian

Description

Using bitwise operations (e.g. &, |, ^) to combine two comparison expressions in a coverpoint iff condition causes a TypeError during sample() when both operands need to be evaluated.

Minimal Reproducible Example

@vsc.randobj
class Item:
    def __init__(self):
        self.x = vsc.rand_uint8_t()
        self.y = vsc.rand_uint8_t()

@vsc.covergroup
class Cg:
    def __init__(self):
        self.with_sample(dict(it=Item()))
        self.options.name = "cg"

        self.cp_and = vsc.coverpoint(
            self.it.x,
            iff=(self.it.x > 10) & (self.it.y < 100),
            bins={"a": vsc.bin([0, 255])}
        )

cg = Cg()
item = Item()

for i in range(10):
    item.randomize()
    try:
        cg.sample(item)
        print(f"x={item.x}, y={item.y}: OK")
    except TypeError as e:
        print(f"x={item.x}, y={item.y}: FAILED - {e}")

Expected output

All iterations should complete without error.

Actual output

FAILED - TypeError: unsupported operand type(s) for &: 'ValueBool' and 'ValueBool'

The above exception is thrown.

Root Cause

ExprBinModel.val() applies &/| directly on ValueBool objects returned by comparison expressions, but ValueBool does not implement __and__, __or__, __xor__, __invert__, __rand__, __ror__, or __rxor__.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions