Merge "Use TRex release v2.41 to support both x86 and aarch64"
[yardstick.git] / yardstick / tests / unit / network_services / traffic_profile / test_prox_ramp.py
1 # Copyright (c) 2017 Intel Corporation
2 #
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
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14 #
15
16 import unittest
17 import mock
18
19 from yardstick.tests import STL_MOCKS
20
21 STLClient = mock.MagicMock()
22 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
23 stl_patch.start()
24
25 if stl_patch:
26     from yardstick.network_services.traffic_profile.prox_ramp import ProxRampProfile
27     from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxProfileHelper
28     from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxTestDataTuple
29
30
31 class TestProxRampProfile(unittest.TestCase):
32
33     def test_run_test_with_pkt_size(self):
34         tp_config = {
35             'traffic_profile': {
36                 'lower_bound': 10.0,
37                 'upper_bound': 100.0,
38                 'step_value': 10.0,
39             },
40         }
41
42         success_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.1, 5.2, 5.3], 995, 1000, 123.4)
43
44         traffic_gen = mock.MagicMock()
45         traffic_gen._test_type = 'Generic'
46
47         profile_helper = ProxProfileHelper(traffic_gen.resource_helper)
48         profile_helper.run_test = run_test = mock.MagicMock(return_value=success_tuple)
49
50         profile = ProxRampProfile(tp_config)
51         profile.fill_samples = fill_samples = mock.MagicMock()
52         profile.queue = mock.MagicMock()
53         profile._profile_helper = profile_helper
54
55         profile.run_test_with_pkt_size(traffic_gen, 128, 30)
56         self.assertEqual(run_test.call_count, 10)
57         self.assertEqual(fill_samples.call_count, 10)
58
59     def test_run_test_with_pkt_size_with_fail(self):
60         tp_config = {
61             'traffic_profile': {
62                 'lower_bound': 10.0,
63                 'upper_bound': 100.0,
64                 'step_value': 10.0,
65             },
66         }
67
68         success_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.1, 5.2, 5.3], 995, 1000, 123.4)
69         fail_tuple = ProxTestDataTuple(10.0, 1, 2, 3, 4, [5.6, 5.7, 5.8], 850, 1000, 123.4)
70
71         result_list = [
72             success_tuple,
73             success_tuple,
74             success_tuple,
75             fail_tuple,
76             success_tuple,
77             fail_tuple,
78             fail_tuple,
79             fail_tuple,
80         ]
81
82         traffic_gen = mock.MagicMock()
83         traffic_gen._test_type = 'Generic'
84
85         profile_helper = ProxProfileHelper(traffic_gen.resource_helper)
86         profile_helper.run_test = run_test = mock.MagicMock(side_effect=result_list)
87
88         profile = ProxRampProfile(tp_config)
89         profile.fill_samples = fill_samples = mock.MagicMock()
90         profile.queue = mock.MagicMock()
91         profile._profile_helper = profile_helper
92
93         profile.run_test_with_pkt_size(traffic_gen, 128, 30)
94         self.assertEqual(run_test.call_count, 4)
95         self.assertEqual(fill_samples.call_count, 3)