Skip to content

Commit

Permalink
0.8.5
Browse files Browse the repository at this point in the history
- (#189) - Correct an issue with how arrays with constraints on sum are
  grouped into rand sets.

Signed-off-by: Matthew Ballance <matt.ballance@gmail.com>
  • Loading branch information
mballance committed Aug 22, 2023
1 parent 9c3d713 commit 32f01e6
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 2 deletions.
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.5
- (#189) - Correct an issue with how arrays with constraints on sum are
grouped into rand sets.

## 0.8.4
- (#188) - Automatically convert floating-point numbers used in constraints
to integers
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.4
version=0.8.5

7 changes: 6 additions & 1 deletion src/vsc/model/rand_info_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,12 @@ def visit_expr_array_subscript(self, s : ExprArraySubscriptModel):

if fm in self._field_m.keys():
self._field_m.pop(fm)


def visit_expr_array_sum(self, e):
# Summing the array relates all array elements
for f in e.arr.field_l:
self.process_fieldref(f)

def visit_expr_fieldref(self, e):
# If the field is already referenced by an existing randset
# that is not this one, we need to merge the sets
Expand Down
67 changes: 67 additions & 0 deletions ve/unit/test_randsz_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,70 @@ def a_c(self):
self.assertLess(my_top_rand.a.size, 5)
print("Size: %d" % my_top_rand.a.size)

def test_arr_sum(self):

@vsc.randobj
class ThreadGroupConstraintItem(object):
def __init__(self, aThreadNum, aSharePercent):
self.mThreadNum = aThreadNum
self.mSharePercent = aSharePercent

self.mSharePercentGoal = self.mSharePercent
self.mSharePercentDelta = 10
self.mSharePercentGoalMin = 0
self.mSharePercentGoalMax = 0
self._genSharePrecent()
self.mSharePercentGoalMinConstr = vsc.rand_uint16_t(0)
self.mSharePercentGoalMaxConstr = vsc.rand_uint16_t(0)
self.mGroupSize = vsc.rand_uint16_t(0)
self.GroupList = vsc.randsz_list_t(vsc.rand_uint16_t())
self.GroupListScore = vsc.randsz_list_t(vsc.rand_uint16_t())

@vsc.constraint
def basic_c(self):
self.mGroupSize < self.mThreadNum
self.mGroupSize > 0
self.GroupList.size == self.mGroupSize
self.GroupListScore.size == self.mGroupSize
# self.GroupListSum == self.GroupList.sum
# self.GroupList.sum == self.GroupListSum
# self.GroupListSum == self.mThreadNum
with vsc.foreach(self.GroupList, idx=True, it=False) as idx:
self.GroupList[idx]<= self.mThreadNum
self.GroupList[idx]>0
with vsc.foreach(self.GroupList, idx=True, it=False) as idx:
with vsc.if_then(self.GroupList[idx] > 1):
self.GroupListScore[idx] == 1
with vsc.else_then():
self.GroupListScore[idx] == 0
self.GroupList.sum == self.mThreadNum
# self.mSharePercentGoalMinConstr == self.mSharePercentGoalMin
# self.mSharePercentGoalMaxConstr == self.mSharePercentGoalMax
# self.GroupListScore.sum/self.mGroupSize < int(self.mSharePercentGoalMax/100)
# self.GroupListScore.sum/self.mGroupSize > int(self.mSharePercentGoalMin/100)

def _genSharePrecent(self):
"""generate share percent min/max
"""
if self.mSharePercent > self.mSharePercentDelta:
self.mSharePercentMin = self.mSharePercent - self.mSharePercentDelta
else:
self.mSharePercentMin = 0

if self.mSharePercent < 100 - self.mSharePercentDelta:
self.mSharePercentMax = self.mSharePercent + self.mSharePercentDelta
else:
self.mSharePercentMax = 100

my_obj_rand = ThreadGroupConstraintItem(8, 80)
for i in range(10):
print("Iter %d", i)
my_obj_rand.randomize(debug=False)
self.assertEqual(my_obj_rand.mThreadNum, sum(my_obj_rand.GroupList))
# with vsc.randomize_with(my_obj_rand):
# my_obj_rand.GroupList.sum == my_obj_rand.mThreadNum
print("Thread_num: %0d, GroupList.sum: %d" % (my_obj_rand.mThreadNum, sum(my_obj_rand.GroupList)))
for i,it in enumerate(my_obj_rand.GroupList):
print(" GroupList[%d]: %d" % (i, it))
print(" GroupListScore[%d]: %d" % (i, my_obj_rand.GroupListScore[i]))

0 comments on commit 32f01e6

Please sign in to comment.