Skip to content

Commit cec1810

Browse files
committed
0.8.6
- (#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>
1 parent 29726f2 commit cec1810

File tree

7 files changed

+184
-2
lines changed

7 files changed

+184
-2
lines changed

.readthedocs.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Read the Docs configuration file for Sphinx projects
2+
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
3+
4+
# Required
5+
version: 2
6+
7+
# Set the OS, Python version and other tools you might need
8+
build:
9+
os: ubuntu-22.04
10+
tools:
11+
python: "3.11"
12+
# You can also specify other tool versions:
13+
# nodejs: "20"
14+
# rust: "1.70"
15+
# golang: "1.20"
16+
17+
# Build documentation in the "docs/" directory with Sphinx
18+
sphinx:
19+
configuration: docs/conf.py
20+
# You can configure Sphinx to use a different builder, for instance use the dirhtml builder for simpler URLs
21+
# builder: "dirhtml"
22+
# Fail on all warnings to avoid broken references
23+
# fail_on_warning: true
24+
25+
# Optionally build your docs in additional formats such as PDF and ePub
26+
# formats:
27+
# - pdf
28+
# - epub
29+
30+
# Optional but recommended, declare the Python requirements required
31+
# to build your documentation
32+
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
33+
# python:
34+
# install:
35+
# - requirements: docs/requirements.txt

doc/Changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11

2+
## 0.8.6
3+
- (#191) - Fix from @alwilson to ensure proper priority of dist vs soft constraints
4+
- (exp) - Add experimental covergroup callback
5+
-
26
## 0.8.5
37
- (#189) - Correct an issue with how arrays with constraints on sum are
48
grouped into rand sets.

etc/ivpm.info

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11

22
name=pyvsc
3-
version=0.8.5
3+
version=0.8.6
44

src/vsc/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
from vsc import profile
4343
from vsc.impl.ctor import glbl_debug, glbl_solvefail_debug
4444

45+
from vsc import util
46+
4547

4648
def get_coverage_report(details=False)->str:
4749
"""

src/vsc/util/__init__.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#****************************************************************************
2+
#* init.py
3+
#*
4+
#* Copyright 2022 Matthew Ballance and Contributors
5+
#*
6+
#* Licensed under the Apache License, Version 2.0 (the "License"); you may
7+
#* not use this file except in compliance with the License.
8+
#* You may obtain a copy of the License at:
9+
#*
10+
#* http://www.apache.org/licenses/LICENSE-2.0
11+
#*
12+
#* Unless required by applicable law or agreed to in writing, software
13+
#* distributed under the License is distributed on an "AS IS" BASIS,
14+
#* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
#* See the License for the specific language governing permissions and
16+
#* limitations under the License.
17+
#*
18+
#* Created on:
19+
#* Author:
20+
#*
21+
#****************************************************************************
22+
23+
from .covergroup_callback_base import CovergroupCallbackBase
24+
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#****************************************************************************
2+
#* covergroup_callback_base.py
3+
#*
4+
#* Copyright 2022 Matthew Ballance and Contributors
5+
#*
6+
#* Licensed under the Apache License, Version 2.0 (the "License"); you may
7+
#* not use this file except in compliance with the License.
8+
#* You may obtain a copy of the License at:
9+
#*
10+
#* http://www.apache.org/licenses/LICENSE-2.0
11+
#*
12+
#* Unless required by applicable law or agreed to in writing, software
13+
#* distributed under the License is distributed on an "AS IS" BASIS,
14+
#* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
#* See the License for the specific language governing permissions and
16+
#* limitations under the License.
17+
#*
18+
#* Created on:
19+
#* Author:
20+
#*
21+
#****************************************************************************
22+
23+
from ..model.covergroup_model import CovergroupModel
24+
from ..model.coverpoint_model import CoverpointModel
25+
from ..model.coverpoint_cross_model import CoverpointCrossModel
26+
27+
class CovergroupCallbackBase(object):
28+
29+
def __init__(self):
30+
self._hit_m = {}
31+
self._cb = None
32+
33+
def set_cb(self, cb):
34+
self._cb = cb
35+
36+
def sample_cb(self, *args, **kwargs):
37+
# Call the 'real' sample method
38+
self.sample(*args, **kwargs)
39+
40+
self.call_callbacks()
41+
42+
def call_callbacks(self):
43+
model : CovergroupModel = self.get_model()
44+
for cp in model.coverpoint_l:
45+
self.process_coverpoint(cp)
46+
for cr in model.cross_l:
47+
self.process_cross(cr)
48+
49+
def process_coverpoint(self, cp : CoverpointModel):
50+
for bi in range(cp.get_n_bins()):
51+
name = cp.name + "." + cp.get_bin_name(bi)
52+
if name not in self._hit_m.keys():
53+
self._hit_m[name] = 0
54+
hits = cp.get_bin_hits(bi)
55+
if self._hit_m[name] != hits:
56+
self._hit_m[name] = hits
57+
self._cb(name, hits)
58+
59+
def process_cross(self, cp : CoverpointCrossModel):
60+
for bi in range(cp.get_n_bins()):
61+
name = cp.name + "." + cp.get_bin_name(bi)
62+
if name not in self._hit_m.keys():
63+
self._hit_m[name] = 0
64+
hits = cp.get_bin_hits(bi)
65+
if self._hit_m[name] != hits:
66+
self._hit_m[name] = hits
67+
self._cb(name, hits)
68+
69+
70+

ve/unit/test_covergroup_sampling.py

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import vsc
99
from vsc_test_case import VscTestCase
10+
from vsc.model.covergroup_model import CovergroupModel
11+
from vsc.model.coverpoint_model import CoverpointModel
1012

1113

1214
class TestCovergroupSampling(VscTestCase):
@@ -219,4 +221,49 @@ def __init__(self):
219221

220222
vsc.report_coverage(details=True)
221223

222-
224+
def test_object_sample_cb_1(self):
225+
import vsc
226+
227+
@vsc.randobj
228+
class BranchInstr:
229+
def __init__(self):
230+
self.type = vsc.rand_bit_t(1)
231+
self.disp = vsc.rand_bit_t(19)
232+
233+
@vsc.constraint
234+
def short_offset_cnstr(self):
235+
self.disp <= 4096
236+
237+
def __str__(self):
238+
return(f"type = {self.type}, displacement = {self.disp}")
239+
240+
# Note: Covergroup must inherit from CovergroupCallbackBase
241+
@vsc.covergroup
242+
class BranchInstr_cg(vsc.util.CovergroupCallbackBase):
243+
def __init__(self):
244+
super().__init__()
245+
self.with_sample(
246+
item = BranchInstr()
247+
)
248+
249+
self.type = vsc.coverpoint(self.item.type)
250+
251+
self.disp_cp = vsc.coverpoint(self.item.disp, bins = {
252+
"small_pos" : vsc.bin_array([4], [0, 4096])
253+
})
254+
255+
branchInstr = BranchInstr()
256+
branchInstr_cg = BranchInstr_cg()
257+
258+
# Note: Callback function accepts bin name and new hit count
259+
def callback(bin, hit):
260+
print("Hit: %s %d" % (bin, hit))
261+
262+
# Note: Register the callback with the covergroup
263+
branchInstr_cg.set_cb(callback)
264+
265+
for i in range(32):
266+
branchInstr.randomize()
267+
# Note: Call 'sample_cb' instead of 'sample'
268+
branchInstr_cg.sample_cb(branchInstr)
269+
print(branchInstr)

0 commit comments

Comments
 (0)