Skip to content

Commit

Permalink
Merge pull request #209 from alwilson/misc_doc_updates
Browse files Browse the repository at this point in the history
doc: fix intro and other examples, update feature list
  • Loading branch information
mballance authored Mar 27, 2024
2 parents 6b8b9e8 + f6cf6cc commit fc51652
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 52 deletions.
2 changes: 1 addition & 1 deletion doc/source/constraints.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ condition without knowing the details of what that condition is.
my_i = my_cls()
with my_i.randomize()
my_i.randomize()
with my_i.randomize_with() as it:
it.a_small()
Expand Down
6 changes: 3 additions & 3 deletions doc/source/features.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ scalar dynamic array Y Y N
class fixed-size array Y Y Y
class dynamic array Y Y N
class (in)equality N N Y
array sum N Y Y
array size N Y Y
array sum Y Y Y
array size Y Y Y
array reduction OR N Y N
array reduction AND N Y N
array reduction XOR N Y N
Expand All @@ -50,7 +50,7 @@ default N N Y
dynamic Y N Y
inside (in) Y Y Y
soft Y Y N
solve before N Y N
solve before Y Y N
`unique` Y Y Y
`foreach` Y Y Y
`forall` N Y Y
Expand Down
90 changes: 44 additions & 46 deletions doc/source/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,60 +40,58 @@ coverage, and inline randomization.

.. code-block:: python3
import vsc
@vsc.randobj
class my_item_c(object):
def __init__(self):
self.a = vsc.rand_bit_t(8)
self.b = vsc.rand_bit_t(8)
@vsc.constraint
def ab_c(self):
self.a != 0
self.a <= self.b
self.b in vsc.rangelist(1,2,4,8)
@vsc.covergroup
class my_cg(object):
def __init__(self):
# Define the parameters accepted by the sample function
self.with_sample(dict(
it=my_item_c()
))
self.a_cp = vsc.coverpoint( self.it.a, bins=dict(
# Create 4 bins across the space 0..255
a_bins = bin_array([4], [0,255])
)
self.b_cp = vsc.coverpoint(self.it.b, bins=dict(
# Create one bin for each value (1,2,4,8)
b_bins = bin_array([], 1, 2, 4, 8)
)
self.ab_cross = vsc.cross([self.a_cp, self.b_cp])
# Create an instance of the covergroup
my_cg_i = my_cg()
# Create an instance of the item class
my_item_i = my_item_c()
# Randomize and sample coverage
for i in range(16):
my_item_i.randomize()
my_cg_i.sample(my_item_i)
# Now, randomize keeping b in the range [1,2]
for i in range(16):
with my_item_i.randomize_with() as it:
it.b in vsc.rangelist(1,2)
my_cg_i.sample(my_item_i)
print("Coverage: %f \%" % (my_cg_i.get_coverage()))
@vsc.constraint
def ab_c(self):
self.a != 0
self.a <= self.b
self.b in vsc.rangelist(1,2,4,8)
@vsc.covergroup
class my_cg(object):
def __init__(self):
# Define the parameters accepted by the sample function
self.with_sample(dict(
it = my_item_c()
))
self.a_cp = vsc.coverpoint(self.it.a, bins=dict(
# Create 4 bins across the space 0..255
a_bins = vsc.bin_array([4], [0,255])
))
self.b_cp = vsc.coverpoint(self.it.b, bins=dict(
# Create one bin for each value (1,2,4,8)
b_bins = vsc.bin_array([], 1, 2, 4, 8)
))
self.ab_cross = vsc.cross([self.a_cp, self.b_cp])
# Create an instance of the covergroup
my_cg_i = my_cg()
# Create an instance of the item class
my_item_i = my_item_c()
# Randomize and sample coverage
for i in range(16):
my_item_i.randomize()
my_cg_i.sample(my_item_i)
# Now, randomize keeping b in the range [1,2]
for i in range(16):
with my_item_i.randomize_with() as it:
it.b in vsc.rangelist(1,2)
my_cg_i.sample(my_item_i)
# Print report of type and instance coverage
vsc.report_coverage()
Contributors
Expand Down
13 changes: 11 additions & 2 deletions doc/source/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,20 @@ Installation from Source
cd pyvsc
pip install -e .
Running a Simple Example
A Simple Example
========================

.. code-block:: python3
import vsc
a = vsc.rand_uint8_t()
b = vsc.rand_uint8_t()
for _ in range(10):
with vsc.randomize_with(a, b):
a < b
print(a.get_val(), b.get_val())

0 comments on commit fc51652

Please sign in to comment.