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": 7.5e-07,
69 "Result_theor_max_throughput": 1.234e-10,
70 "Result_pktSize": 200}
71 profile.queue.put.assert_called_with(result_tuple)
73 success_result_tuple = {"Success_CurrentDropPackets": 0.5,
74 "Success_DropPackets": 0.5,
75 "Success_LatencyAvg": 5.3,
76 "Success_LatencyMax": 5.2,
77 "Success_LatencyMin": 5.1,
78 "Success_PktSize": 200,
79 "Success_RxThroughput": 7.5e-07,
80 "Success_Throughput": 7.5e-07,
81 "Success_TxThroughput": 0.00012340000000000002}
83 calls = profile.queue.put(success_result_tuple)
84 profile.queue.put.assert_has_calls(calls)
86 success_result_tuple2 = {"Success_CurrentDropPackets": 0.5,
87 "Success_DropPackets": 0.5,
88 "Success_LatencyAvg": 5.3,
89 "Success_LatencyMax": 5.2,
90 "Success_LatencyMin": 5.1,
91 "Success_PktSize": 200,
92 "Success_RxThroughput": 7.5e-07,
93 "Success_Throughput": 7.5e-07,
94 "Success_TxThroughput": 123.4,
95 "Success_can_be_lost": 409600,
96 "Success_drop_total": 20480,
97 "Success_rx_total": 4075520,
98 "Success_tx_total": 4096000}
100 calls = profile.queue.put(success_result_tuple2)
101 profile.queue.put.assert_has_calls(calls)
103 def test_execute_2(self):
104 def target(*args, **_):
106 if args[2] < 0 or args[2] > 100:
107 raise RuntimeError(' '.join([str(args), str(runs)]))
109 return fail_tuple, {}
110 return success_tuple, {}
114 'packet_sizes': [200],
115 'test_precision': 2.0,
116 'tolerated_loss': 0.001,
121 success_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.1, 5.2, 5.3], 995, 1000, 123.4)
122 fail_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.6, 5.7, 5.8], 850, 1000, 123.4)
124 traffic_generator = mock.MagicMock()
126 profile_helper = mock.MagicMock()
127 profile_helper.run_test = target
129 profile = ProxBinSearchProfile(tp_config)
130 profile.init(mock.MagicMock())
131 profile._profile_helper = profile_helper
133 profile.execute_traffic(traffic_generator)
134 self.assertEqual(round(profile.current_lower, 2), 24.06)
135 self.assertEqual(round(profile.current_upper, 2), 25.47)
136 self.assertEqual(len(runs), 7)
138 def test_execute_3(self):
139 def target(*args, **_):
141 if args[2] < 0 or args[2] > 100:
142 raise RuntimeError(' '.join([str(args), str(runs)]))
144 return fail_tuple, {}
145 return success_tuple, {}
149 'packet_sizes': [200],
150 'test_precision': 2.0,
151 'tolerated_loss': 0.001,
156 success_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.1, 5.2, 5.3], 995, 1000, 123.4)
157 fail_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.6, 5.7, 5.8], 850, 1000, 123.4)
159 traffic_generator = mock.MagicMock()
161 profile_helper = mock.MagicMock()
162 profile_helper.run_test = target
164 profile = ProxBinSearchProfile(tp_config)
165 profile.init(mock.MagicMock())
166 profile._profile_helper = profile_helper
168 profile.upper_bound = 100.0
169 profile.lower_bound = 99.0
170 profile.execute_traffic(traffic_generator)
174 result_tuple = {"Result_theor_max_throughput": 0, "Result_pktSize": 200}
175 profile.queue.put.assert_called_with(result_tuple)
177 # Check for success_ tuple (None expected)
178 calls = profile.queue.put.mock_calls
180 for call_detail in call[1]:
181 for k in call_detail:
183 self.assertRaises(AttributeError)