@@ -71,6 +71,18 @@ class MoreRepeatsUnittestPlug(UnittestPlug):
71
71
return_continue_count = 100
72
72
73
73
74
+ class RepeatTracker ():
75
+
76
+ def __init__ (self ):
77
+ self .count = 0
78
+
79
+ def increment (self ):
80
+ self .count += 1
81
+
82
+ def get_num_repeats (self ) -> int :
83
+ return self .count
84
+
85
+
74
86
class FailedPlugError (Exception ):
75
87
"""Exception for the failed plug."""
76
88
@@ -115,6 +127,29 @@ def phase_repeat(test, test_plug):
115
127
return openhtf .PhaseResult .CONTINUE if ret else openhtf .PhaseResult .REPEAT
116
128
117
129
130
+ @openhtf .PhaseOptions (repeat_on_measurement_fail = True , repeat_limit = 5 )
131
+ @openhtf .measures (
132
+ openhtf .Measurement ('example_dimension' ).with_dimensions (
133
+ 'dim' ).dimension_pivot_validate (
134
+ util .validators .InRange (
135
+ minimum = - 5 ,
136
+ maximum = 5 ,
137
+ )))
138
+ def phase_repeat_on_multidim_measurement_fail (test , meas_value : int ,
139
+ tracker : RepeatTracker ):
140
+ test .measurements ['example_dimension' ][0 ] = meas_value
141
+ tracker .increment ()
142
+
143
+
144
+ @openhtf .PhaseOptions (repeat_on_measurement_fail = True , repeat_limit = 5 )
145
+ @openhtf .measures (
146
+ openhtf .Measurement ('meas_val' ).in_range (minimum = - 5 , maximum = 5 ,))
147
+ def phase_repeat_on_measurement_fail (test , meas_value : int ,
148
+ tracker : RepeatTracker ):
149
+ test .measurements ['meas_val' ] = meas_value
150
+ tracker .increment ()
151
+
152
+
118
153
@openhtf .PhaseOptions (run_if = lambda : False )
119
154
def phase_skip_from_run_if (test ):
120
155
del test # Unused.
@@ -1129,15 +1164,16 @@ def test_branch_with_log(self):
1129
1164
'branch:{}' .format (diag_cond .message ))
1130
1165
1131
1166
1132
- class PhaseExecutorTest (unittest .TestCase ):
1167
+ class PhaseExecutorTest (parameterized .TestCase ):
1133
1168
1134
1169
def setUp (self ):
1135
1170
super (PhaseExecutorTest , self ).setUp ()
1136
1171
self .test_state = mock .MagicMock (
1137
1172
spec = test_state .TestState ,
1138
1173
plug_manager = plugs .PlugManager (),
1139
1174
execution_uid = '01234567890' ,
1140
- state_logger = mock .MagicMock ())
1175
+ state_logger = mock .MagicMock (),
1176
+ test_record = mock .MagicMock (spec = test_record .TestRecord ))
1141
1177
self .test_state .plug_manager .initialize_plugs (
1142
1178
[UnittestPlug , MoreRepeatsUnittestPlug ])
1143
1179
self .phase_executor = phase_executor .PhaseExecutor (self .test_state )
@@ -1148,14 +1184,54 @@ def test_execute_continue_phase(self):
1148
1184
1149
1185
def test_execute_repeat_okay_phase (self ):
1150
1186
result , _ = self .phase_executor .execute_phase (
1151
- phase_repeat .with_plugs (test_plug = UnittestPlug ))
1187
+ phase_repeat .with_plugs (test_plug = UnittestPlug )
1188
+ )
1152
1189
self .assertEqual (openhtf .PhaseResult .CONTINUE , result .phase_result )
1153
1190
1154
1191
def test_execute_repeat_limited_phase (self ):
1155
1192
result , _ = self .phase_executor .execute_phase (
1156
- phase_repeat .with_plugs (test_plug = MoreRepeatsUnittestPlug ))
1193
+ phase_repeat .with_plugs (test_plug = MoreRepeatsUnittestPlug )
1194
+ )
1157
1195
self .assertEqual (openhtf .PhaseResult .STOP , result .phase_result )
1158
1196
1197
+ @parameterized .named_parameters (
1198
+ # NAME, PHASE, MEASUREMENT_VALUE, OUTCOME, EXPECTED_NUMBER_OF_RUNS.
1199
+ # Not failing phase with a simple measurement value in range [-5, +5].
1200
+ ('measurement_phase_not_failing' , phase_repeat_on_measurement_fail , 4 ,
1201
+ test_record .PhaseOutcome .PASS , 1 ),
1202
+ # Failing phase with simple measurement value out of range.
1203
+ ('measurement_phase_failing' , phase_repeat_on_measurement_fail , 10 ,
1204
+ test_record .PhaseOutcome .FAIL , 5 ),
1205
+ # Not failing phase with a multidim measurement value in range [-5, +5].
1206
+ ('multidim_measurement_phase_not_failing' ,
1207
+ phase_repeat_on_multidim_measurement_fail , 4 ,
1208
+ test_record .PhaseOutcome .PASS , 1 ),
1209
+ # Failing phase with multidim measurement value out of range.
1210
+ ('multidim_measurement_phase_failing' ,
1211
+ phase_repeat_on_multidim_measurement_fail , 10 ,
1212
+ test_record .PhaseOutcome .FAIL , 5 ),
1213
+ )
1214
+ def test_execute_repeat_on_measurement_fail_phase (self , phase , meas_value ,
1215
+ outcome , num_runs ):
1216
+ mock_test_state = mock .MagicMock (
1217
+ spec = test_state .TestState ,
1218
+ plug_manager = plugs .PlugManager (),
1219
+ execution_uid = '01234567890' ,
1220
+ state_logger = mock .MagicMock (),
1221
+ test_record = test_record .TestRecord ('mock-dut-id' , 'mock-station-id' ))
1222
+ mock_test_state .plug_manager .initialize_plugs (
1223
+ [UnittestPlug , MoreRepeatsUnittestPlug ])
1224
+ my_phase_record = test_record .PhaseRecord .from_descriptor (phase )
1225
+ my_phase_record .outcome = outcome
1226
+ mock_test_state .test_record .add_phase_record (my_phase_record )
1227
+ my_phase_executor = phase_executor .PhaseExecutor (mock_test_state )
1228
+ tracker = RepeatTracker ()
1229
+ result , _ = my_phase_executor .execute_phase (
1230
+ phase .with_args (tracker = tracker , meas_value = meas_value )
1231
+ )
1232
+ self .assertEqual (openhtf .PhaseResult .CONTINUE , result .phase_result )
1233
+ self .assertEqual (tracker .get_num_repeats (), num_runs )
1234
+
1159
1235
def test_execute_run_if_false (self ):
1160
1236
result , _ = self .phase_executor .execute_phase (phase_skip_from_run_if )
1161
1237
self .assertEqual (openhtf .PhaseResult .SKIP , result .phase_result )
0 commit comments