4141
4242# Deltas that are accepted between expected values and achieved
4343# values throughout the tests
44- MAX_BYTES_DIFF_PERCENTAGE = 10
44+ MAX_RELATIVE_KBPS_CHANGE = 0.1
4545MAX_TIME_DIFF = 25
4646
4747
@@ -152,12 +152,12 @@ def _check_tx_rate_limiting(test_microvm):
152152
153153 # Sanity check that bandwidth with no rate limiting is at least double
154154 # 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
156156
157157 # Second step: check bandwidth when rate limiting is on.
158158 print ("Run guest TX iperf for rate limiting without burst" )
159159 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_RELATIVE_KBPS_CHANGE
161161
162162 # Third step: get the number of bytes when rate limiting is on and there is
163163 # an initial burst size from where to consume.
@@ -172,11 +172,11 @@ def _check_tx_rate_limiting(test_microvm):
172172 _ , burst_kbps = _process_iperf_output (iperf_out )
173173 print ("TX burst_kbps: {}" .format (burst_kbps ))
174174 # 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
176176
177177 # Since the burst should be consumed, check rate limit is in place.
178178 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_RELATIVE_KBPS_CHANGE
180180
181181
182182def _check_rx_rate_limiting (test_microvm ):
@@ -198,12 +198,12 @@ def _check_rx_rate_limiting(test_microvm):
198198
199199 # Sanity check that bandwidth with no rate limiting is at least double
200200 # 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
202202
203203 # Second step: check bandwidth when rate limiting is on.
204204 print ("Run guest RX iperf for rate limiting without burst" )
205205 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_RELATIVE_KBPS_CHANGE
207207
208208 # Third step: get the number of bytes when rate limiting is on and there is
209209 # an initial burst size from where to consume.
@@ -221,11 +221,11 @@ def _check_rx_rate_limiting(test_microvm):
221221 _ , burst_kbps = _process_iperf_output (iperf_out )
222222 print ("RX burst_kbps: {}" .format (burst_kbps ))
223223 # 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
225225
226226 # Since the burst should be consumed, check rate limit is in place.
227227 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_RELATIVE_KBPS_CHANGE
229229
230230
231231def _check_tx_rate_limit_patch (test_microvm ):
@@ -239,19 +239,19 @@ def _check_tx_rate_limit_patch(test_microvm):
239239 # interface.
240240 _patch_iface_bw (test_microvm , "eth0" , "TX" , bucket_size , REFILL_TIME_MS )
241241 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_RELATIVE_KBPS_CHANGE
243243
244244 # Check that a TX rate limiter can be updated.
245245 _patch_iface_bw (test_microvm , "eth1" , "TX" , bucket_size , REFILL_TIME_MS )
246246 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_RELATIVE_KBPS_CHANGE
248248
249249 # Check that a TX rate limiter can be removed.
250250 _patch_iface_bw (test_microvm , "eth0" , "TX" , 0 , 0 )
251251 rate_no_limit_kbps = _get_tx_bandwidth (test_microvm , eth0 .host_ip )
252252 # Check that bandwidth when rate-limit disabled is at least 1.5x larger
253253 # 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
255255
256256
257257def _check_rx_rate_limit_patch (test_microvm ):
@@ -265,19 +265,19 @@ def _check_rx_rate_limit_patch(test_microvm):
265265 # interface.
266266 _patch_iface_bw (test_microvm , "eth0" , "RX" , bucket_size , REFILL_TIME_MS )
267267 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_RELATIVE_KBPS_CHANGE
269269
270270 # Check that an RX rate limiter can be updated.
271271 _patch_iface_bw (test_microvm , "eth1" , "RX" , bucket_size , REFILL_TIME_MS )
272272 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_RELATIVE_KBPS_CHANGE
274274
275275 # Check that an RX rate limiter can be removed.
276276 _patch_iface_bw (test_microvm , "eth0" , "RX" , 0 , 0 )
277277 rate_no_limit_kbps = _get_rx_bandwidth (test_microvm , eth0 .guest_ip )
278278 # Check that bandwidth when rate-limit disabled is at least 1.5x larger
279279 # 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
281281
282282
283283def _get_tx_bandwidth (test_microvm , host_ip ):
@@ -372,10 +372,10 @@ def _run_iperf_on_host(iperf_cmd, test_microvm):
372372 return stdout
373373
374374
375- def _diff (measured , base ):
375+ def _relative_change (measured , base ):
376376 """Return the percentage delta between the arguments."""
377377 assert base != 0
378- return ( abs (measured - base ) / base ) * 100.0
378+ return abs (measured - base ) / base
379379
380380
381381def _process_iperf_line (line ):
0 commit comments