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.
19 from yardstick.tests import STL_MOCKS
21 STLClient = mock.MagicMock()
22 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
26 from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxTestDataTuple
27 from yardstick.network_services.traffic_profile.prox_binsearch import ProxBinSearchProfile
30 class TestProxBinSearchProfile(unittest.TestCase):
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()
55 profile_helper = mock.MagicMock()
56 profile_helper.run_test = target
58 profile = ProxBinSearchProfile(tp_config)
59 profile.init(mock.MagicMock())
60 profile._profile_helper = profile_helper
62 profile.execute_traffic(traffic_generator)
63 self.assertEqual(round(profile.current_lower, 2), 74.69)
64 self.assertEqual(round(profile.current_upper, 2), 76.09)
65 self.assertEqual(len(runs), 7)
67 # Result Samples inc theor_max
68 result_tuple = {'Result_Actual_throughput': 5e-07,
69 'Result_theor_max_throughput': 0.00012340000000000002,
70 'Result_pktSize': 200}
72 profile.queue.put.assert_called_with(result_tuple)
74 success_result_tuple = {"Success_CurrentDropPackets": 0.5,
75 "Success_DropPackets": 0.5,
76 "Success_LatencyAvg": 5.3,
77 "Success_LatencyMax": 5.2,
78 "Success_LatencyMin": 5.1,
79 "Success_PktSize": 200,
80 "Success_RxThroughput": 7.5e-07,
81 "Success_Throughput": 7.5e-07,
82 "Success_TxThroughput": 0.00012340000000000002}
84 calls = profile.queue.put(success_result_tuple)
85 profile.queue.put.assert_has_calls(calls)
87 success_result_tuple2 = {"Success_CurrentDropPackets": 0.5,
88 "Success_DropPackets": 0.5,
89 "Success_LatencyAvg": 5.3,
90 "Success_LatencyMax": 5.2,
91 "Success_LatencyMin": 5.1,
92 "Success_PktSize": 200,
93 "Success_RxThroughput": 7.5e-07,
94 "Success_Throughput": 7.5e-07,
95 "Success_TxThroughput": 123.4,
96 "Success_can_be_lost": 409600,
97 "Success_drop_total": 20480,
98 "Success_rx_total": 4075520,
99 "Success_tx_total": 4096000}
101 calls = profile.queue.put(success_result_tuple2)
102 profile.queue.put.assert_has_calls(calls)
104 def test_execute_2(self):
105 def target(*args, **_):
107 if args[2] < 0 or args[2] > 100:
108 raise RuntimeError(' '.join([str(args), str(runs)]))
110 return fail_tuple, {}
111 return success_tuple, {}
115 'packet_sizes': [200],
116 'test_precision': 2.0,
117 'tolerated_loss': 0.001,
122 success_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.1, 5.2, 5.3], 995, 1000, 123.4)
123 fail_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.6, 5.7, 5.8], 850, 1000, 123.4)
125 traffic_generator = mock.MagicMock()
127 profile_helper = mock.MagicMock()
128 profile_helper.run_test = target
130 profile = ProxBinSearchProfile(tp_config)
131 profile.init(mock.MagicMock())
132 profile._profile_helper = profile_helper
134 profile.execute_traffic(traffic_generator)
135 self.assertEqual(round(profile.current_lower, 2), 24.06)
136 self.assertEqual(round(profile.current_upper, 2), 25.47)
137 self.assertEqual(len(runs), 7)
139 def test_execute_3(self):
140 def target(*args, **_):
142 if args[2] < 0 or args[2] > 100:
143 raise RuntimeError(' '.join([str(args), str(runs)]))
145 return fail_tuple, {}
146 return success_tuple, {}
150 'packet_sizes': [200],
151 'test_precision': 2.0,
152 'tolerated_loss': 0.001,
157 success_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.1, 5.2, 5.3], 995, 1000, 123.4)
158 fail_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.6, 5.7, 5.8], 850, 1000, 123.4)
160 traffic_generator = mock.MagicMock()
162 profile_helper = mock.MagicMock()
163 profile_helper.run_test = target
165 profile = ProxBinSearchProfile(tp_config)
166 profile.init(mock.MagicMock())
167 profile._profile_helper = profile_helper
169 profile.upper_bound = 100.0
170 profile.lower_bound = 99.0
171 profile.execute_traffic(traffic_generator)
175 result_tuple = {"Result_theor_max_throughput": 0, "Result_pktSize": 200}
176 profile.queue.put.assert_called_with(result_tuple)
178 # Check for success_ tuple (None expected)
179 calls = profile.queue.put.mock_calls
181 for call_detail in call[1]:
182 for k in call_detail:
184 self.assertRaises(AttributeError)