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.
19 from experimental_framework.benchmarks import rfc2544_throughput_benchmark \
21 import experimental_framework.common as common
24 class RFC2544ThroughputBenchmarkRunTest(unittest.TestCase):
29 params[mut.VLAN_SENDER] = '1'
30 params[mut.VLAN_RECEIVER] = '2'
31 common.BASE_DIR = os.getcwd()
32 self.benchmark = mut.RFC2544ThroughputBenchmark(name, params)
35 common.BASE_DIR = None
37 def test_get_features_for_sanity(self):
38 output = self.benchmark.get_features()
39 self.assertIsInstance(output, dict)
40 self.assertIn('parameters', output.keys())
41 self.assertIn('allowed_values', output.keys())
42 self.assertIn('default_values', output.keys())
43 self.assertIsInstance(output['parameters'], list)
44 self.assertIsInstance(output['allowed_values'], dict)
45 self.assertIsInstance(output['default_values'], dict)
48 self.assertEqual(self.benchmark.init(), None)
50 def test_finalize(self):
51 self.assertEqual(self.benchmark.finalize(), None)
53 @mock.patch('experimental_framework.common.LOG')
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,
70 reset_lua_file_mock, mock_common_log):
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 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/'