1 # Copyright (c) 2017 Intel Corporation
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
18 from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxTestDataTuple
19 from yardstick.network_services.traffic_profile import prox_binsearch
22 class TestProxBinSearchProfile(unittest.TestCase):
25 self._mock_log_info = mock.patch.object(prox_binsearch.LOG, 'info')
26 self.mock_log_info = self._mock_log_info.start()
27 self.addCleanup(self._stop_mocks)
29 def _stop_mocks(self):
30 self._mock_log_info.stop()
32 def test_execute_1(self):
33 def target(*args, **_):
35 if args[2] < 0 or args[2] > 100:
36 raise RuntimeError(' '.join([str(args), str(runs)]))
39 return success_tuple, {}
43 'packet_sizes': [200],
44 'test_precision': 2.0,
45 'tolerated_loss': 0.001,
50 success_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.1, 5.2, 5.3], 995, 1000, 123.4)
51 fail_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.6, 5.7, 5.8], 850, 1000, 123.4)
53 traffic_generator = mock.MagicMock()
54 attrs1 = {'get.return_value' : 10}
55 traffic_generator.scenario_helper.all_options.configure_mock(**attrs1)
57 attrs2 = {'__getitem__.return_value' : 10, 'get.return_value': 10}
58 traffic_generator.scenario_helper.scenario_cfg["runner"].configure_mock(**attrs2)
60 profile_helper = mock.MagicMock()
61 profile_helper.run_test = target
63 profile = prox_binsearch.ProxBinSearchProfile(tp_config)
64 profile.init(mock.MagicMock())
65 profile._profile_helper = profile_helper
67 profile.execute_traffic(traffic_generator)
69 self.assertEqual(round(profile.current_lower, 2), 74.69)
70 self.assertEqual(round(profile.current_upper, 2), 76.09)
71 self.assertEqual(len(runs), 77)
73 # Result Samples inc theor_max
74 result_tuple = {'Result_Actual_throughput': 5e-07,
75 'Result_theor_max_throughput': 7.5e-07,
76 'Result_pktSize': 200}
78 profile.queue.put.assert_called_with(result_tuple)
80 success_result_tuple = {"Success_CurrentDropPackets": 0.5,
81 "Success_DropPackets": 0.5,
82 "Success_LatencyAvg": 5.3,
83 "Success_LatencyMax": 5.2,
84 "Success_LatencyMin": 5.1,
85 "Success_PktSize": 200,
86 "Success_RxThroughput": 7.5e-07,
87 "Success_Throughput": 7.5e-07,
88 "Success_TxThroughput": 0.00012340000000000002}
90 calls = profile.queue.put(success_result_tuple)
91 profile.queue.put.assert_has_calls(calls)
93 success_result_tuple2 = {"Success_CurrentDropPackets": 0.5,
94 "Success_DropPackets": 0.5,
95 "Success_LatencyAvg": 5.3,
96 "Success_LatencyMax": 5.2,
97 "Success_LatencyMin": 5.1,
98 "Success_PktSize": 200,
99 "Success_RxThroughput": 7.5e-07,
100 "Success_Throughput": 7.5e-07,
101 "Success_TxThroughput": 123.4,
102 "Success_can_be_lost": 409600,
103 "Success_drop_total": 20480,
104 "Success_rx_total": 4075520,
105 "Success_tx_total": 4096000}
107 calls = profile.queue.put(success_result_tuple2)
108 profile.queue.put.assert_has_calls(calls)
110 def test_execute_2(self):
111 def target(*args, **_):
113 if args[2] < 0 or args[2] > 100:
114 raise RuntimeError(' '.join([str(args), str(runs)]))
116 return fail_tuple, {}
117 return success_tuple, {}
121 'packet_sizes': [200],
122 'test_precision': 2.0,
123 'tolerated_loss': 0.001,
128 success_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.1, 5.2, 5.3], 995, 1000, 123.4)
129 fail_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.6, 5.7, 5.8], 850, 1000, 123.4)
131 traffic_generator = mock.MagicMock()
132 attrs1 = {'get.return_value': 10}
133 traffic_generator.scenario_helper.all_options.configure_mock(**attrs1)
135 attrs2 = {'__getitem__.return_value': 0, 'get.return_value': 0}
136 traffic_generator.scenario_helper.scenario_cfg["runner"].configure_mock(**attrs2)
138 profile_helper = mock.MagicMock()
139 profile_helper.run_test = target
141 profile = prox_binsearch.ProxBinSearchProfile(tp_config)
142 profile.init(mock.MagicMock())
143 profile._profile_helper = profile_helper
145 profile.execute_traffic(traffic_generator)
146 self.assertEqual(round(profile.current_lower, 2), 24.06)
147 self.assertEqual(round(profile.current_upper, 2), 25.47)
148 self.assertEqual(len(runs), 7)
150 def test_execute_3(self):
151 def target(*args, **_):
153 if args[2] < 0 or args[2] > 100:
154 raise RuntimeError(' '.join([str(args), str(runs)]))
156 return fail_tuple, {}
157 return success_tuple, {}
161 'packet_sizes': [200],
162 'test_precision': 2.0,
163 'tolerated_loss': 0.001,
168 success_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.1, 5.2, 5.3], 995, 1000, 123.4)
169 fail_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.6, 5.7, 5.8], 850, 1000, 123.4)
171 traffic_generator = mock.MagicMock()
173 profile_helper = mock.MagicMock()
174 profile_helper.run_test = target
176 profile = prox_binsearch.ProxBinSearchProfile(tp_config)
177 profile.init(mock.MagicMock())
178 profile._profile_helper = profile_helper
180 profile.upper_bound = 100.0
181 profile.lower_bound = 99.0
182 profile.execute_traffic(traffic_generator)
186 result_tuple = {'Result_Actual_throughput': 0, "Result_theor_max_throughput": 0,
187 "Result_pktSize": 200}
188 profile.queue.put.assert_called_with(result_tuple)
190 # Check for success_ tuple (None expected)
191 calls = profile.queue.put.mock_calls
193 for call_detail in call[1]:
194 for k in call_detail:
196 self.assertRaises(AttributeError)
198 def test_execute_4(self):
200 def target(*args, **_):
202 if args[2] < 0 or args[2] > 100:
203 raise RuntimeError(' '.join([str(args), str(runs)]))
205 return fail_tuple, {}
206 return success_tuple, {}
210 'packet_sizes': [200],
211 'test_precision': 2.0,
212 'tolerated_loss': 0.001,
217 success_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.1, 5.2, 5.3], 995, 1000, 123.4)
218 fail_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.6, 5.7, 5.8], 850, 1000, 123.4)
220 traffic_generator = mock.MagicMock()
221 attrs1 = {'get.return_value': 100000}
222 traffic_generator.scenario_helper.all_options.configure_mock(**attrs1)
224 attrs2 = {'__getitem__.return_value': 0, 'get.return_value': 0}
225 traffic_generator.scenario_helper.scenario_cfg["runner"].configure_mock(**attrs2)
227 profile_helper = mock.MagicMock()
228 profile_helper.run_test = target
230 profile = prox_binsearch.ProxBinSearchProfile(tp_config)
231 profile.init(mock.MagicMock())
232 profile._profile_helper = profile_helper
234 profile.execute_traffic(traffic_generator)
235 self.assertEqual(round(profile.current_lower, 2), 74.69)
236 self.assertEqual(round(profile.current_upper, 2), 76.09)
237 self.assertEqual(len(runs), 7)
239 # Result Samples inc theor_max
240 result_tuple = {'Result_Actual_throughput': 5e-07,
241 'Result_theor_max_throughput': 7.5e-07,
242 'Result_pktSize': 200}
244 profile.queue.put.assert_called_with(result_tuple)
246 success_result_tuple = {"Success_CurrentDropPackets": 0.5,
247 "Success_DropPackets": 0.5,
248 "Success_LatencyAvg": 5.3,
249 "Success_LatencyMax": 5.2,
250 "Success_LatencyMin": 5.1,
251 "Success_PktSize": 200,
252 "Success_RxThroughput": 7.5e-07,
253 "Success_Throughput": 7.5e-07,
254 "Success_TxThroughput": 0.00012340000000000002}
256 calls = profile.queue.put(success_result_tuple)
257 profile.queue.put.assert_has_calls(calls)
259 success_result_tuple2 = {"Success_CurrentDropPackets": 0.5,
260 "Success_DropPackets": 0.5,
261 "Success_LatencyAvg": 5.3,
262 "Success_LatencyMax": 5.2,
263 "Success_LatencyMin": 5.1,
264 "Success_PktSize": 200,
265 "Success_RxThroughput": 7.5e-07,
266 "Success_Throughput": 7.5e-07,
267 "Success_TxThroughput": 123.4,
268 "Success_can_be_lost": 409600,
269 "Success_drop_total": 20480,
270 "Success_rx_total": 4075520,
271 "Success_tx_total": 4096000}
273 calls = profile.queue.put(success_result_tuple2)
274 profile.queue.put.assert_has_calls(calls)