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