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.
16 from __future__ import absolute_import
21 from tests.unit import STL_MOCKS
23 STLClient = mock.MagicMock()
24 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
28 from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxTestDataTuple
29 from yardstick.network_services.traffic_profile.prox_binsearch import ProxBinSearchProfile
32 class TestProxBinSearchProfile(unittest.TestCase):
34 def test_execute_1(self):
35 def target(*args, **_):
37 if args[2] < 0 or args[2] > 100:
38 raise RuntimeError(' '.join([str(args), str(runs)]))
41 return success_tuple, {}
45 'packet_sizes': [200],
46 'test_precision': 2.0,
47 'tolerated_loss': 0.001,
52 success_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.1, 5.2, 5.3], 995, 1000, 123.4)
53 fail_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.6, 5.7, 5.8], 850, 1000, 123.4)
55 traffic_generator = mock.MagicMock()
57 profile_helper = mock.MagicMock()
58 profile_helper.run_test = target
60 profile = ProxBinSearchProfile(tp_config)
61 profile.init(mock.MagicMock())
62 profile._profile_helper = profile_helper
64 profile.execute_traffic(traffic_generator)
65 self.assertEqual(round(profile.current_lower, 2), 74.69)
66 self.assertEqual(round(profile.current_upper, 2), 76.09)
67 self.assertEqual(len(runs), 7)
69 # Result Samples inc theor_max
70 result_tuple = {"Result_Actual_throughput": 7.5e-07,
71 "Result_theor_max_throughput": 0.00012340000000000002,
72 "Result_pktSize": 200}
73 profile.queue.put.assert_called_with(result_tuple)
75 success_result_tuple = {"Success_CurrentDropPackets": 0.5,
76 "Success_DropPackets": 0.5,
77 "Success_LatencyAvg": 5.3,
78 "Success_LatencyMax": 5.2,
79 "Success_LatencyMin": 5.1,
80 "Success_PktSize": 200,
81 "Success_RxThroughput": 7.5e-07,
82 "Success_Throughput": 7.5e-07,
83 "Success_TxThroughput": 0.00012340000000000002}
85 calls = profile.queue.put(success_result_tuple)
86 profile.queue.put.assert_has_calls(calls)
88 success_result_tuple2 = {"Success_CurrentDropPackets": 0.5,
89 "Success_DropPackets": 0.5,
90 "Success_LatencyAvg": 5.3,
91 "Success_LatencyMax": 5.2,
92 "Success_LatencyMin": 5.1,
93 "Success_PktSize": 200,
94 "Success_RxThroughput": 7.5e-07,
95 "Success_Throughput": 7.5e-07,
96 "Success_TxThroughput": 123.4,
97 "Success_can_be_lost": 409600,
98 "Success_drop_total": 20480,
99 "Success_rx_total": 4075520,
100 "Success_tx_total": 4096000}
102 calls = profile.queue.put(success_result_tuple2)
103 profile.queue.put.assert_has_calls(calls)
105 def test_execute_2(self):
106 def target(*args, **_):
108 if args[2] < 0 or args[2] > 100:
109 raise RuntimeError(' '.join([str(args), str(runs)]))
111 return fail_tuple, {}
112 return success_tuple, {}
116 'packet_sizes': [200],
117 'test_precision': 2.0,
118 'tolerated_loss': 0.001,
123 success_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.1, 5.2, 5.3], 995, 1000, 123.4)
124 fail_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.6, 5.7, 5.8], 850, 1000, 123.4)
126 traffic_generator = mock.MagicMock()
128 profile_helper = mock.MagicMock()
129 profile_helper.run_test = target
131 profile = ProxBinSearchProfile(tp_config)
132 profile.init(mock.MagicMock())
133 profile._profile_helper = profile_helper
135 profile.execute_traffic(traffic_generator)
136 self.assertEqual(round(profile.current_lower, 2), 24.06)
137 self.assertEqual(round(profile.current_upper, 2), 25.47)
138 self.assertEqual(len(runs), 7)
140 def test_execute_3(self):
141 def target(*args, **_):
143 if args[2] < 0 or args[2] > 100:
144 raise RuntimeError(' '.join([str(args), str(runs)]))
146 return fail_tuple, {}
147 return success_tuple, {}
151 'packet_sizes': [200],
152 'test_precision': 2.0,
153 'tolerated_loss': 0.001,
158 success_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.1, 5.2, 5.3], 995, 1000, 123.4)
159 fail_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.6, 5.7, 5.8], 850, 1000, 123.4)
161 traffic_generator = mock.MagicMock()
163 profile_helper = mock.MagicMock()
164 profile_helper.run_test = target
166 profile = ProxBinSearchProfile(tp_config)
167 profile.init(mock.MagicMock())
168 profile._profile_helper = profile_helper
170 profile.upper_bound = 100.0
171 profile.lower_bound = 99.0
172 profile.execute_traffic(traffic_generator)
176 result_tuple = {"Result_theor_max_throughput": 0, "Result_pktSize": 200}
177 profile.queue.put.assert_called_with(result_tuple)
179 # Check for success_ tuple (None expected)
180 calls = profile.queue.put.mock_calls
182 for call_detail in call[1]:
183 for k in call_detail:
185 self.assertRaises(AttributeError)