1 # Copyright (c) 2015 Intel Research and Development Ireland Ltd.
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
20 from experimental_framework.benchmarks import rfc2544_throughput_benchmark \
22 import experimental_framework.common as common
25 class RFC2544ThroughputBenchmarkRunTest(unittest.TestCase):
30 params[mut.VLAN_SENDER] = '1'
31 params[mut.VLAN_RECEIVER] = '2'
32 common.BASE_DIR = os.getcwd()
33 self.benchmark = mut.RFC2544ThroughputBenchmark(name, params)
36 common.BASE_DIR = None
38 def test_get_features_for_sanity(self):
39 output = self.benchmark.get_features()
40 self.assertIsInstance(output, dict)
41 self.assertIn('parameters', list(output.keys()))
42 self.assertIn('allowed_values', list(output.keys()))
43 self.assertIn('default_values', list(output.keys()))
44 self.assertIsInstance(output['parameters'], list)
45 self.assertIsInstance(output['allowed_values'], dict)
46 self.assertIsInstance(output['default_values'], dict)
49 self.assertEqual(self.benchmark.init(), None)
51 def test_finalize(self):
52 self.assertEqual(self.benchmark.finalize(), None)
54 @mock.patch('experimental_framework.common.LOG')
55 @mock.patch('experimental_framework.benchmarks.'
56 'rfc2544_throughput_benchmark.RFC2544ThroughputBenchmark.'
58 @mock.patch('experimental_framework.benchmarks.'
59 'rfc2544_throughput_benchmark.RFC2544ThroughputBenchmark.'
60 '_configure_lua_file')
61 @mock.patch('experimental_framework.benchmarks.'
62 'rfc2544_throughput_benchmark.RFC2544ThroughputBenchmark.'
63 '_extract_packet_size_from_params')
64 @mock.patch('experimental_framework.benchmarks.'
65 'rfc2544_throughput_benchmark.RFC2544ThroughputBenchmark.'
67 @mock.patch('experimental_framework.benchmarks.'
68 'rfc2544_throughput_benchmark.dpdk.DpdkPacketGenerator')
69 def test_run_for_success(self, mock_dpdk, mock_get_results,
70 mock_extract_size, conf_lua_file_mock,
71 reset_lua_file_mock, mock_common_log):
72 expected = {'results': 0}
73 mock_extract_size.return_value = '1'
74 mock_get_results.return_value = {'results': 0}
75 output = self.benchmark.run()
76 self.assertEqual(expected, output)
77 conf_lua_file_mock.assert_called_once()
78 dpdk_instance = mock_dpdk()
79 dpdk_instance.init_dpdk_pktgen.assert_called_once_with(
80 dpdk_interfaces=2, pcap_file_0='packet_1.pcap',
81 pcap_file_1='igmp.pcap', lua_script='rfc2544.lua',
82 vlan_0='1', vlan_1='2')
83 dpdk_instance.send_traffic.assert_called_once_with()
86 class RFC2544ThroughputBenchmarkOthers(unittest.TestCase):
90 params = {'packet_size': '128'}
91 common.BASE_DIR = os.getcwd()
92 self.benchmark = mut.RFC2544ThroughputBenchmark(name, params)
95 common.BASE_DIR = None
97 def test__extract_packet_size_from_params_for_success(self):
99 output = self.benchmark._extract_packet_size_from_params()
100 self.assertEqual(expected, output)
102 @mock.patch('experimental_framework.common.replace_in_file')
103 def test__configure_lua_file(self, mock_common_replace_in_file):
104 self.benchmark.lua_file = 'lua_file'
105 self.benchmark.results_file = 'result_file'
106 self.benchmark._configure_lua_file()
107 mock_common_replace_in_file.\
108 assert_called_once_with('lua_file', 'local out_file = ""',
109 'local out_file = "result_file"')
111 @mock.patch('experimental_framework.common.replace_in_file')
112 def test__reset_lua_file(self, mock_common_replace_in_file):
113 self.benchmark.lua_file = 'lua_file'
114 self.benchmark.results_file = 'result_file'
115 self.benchmark._reset_lua_file()
116 mock_common_replace_in_file.\
117 assert_called_once_with('lua_file',
118 'local out_file = "result_file"',
119 'local out_file = ""')
122 class RFC2544ThroughputBenchmarkGetResultsTest(unittest.TestCase):
125 common.BASE_DIR = os.getcwd()
128 common.BASE_DIR = None
130 @mock.patch('experimental_framework.common.get_file_first_line')
131 def test__get_results_for_success(self, mock_common_file_line):
133 params = {'packet_size': '128'}
134 self.benchmark = mut.RFC2544ThroughputBenchmark(name, params)
135 self.benchmark.results_file = 'base_dir/experimental_framework/' \
136 'packet_generators/dpdk_pktgen/' \
138 mock_common_file_line.return_value = '10'
139 expected = {'throughput': 10}
140 output = self.benchmark._get_results()
141 self.assertEqual(expected, output)
142 mock_common_file_line.\
143 assert_called_once_with('base_dir/experimental_framework/'
144 'packet_generators/dpdk_pktgen/'
147 @mock.patch('experimental_framework.common.get_file_first_line')
148 def test__get_results_for_success_2(self, mock_common_file_line):
150 params = {'packet_size': '128'}
151 self.benchmark = mut.RFC2544ThroughputBenchmark(name, params)
152 self.benchmark.results_file = 'base_dir/experimental_framework/' \
153 'packet_generators/dpdk_pktgen/' \
155 mock_common_file_line.return_value = '1XXX0'
156 expected = {'throughput': 0}
157 output = self.benchmark._get_results()
158 self.assertEqual(expected, output)
159 mock_common_file_line.\
160 assert_called_once_with('base_dir/experimental_framework/'
161 'packet_generators/dpdk_pktgen/'