Skip to content

Commit 32f01e6

Browse files
committed
0.8.5
- (#189) - Correct an issue with how arrays with constraints on sum are grouped into rand sets. Signed-off-by: Matthew Ballance <[email protected]>
1 parent 9c3d713 commit 32f01e6

File tree

4 files changed

+78
-2
lines changed

4 files changed

+78
-2
lines changed

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.5
3+
- (#189) - Correct an issue with how arrays with constraints on sum are
4+
grouped into rand sets.
5+
26
## 0.8.4
37
- (#188) - Automatically convert floating-point numbers used in constraints
48
to integers

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.4
3+
version=0.8.5
44

src/vsc/model/rand_info_builder.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,12 @@ def visit_expr_array_subscript(self, s : ExprArraySubscriptModel):
329329

330330
if fm in self._field_m.keys():
331331
self._field_m.pop(fm)
332-
332+
333+
def visit_expr_array_sum(self, e):
334+
# Summing the array relates all array elements
335+
for f in e.arr.field_l:
336+
self.process_fieldref(f)
337+
333338
def visit_expr_fieldref(self, e):
334339
# If the field is already referenced by an existing randset
335340
# that is not this one, we need to merge the sets

ve/unit/test_randsz_array.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,70 @@ def a_c(self):
6161
self.assertLess(my_top_rand.a.size, 5)
6262
print("Size: %d" % my_top_rand.a.size)
6363

64+
def test_arr_sum(self):
65+
66+
@vsc.randobj
67+
class ThreadGroupConstraintItem(object):
68+
def __init__(self, aThreadNum, aSharePercent):
69+
self.mThreadNum = aThreadNum
70+
self.mSharePercent = aSharePercent
71+
72+
self.mSharePercentGoal = self.mSharePercent
73+
self.mSharePercentDelta = 10
74+
self.mSharePercentGoalMin = 0
75+
self.mSharePercentGoalMax = 0
76+
self._genSharePrecent()
77+
self.mSharePercentGoalMinConstr = vsc.rand_uint16_t(0)
78+
self.mSharePercentGoalMaxConstr = vsc.rand_uint16_t(0)
79+
self.mGroupSize = vsc.rand_uint16_t(0)
80+
self.GroupList = vsc.randsz_list_t(vsc.rand_uint16_t())
81+
self.GroupListScore = vsc.randsz_list_t(vsc.rand_uint16_t())
82+
83+
@vsc.constraint
84+
def basic_c(self):
85+
self.mGroupSize < self.mThreadNum
86+
self.mGroupSize > 0
87+
self.GroupList.size == self.mGroupSize
88+
self.GroupListScore.size == self.mGroupSize
89+
# self.GroupListSum == self.GroupList.sum
90+
# self.GroupList.sum == self.GroupListSum
91+
# self.GroupListSum == self.mThreadNum
92+
with vsc.foreach(self.GroupList, idx=True, it=False) as idx:
93+
self.GroupList[idx]<= self.mThreadNum
94+
self.GroupList[idx]>0
95+
with vsc.foreach(self.GroupList, idx=True, it=False) as idx:
96+
with vsc.if_then(self.GroupList[idx] > 1):
97+
self.GroupListScore[idx] == 1
98+
with vsc.else_then():
99+
self.GroupListScore[idx] == 0
100+
self.GroupList.sum == self.mThreadNum
101+
# self.mSharePercentGoalMinConstr == self.mSharePercentGoalMin
102+
# self.mSharePercentGoalMaxConstr == self.mSharePercentGoalMax
103+
# self.GroupListScore.sum/self.mGroupSize < int(self.mSharePercentGoalMax/100)
104+
# self.GroupListScore.sum/self.mGroupSize > int(self.mSharePercentGoalMin/100)
105+
106+
def _genSharePrecent(self):
107+
"""generate share percent min/max
108+
"""
109+
if self.mSharePercent > self.mSharePercentDelta:
110+
self.mSharePercentMin = self.mSharePercent - self.mSharePercentDelta
111+
else:
112+
self.mSharePercentMin = 0
113+
114+
if self.mSharePercent < 100 - self.mSharePercentDelta:
115+
self.mSharePercentMax = self.mSharePercent + self.mSharePercentDelta
116+
else:
117+
self.mSharePercentMax = 100
118+
119+
my_obj_rand = ThreadGroupConstraintItem(8, 80)
120+
for i in range(10):
121+
print("Iter %d", i)
122+
my_obj_rand.randomize(debug=False)
123+
self.assertEqual(my_obj_rand.mThreadNum, sum(my_obj_rand.GroupList))
124+
# with vsc.randomize_with(my_obj_rand):
125+
# my_obj_rand.GroupList.sum == my_obj_rand.mThreadNum
126+
print("Thread_num: %0d, GroupList.sum: %d" % (my_obj_rand.mThreadNum, sum(my_obj_rand.GroupList)))
127+
for i,it in enumerate(my_obj_rand.GroupList):
128+
print(" GroupList[%d]: %d" % (i, it))
129+
print(" GroupListScore[%d]: %d" % (i, my_obj_rand.GroupListScore[i]))
130+

0 commit comments

Comments
 (0)