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.
15 __author__ = 'vmriccox'
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 self.benchmark = mut.RFC2544ThroughputBenchmark(name, params)
38 def test_get_features_for_sanity(self):
39 output = self.benchmark.get_features()
40 self.assertIsInstance(output, dict)
41 self.assertIn('parameters', output.keys())
42 self.assertIn('allowed_values', output.keys())
43 self.assertIn('default_values', 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.benchmarks.'
55 'rfc2544_throughput_benchmark.RFC2544ThroughputBenchmark.'
57 @mock.patch('experimental_framework.benchmarks.'
58 'rfc2544_throughput_benchmark.RFC2544ThroughputBenchmark.'
59 '_configure_lua_file')
60 @mock.patch('experimental_framework.benchmarks.'
61 'rfc2544_throughput_benchmark.RFC2544ThroughputBenchmark.'
62 '_extract_packet_size_from_params')
63 @mock.patch('experimental_framework.benchmarks.'
64 'rfc2544_throughput_benchmark.RFC2544ThroughputBenchmark.'
66 @mock.patch('experimental_framework.benchmarks.'
67 'rfc2544_throughput_benchmark.dpdk.DpdkPacketGenerator')
68 def test_run_for_success(self, mock_dpdk, mock_get_results,
69 mock_extract_size, conf_lua_file_mock,
71 expected = {'results': 0, 'packet_size': '1'}
72 mock_extract_size.return_value = '1'
73 mock_get_results.return_value = {'results': 0}
74 output = self.benchmark.run()
75 self.assertEqual(expected, output)
76 conf_lua_file_mock.assert_called_once()
77 reset_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 self.benchmark = mut.RFC2544ThroughputBenchmark(name, params)
96 def test__extract_packet_size_from_params_for_success(self):
98 output = self.benchmark._extract_packet_size_from_params()
99 self.assertEqual(expected, output)
101 @mock.patch('experimental_framework.common.replace_in_file')
102 def test__configure_lua_file(self, mock_common_replace_in_file):
103 self.benchmark.lua_file = 'lua_file'
104 self.benchmark.results_file = 'result_file'
105 self.benchmark._configure_lua_file()
106 mock_common_replace_in_file.\
107 assert_called_once_with('lua_file', 'local out_file = ""',
108 'local out_file = "result_file"')
110 @mock.patch('experimental_framework.common.replace_in_file')
111 def test__reset_lua_file(self, mock_common_replace_in_file):
112 self.benchmark.lua_file = 'lua_file'
113 self.benchmark.results_file = 'result_file'
114 self.benchmark._reset_lua_file()
115 mock_common_replace_in_file.\
116 assert_called_once_with('lua_file',
117 'local out_file = "result_file"',
118 'local out_file = ""')
121 class RFC2544ThroughputBenchmarkGetResultsTest(unittest.TestCase):
129 @mock.patch('experimental_framework.common.get_file_first_line')
130 def test__get_results_for_success(self, mock_common_file_line):
132 params = {'packet_size': '128'}
133 self.benchmark = mut.RFC2544ThroughputBenchmark(name, params)
134 self.benchmark.results_file = 'base_dir/experimental_framework/' \
135 'packet_generators/dpdk_pktgen/' \
137 mock_common_file_line.return_value = '10'
138 expected = {'throughput': 10}
139 output = self.benchmark._get_results()
140 self.assertEqual(expected, output)
141 mock_common_file_line.\
142 assert_called_once_with('base_dir/experimental_framework/'
143 'packet_generators/dpdk_pktgen/'
146 @mock.patch('experimental_framework.common.get_file_first_line')
147 def test__get_results_for_success_2(self, mock_common_file_line):
149 params = {'packet_size': '128'}
150 self.benchmark = mut.RFC2544ThroughputBenchmark(name, params)
151 self.benchmark.results_file = 'base_dir/experimental_framework/' \
152 'packet_generators/dpdk_pktgen/' \
154 mock_common_file_line.return_value = '1XXX0'
155 expected = {'throughput': 0}
156 output = self.benchmark._get_results()
157 self.assertEqual(expected, output)
158 mock_common_file_line.\
159 assert_called_once_with('base_dir/experimental_framework/'
160 'packet_generators/dpdk_pktgen/'