diff --git a/doc/Changelog.md b/doc/Changelog.md index 513cc5f..f6971bf 100644 --- a/doc/Changelog.md +++ b/doc/Changelog.md @@ -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 diff --git a/etc/ivpm.info b/etc/ivpm.info index 9654a68..3d0c584 100644 --- a/etc/ivpm.info +++ b/etc/ivpm.info @@ -1,4 +1,4 @@ name=pyvsc -version=0.8.4 +version=0.8.5 diff --git a/src/vsc/model/rand_info_builder.py b/src/vsc/model/rand_info_builder.py index e31455a..b661b4f 100644 --- a/src/vsc/model/rand_info_builder.py +++ b/src/vsc/model/rand_info_builder.py @@ -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 diff --git a/ve/unit/test_randsz_array.py b/ve/unit/test_randsz_array.py index 2321065..cd19e5b 100644 --- a/ve/unit/test_randsz_array.py +++ b/ve/unit/test_randsz_array.py @@ -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])) +