41
41
42
42
# Deltas that are accepted between expected values and achieved
43
43
# values throughout the tests
44
- MAX_BYTES_DIFF_PERCENTAGE = 10
44
+ MAX_BYTES_DIFF_PERCENTAGE = 0.1
45
45
MAX_TIME_DIFF = 25
46
46
47
47
@@ -152,12 +152,12 @@ def _check_tx_rate_limiting(test_microvm):
152
152
153
153
# Sanity check that bandwidth with no rate limiting is at least double
154
154
# than the one expected when rate limiting is in place.
155
- assert _diff (rate_no_limit_kbps , expected_kbps ) > 100
155
+ assert _relative_change (rate_no_limit_kbps , expected_kbps ) > 1.0
156
156
157
157
# Second step: check bandwidth when rate limiting is on.
158
158
print ("Run guest TX iperf for rate limiting without burst" )
159
159
observed_kbps = _get_tx_bandwidth (test_microvm , eth1 .host_ip )
160
- assert _diff (observed_kbps , expected_kbps ) < MAX_BYTES_DIFF_PERCENTAGE
160
+ assert _relative_change (observed_kbps , expected_kbps ) < MAX_BYTES_DIFF_PERCENTAGE
161
161
162
162
# Third step: get the number of bytes when rate limiting is on and there is
163
163
# an initial burst size from where to consume.
@@ -172,11 +172,11 @@ def _check_tx_rate_limiting(test_microvm):
172
172
_ , burst_kbps = _process_iperf_output (iperf_out )
173
173
print ("TX burst_kbps: {}" .format (burst_kbps ))
174
174
# Test that the burst bandwidth is at least as two times the rate limit.
175
- assert _diff (burst_kbps , expected_kbps ) > 100
175
+ assert _relative_change (burst_kbps , expected_kbps ) > 1.0
176
176
177
177
# Since the burst should be consumed, check rate limit is in place.
178
178
observed_kbps = _get_tx_bandwidth (test_microvm , eth2 .host_ip )
179
- assert _diff (observed_kbps , expected_kbps ) < MAX_BYTES_DIFF_PERCENTAGE
179
+ assert _relative_change (observed_kbps , expected_kbps ) < MAX_BYTES_DIFF_PERCENTAGE
180
180
181
181
182
182
def _check_rx_rate_limiting (test_microvm ):
@@ -198,12 +198,12 @@ def _check_rx_rate_limiting(test_microvm):
198
198
199
199
# Sanity check that bandwidth with no rate limiting is at least double
200
200
# than the one expected when rate limiting is in place.
201
- assert _diff (rate_no_limit_kbps , expected_kbps ) > 100
201
+ assert _relative_change (rate_no_limit_kbps , expected_kbps ) > 1.0
202
202
203
203
# Second step: check bandwidth when rate limiting is on.
204
204
print ("Run guest RX iperf for rate limiting without burst" )
205
205
observed_kbps = _get_rx_bandwidth (test_microvm , eth1 .guest_ip )
206
- assert _diff (observed_kbps , expected_kbps ) < MAX_BYTES_DIFF_PERCENTAGE
206
+ assert _relative_change (observed_kbps , expected_kbps ) < MAX_BYTES_DIFF_PERCENTAGE
207
207
208
208
# Third step: get the number of bytes when rate limiting is on and there is
209
209
# an initial burst size from where to consume.
@@ -221,11 +221,11 @@ def _check_rx_rate_limiting(test_microvm):
221
221
_ , burst_kbps = _process_iperf_output (iperf_out )
222
222
print ("RX burst_kbps: {}" .format (burst_kbps ))
223
223
# Test that the burst bandwidth is at least as two times the rate limit.
224
- assert _diff (burst_kbps , expected_kbps ) > 100
224
+ assert _relative_change (burst_kbps , expected_kbps ) > 1.0
225
225
226
226
# Since the burst should be consumed, check rate limit is in place.
227
227
observed_kbps = _get_rx_bandwidth (test_microvm , eth2 .guest_ip )
228
- assert _diff (observed_kbps , expected_kbps ) < MAX_BYTES_DIFF_PERCENTAGE
228
+ assert _relative_change (observed_kbps , expected_kbps ) < MAX_BYTES_DIFF_PERCENTAGE
229
229
230
230
231
231
def _check_tx_rate_limit_patch (test_microvm ):
@@ -239,19 +239,19 @@ def _check_tx_rate_limit_patch(test_microvm):
239
239
# interface.
240
240
_patch_iface_bw (test_microvm , "eth0" , "TX" , bucket_size , REFILL_TIME_MS )
241
241
observed_kbps = _get_tx_bandwidth (test_microvm , eth0 .host_ip )
242
- assert _diff (observed_kbps , expected_kbps ) < MAX_BYTES_DIFF_PERCENTAGE
242
+ assert _relative_change (observed_kbps , expected_kbps ) < MAX_BYTES_DIFF_PERCENTAGE
243
243
244
244
# Check that a TX rate limiter can be updated.
245
245
_patch_iface_bw (test_microvm , "eth1" , "TX" , bucket_size , REFILL_TIME_MS )
246
246
observed_kbps = _get_tx_bandwidth (test_microvm , eth1 .host_ip )
247
- assert _diff (observed_kbps , expected_kbps ) < MAX_BYTES_DIFF_PERCENTAGE
247
+ assert _relative_change (observed_kbps , expected_kbps ) < MAX_BYTES_DIFF_PERCENTAGE
248
248
249
249
# Check that a TX rate limiter can be removed.
250
250
_patch_iface_bw (test_microvm , "eth0" , "TX" , 0 , 0 )
251
251
rate_no_limit_kbps = _get_tx_bandwidth (test_microvm , eth0 .host_ip )
252
252
# Check that bandwidth when rate-limit disabled is at least 1.5x larger
253
253
# than the one when rate limiting was enabled.
254
- assert _diff (rate_no_limit_kbps , expected_kbps ) > 50
254
+ assert _relative_change (rate_no_limit_kbps , expected_kbps ) > 0.5
255
255
256
256
257
257
def _check_rx_rate_limit_patch (test_microvm ):
@@ -265,19 +265,19 @@ def _check_rx_rate_limit_patch(test_microvm):
265
265
# interface.
266
266
_patch_iface_bw (test_microvm , "eth0" , "RX" , bucket_size , REFILL_TIME_MS )
267
267
observed_kbps = _get_rx_bandwidth (test_microvm , eth0 .guest_ip )
268
- assert _diff (observed_kbps , expected_kbps ) < MAX_BYTES_DIFF_PERCENTAGE
268
+ assert _relative_change (observed_kbps , expected_kbps ) < MAX_BYTES_DIFF_PERCENTAGE
269
269
270
270
# Check that an RX rate limiter can be updated.
271
271
_patch_iface_bw (test_microvm , "eth1" , "RX" , bucket_size , REFILL_TIME_MS )
272
272
observed_kbps = _get_rx_bandwidth (test_microvm , eth1 .guest_ip )
273
- assert _diff (observed_kbps , expected_kbps ) < MAX_BYTES_DIFF_PERCENTAGE
273
+ assert _relative_change (observed_kbps , expected_kbps ) < MAX_BYTES_DIFF_PERCENTAGE
274
274
275
275
# Check that an RX rate limiter can be removed.
276
276
_patch_iface_bw (test_microvm , "eth0" , "RX" , 0 , 0 )
277
277
rate_no_limit_kbps = _get_rx_bandwidth (test_microvm , eth0 .guest_ip )
278
278
# Check that bandwidth when rate-limit disabled is at least 1.5x larger
279
279
# than the one when rate limiting was enabled.
280
- assert _diff (rate_no_limit_kbps , expected_kbps ) > 50
280
+ assert _relative_change (rate_no_limit_kbps , expected_kbps ) > 0.5
281
281
282
282
283
283
def _get_tx_bandwidth (test_microvm , host_ip ):
@@ -372,10 +372,10 @@ def _run_iperf_on_host(iperf_cmd, test_microvm):
372
372
return stdout
373
373
374
374
375
- def _diff (measured , base ):
375
+ def _relative_change (measured , base ):
376
376
"""Return the percentage delta between the arguments."""
377
377
assert base != 0
378
- return ( abs (measured - base ) / base ) * 100.0
378
+ return abs (measured - base ) / base
379
379
380
380
381
381
def _process_iperf_line (line ):
0 commit comments