Skip to content

Commit

Permalink
0.8.6
Browse files Browse the repository at this point in the history
- (#191) - Fix from @alwilson to ensure proper priority of dist vs soft constraints
- (exp) - Add experimental covergroup callback

Signed-off-by: Matthew Ballance <matt.ballance@gmail.com>
  • Loading branch information
mballance committed Sep 26, 2023
1 parent 29726f2 commit cec1810
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 2 deletions.
35 changes: 35 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Read the Docs configuration file for Sphinx projects
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the OS, Python version and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.11"
# You can also specify other tool versions:
# nodejs: "20"
# rust: "1.70"
# golang: "1.20"

# Build documentation in the "docs/" directory with Sphinx
sphinx:
configuration: docs/conf.py
# You can configure Sphinx to use a different builder, for instance use the dirhtml builder for simpler URLs
# builder: "dirhtml"
# Fail on all warnings to avoid broken references
# fail_on_warning: true

# Optionally build your docs in additional formats such as PDF and ePub
# formats:
# - pdf
# - epub

# Optional but recommended, declare the Python requirements required
# to build your documentation
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
# python:
# install:
# - requirements: docs/requirements.txt
4 changes: 4 additions & 0 deletions doc/Changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

## 0.8.6
- (#191) - Fix from @alwilson to ensure proper priority of dist vs soft constraints
- (exp) - Add experimental covergroup callback
-
## 0.8.5
- (#189) - Correct an issue with how arrays with constraints on sum are
grouped into rand sets.
Expand Down
2 changes: 1 addition & 1 deletion etc/ivpm.info
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

name=pyvsc
version=0.8.5
version=0.8.6

2 changes: 2 additions & 0 deletions src/vsc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
from vsc import profile
from vsc.impl.ctor import glbl_debug, glbl_solvefail_debug

from vsc import util


def get_coverage_report(details=False)->str:
"""
Expand Down
24 changes: 24 additions & 0 deletions src/vsc/util/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#****************************************************************************
#* init.py
#*
#* Copyright 2022 Matthew Ballance and Contributors
#*
#* Licensed under the Apache License, Version 2.0 (the "License"); you may
#* not use this file except in compliance with the License.
#* You may obtain a copy of the License at:
#*
#* http://www.apache.org/licenses/LICENSE-2.0
#*
#* Unless required by applicable law or agreed to in writing, software
#* distributed under the License is distributed on an "AS IS" BASIS,
#* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#* See the License for the specific language governing permissions and
#* limitations under the License.
#*
#* Created on:
#* Author:
#*
#****************************************************************************

from .covergroup_callback_base import CovergroupCallbackBase

70 changes: 70 additions & 0 deletions src/vsc/util/covergroup_callback_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#****************************************************************************
#* covergroup_callback_base.py
#*
#* Copyright 2022 Matthew Ballance and Contributors
#*
#* Licensed under the Apache License, Version 2.0 (the "License"); you may
#* not use this file except in compliance with the License.
#* You may obtain a copy of the License at:
#*
#* http://www.apache.org/licenses/LICENSE-2.0
#*
#* Unless required by applicable law or agreed to in writing, software
#* distributed under the License is distributed on an "AS IS" BASIS,
#* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#* See the License for the specific language governing permissions and
#* limitations under the License.
#*
#* Created on:
#* Author:
#*
#****************************************************************************

from ..model.covergroup_model import CovergroupModel
from ..model.coverpoint_model import CoverpointModel
from ..model.coverpoint_cross_model import CoverpointCrossModel

class CovergroupCallbackBase(object):

def __init__(self):
self._hit_m = {}
self._cb = None

def set_cb(self, cb):
self._cb = cb

def sample_cb(self, *args, **kwargs):
# Call the 'real' sample method
self.sample(*args, **kwargs)

self.call_callbacks()

def call_callbacks(self):
model : CovergroupModel = self.get_model()
for cp in model.coverpoint_l:
self.process_coverpoint(cp)
for cr in model.cross_l:
self.process_cross(cr)

def process_coverpoint(self, cp : CoverpointModel):
for bi in range(cp.get_n_bins()):
name = cp.name + "." + cp.get_bin_name(bi)
if name not in self._hit_m.keys():
self._hit_m[name] = 0
hits = cp.get_bin_hits(bi)
if self._hit_m[name] != hits:
self._hit_m[name] = hits
self._cb(name, hits)

def process_cross(self, cp : CoverpointCrossModel):
for bi in range(cp.get_n_bins()):
name = cp.name + "." + cp.get_bin_name(bi)
if name not in self._hit_m.keys():
self._hit_m[name] = 0
hits = cp.get_bin_hits(bi)
if self._hit_m[name] != hits:
self._hit_m[name] = hits
self._cb(name, hits)



49 changes: 48 additions & 1 deletion ve/unit/test_covergroup_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import vsc
from vsc_test_case import VscTestCase
from vsc.model.covergroup_model import CovergroupModel
from vsc.model.coverpoint_model import CoverpointModel


class TestCovergroupSampling(VscTestCase):
Expand Down Expand Up @@ -219,4 +221,49 @@ def __init__(self):

vsc.report_coverage(details=True)


def test_object_sample_cb_1(self):
import vsc

@vsc.randobj
class BranchInstr:
def __init__(self):
self.type = vsc.rand_bit_t(1)
self.disp = vsc.rand_bit_t(19)

@vsc.constraint
def short_offset_cnstr(self):
self.disp <= 4096

def __str__(self):
return(f"type = {self.type}, displacement = {self.disp}")

# Note: Covergroup must inherit from CovergroupCallbackBase
@vsc.covergroup
class BranchInstr_cg(vsc.util.CovergroupCallbackBase):
def __init__(self):
super().__init__()
self.with_sample(
item = BranchInstr()
)

self.type = vsc.coverpoint(self.item.type)

self.disp_cp = vsc.coverpoint(self.item.disp, bins = {
"small_pos" : vsc.bin_array([4], [0, 4096])
})

branchInstr = BranchInstr()
branchInstr_cg = BranchInstr_cg()

# Note: Callback function accepts bin name and new hit count
def callback(bin, hit):
print("Hit: %s %d" % (bin, hit))

# Note: Register the callback with the covergroup
branchInstr_cg.set_cb(callback)

for i in range(32):
branchInstr.randomize()
# Note: Call 'sample_cb' instead of 'sample'
branchInstr_cg.sample_cb(branchInstr)
print(branchInstr)

0 comments on commit cec1810

Please sign in to comment.