summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--yardstick/vTC/apexlake/experimental_framework/benchmarks/instantiation_validation_benchmark.py232
-rw-r--r--yardstick/vTC/apexlake/experimental_framework/libraries/__init__.py19
-rw-r--r--yardstick/vTC/apexlake/experimental_framework/libraries/packet_checker/Makefile4
-rw-r--r--yardstick/vTC/apexlake/experimental_framework/libraries/packet_checker/test_sniff.c146
-rw-r--r--yardstick/vTC/apexlake/tests/instantiation_validation_bench_test.py322
5 files changed, 723 insertions, 0 deletions
diff --git a/yardstick/vTC/apexlake/experimental_framework/benchmarks/instantiation_validation_benchmark.py b/yardstick/vTC/apexlake/experimental_framework/benchmarks/instantiation_validation_benchmark.py
new file mode 100644
index 000000000..29a87f2ee
--- /dev/null
+++ b/yardstick/vTC/apexlake/experimental_framework/benchmarks/instantiation_validation_benchmark.py
@@ -0,0 +1,232 @@
+# Copyright (c) 2015 Intel Research and Development Ireland Ltd.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+import commands
+import signal
+import time
+from experimental_framework.benchmarks import benchmark_base_class as base
+from experimental_framework.constants import framework_parameters as fp
+from experimental_framework.constants import conf_file_sections as cfs
+from experimental_framework.packet_generators import dpdk_packet_generator \
+ as dpdk
+import experimental_framework.common as common
+
+
+THROUGHPUT = 'throughput'
+VLAN_SENDER = 'vlan_sender'
+VLAN_RECEIVER = 'vlan_receiver'
+PACKETS_FILE_NAME = 'packets.res'
+PACKET_CHECKER_PROGRAM_NAME = 'test_sniff'
+MULTICAST_GROUP = '224.192.16.1'
+
+
+class InstantiationValidationBenchmark(base.BenchmarkBaseClass):
+
+ def __init__(self, name, params):
+ base.BenchmarkBaseClass.__init__(self, name, params)
+ self.base_dir = common.get_base_dir() + \
+ fp.EXPERIMENTAL_FRAMEWORK_DIR + fp.DPDK_PKTGEN_DIR
+ self.results_file = self.base_dir + PACKETS_FILE_NAME
+ self.lua_file = self.base_dir + 'constant_traffic.lua'
+ self.res_dir = ''
+ self.interface_name = ''
+
+ # Set the packet checker command
+ self.pkt_checker_command = common.get_base_dir()
+ self.pkt_checker_command += 'experimental_framework/libraries/'
+ self.pkt_checker_command += 'packet_checker/'
+ self.pkt_checker_command += PACKET_CHECKER_PROGRAM_NAME + ' '
+
+ def init(self):
+ """
+ Initialize the benchmark
+ :return: None
+ """
+ pass
+
+ def finalize(self):
+ """
+ Finalizes the benchmark
+ :return: None
+ """
+ pass
+
+ def get_features(self):
+ features = dict()
+ features['description'] = 'Instantiation Validation Benchmark'
+ features['parameters'] = [THROUGHPUT, VLAN_SENDER, VLAN_RECEIVER]
+ features['allowed_values'] = dict()
+ features['allowed_values'][THROUGHPUT] = map(str, range(0, 100))
+ features['allowed_values'][VLAN_SENDER] = map(str, range(-1, 4096))
+ features['allowed_values'][VLAN_RECEIVER] = map(str, range(-1, 4096))
+ features['default_values'] = dict()
+ features['default_values'][THROUGHPUT] = '1'
+ features['default_values'][VLAN_SENDER] = '-1'
+ features['default_values'][VLAN_RECEIVER] = '-1'
+ return features
+
+ def run(self):
+ # Setup packet generator
+ traffic_time = '10'
+ packet_size = '512'
+ traffic_rate_percentage = self.params[THROUGHPUT]
+
+ dpdk_pktgen_vars = common.get_dpdk_pktgen_vars()
+ # bus_address = dpdk_pktgen_vars[cfs.CFSP_DPDK_BUS_SLOT_NIC_2]
+ self.interface_name = dpdk_pktgen_vars[cfs.CFSP_DPDK_NAME_IF_2]
+ packetgen = dpdk.DpdkPacketGenerator()
+ self._configure_lua_file(traffic_rate_percentage, traffic_time)
+ packetgen.init_dpdk_pktgen(dpdk_interfaces=1,
+ pcap_file_0='packet_' + packet_size +
+ '.pcap',
+ pcap_file_1='igmp.pcap',
+ lua_script='constant_traffic.lua',
+ vlan_0=self.params[VLAN_SENDER],
+ vlan_1=self.params[VLAN_RECEIVER])
+
+ self._init_packet_checker()
+ # Send constant traffic at a specified rate
+ common.LOG.debug('Start the packet generator')
+ packetgen.send_traffic()
+ common.LOG.debug('Stop the packet generator')
+ time.sleep(5)
+ self._finalize_packet_checker()
+ self._reset_lua_file(traffic_rate_percentage, traffic_time)
+ return self._get_results()
+
+ def _configure_lua_file(self, traffic_rate_percentage, traffic_time):
+ """
+ Configure the packet gen to write the results into the right file
+ :return: None
+ """
+ common.replace_in_file(self.lua_file, 'local out_file = ""',
+ 'local out_file = "' +
+ self.results_file + '"')
+ common.replace_in_file(self.lua_file, 'local traffic_rate = 0',
+ 'local traffic_rate = ' +
+ traffic_rate_percentage)
+ common.replace_in_file(self.lua_file, 'local traffic_delay = 0',
+ 'local traffic_delay = ' + traffic_time)
+
+ def _reset_lua_file(self, traffic_rate_percentage, traffic_time):
+ """
+ Configure the packet gen to write the results into the right file
+ :param traffic_rate_percentage:
+ :param traffic_time:
+ :return: None
+ """
+
+ common.replace_in_file(self.lua_file, 'local out_file = "' +
+ self.results_file + '"',
+ 'local out_file = ""')
+ common.replace_in_file(self.lua_file, 'local traffic_rate = ' +
+ traffic_rate_percentage,
+ 'local traffic_rate = 0')
+ common.replace_in_file(self.lua_file, 'local traffic_delay = ' +
+ traffic_time, 'local traffic_delay = 0')
+
+ def _get_results(self):
+ ret_val = dict()
+ packet_checker_res = 0
+ if self.res_dir:
+ packet_checker_res = \
+ int(common.get_file_first_line(self.res_dir +
+ '/packet_checker.res'))
+ pkt_gen_res = int(common.get_file_first_line(self.results_file))
+ if pkt_gen_res <= packet_checker_res or \
+ (float(pkt_gen_res - packet_checker_res) / pkt_gen_res) <= 0.1:
+ ret_val['failure'] = '0'
+ else:
+ ret_val['failure'] = '1'
+ return ret_val
+
+ def _init_packet_checker(self):
+ """
+ Sets up the multicast and starts the packet checker
+ :return:
+ """
+ # Kill any other process running from previous failed execution
+ self.res_dir = os.getcwd()
+ pids = self._get_pids()
+ for pid in pids:
+ os.kill(pid, signal.SIGTERM)
+
+ # initialization of the VLAN interface
+ command = "ip link add link "
+ command += self.interface_name
+ command += " name "
+ command += self.interface_name + '.' + self.params[VLAN_RECEIVER]
+ command += " type vlan id " + self.params[VLAN_RECEIVER]
+ common.run_command(command)
+
+ # set up the new
+ command = 'ifconfig ' + self.interface_name + '.' + \
+ self.params[VLAN_RECEIVER]
+ # An IP address is required for the interface to receive a multicast
+ # flow. The specific address is not important
+ command += ' 10.254.254.254 up'
+ common.run_command(command)
+
+ # configure smcroute
+ command = "echo 'mgroup from "
+ command += self.interface_name + '.' + self.params[VLAN_RECEIVER]
+ command += " group "
+ command += MULTICAST_GROUP
+ command += "' > /etc/smcroute.conf"
+ common.run_command(command)
+
+ # run smcroute on the interface
+ command = 'smcroute -d'
+ common.run_command(command)
+
+ # Start the packet checker
+ command = self.pkt_checker_command
+ command += self.interface_name + '.' + self.params[VLAN_RECEIVER]
+ command += ' 128'
+ command += ' &'
+ common.run_command(command)
+
+ def _finalize_packet_checker(self):
+ """
+ Obtains the PID of the packet checker and sends an alarm to
+ terminate it
+ :return: None
+ """
+ pids = self._get_pids()
+ for pid in pids:
+ os.kill(pid, signal.SIGTERM)
+
+ # stop smcroute on the interface
+ command = 'smcroute -k'
+ common.run_command(command)
+
+ # finalization of the VLAN interface
+ command = "ip link delete "
+ command += self.interface_name + '.' + self.params[VLAN_RECEIVER]
+ common.run_command(command)
+
+ def _get_pids(self):
+ """
+ Returns a list of integers containing the pid or the pids of the
+ processes currently running on the host
+ :return: type: list of int
+ """
+ output = commands.getoutput("ps -ef |pgrep " +
+ PACKET_CHECKER_PROGRAM_NAME)
+ if not output:
+ pids = []
+ else:
+ pids = map(int, output.split('\n'))
+ return pids
diff --git a/yardstick/vTC/apexlake/experimental_framework/libraries/__init__.py b/yardstick/vTC/apexlake/experimental_framework/libraries/__init__.py
new file mode 100644
index 000000000..dcc18a45b
--- /dev/null
+++ b/yardstick/vTC/apexlake/experimental_framework/libraries/__init__.py
@@ -0,0 +1,19 @@
+# Copyright (c) 2015 Intel Research and Development Ireland Ltd.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+'''
+Libraries to be used by the framework.
+'''
+
+__author__ = 'vmriccox'
diff --git a/yardstick/vTC/apexlake/experimental_framework/libraries/packet_checker/Makefile b/yardstick/vTC/apexlake/experimental_framework/libraries/packet_checker/Makefile
new file mode 100644
index 000000000..c216778f0
--- /dev/null
+++ b/yardstick/vTC/apexlake/experimental_framework/libraries/packet_checker/Makefile
@@ -0,0 +1,4 @@
+CC=gcc
+LDFLAGS= -lpcap
+testsniffmake: test_sniff.c
+ $(CC) $(CFLAGS) -o test_sniff test_sniff.c $(LDFLAGS)
diff --git a/yardstick/vTC/apexlake/experimental_framework/libraries/packet_checker/test_sniff.c b/yardstick/vTC/apexlake/experimental_framework/libraries/packet_checker/test_sniff.c
new file mode 100644
index 000000000..f85acfa11
--- /dev/null
+++ b/yardstick/vTC/apexlake/experimental_framework/libraries/packet_checker/test_sniff.c
@@ -0,0 +1,146 @@
+// Copyright (c) 2015 Intel Research and Development Ireland Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include <pcap.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netinet/if_ether.h>
+
+static int expected_tos = -1;
+static int cmatch = 0;
+
+
+/* 4 bytes IP address */
+typedef struct ip_address
+{
+ u_char byte1;
+ u_char byte2;
+ u_char byte3;
+ u_char byte4;
+} ip_address;
+
+
+/* IPv4 header */
+typedef struct ip_header
+{
+ u_char ver_ihl;
+ u_char tos;
+ u_short tlen;
+ u_short identification;
+ u_short flags_fo;
+ u_char ttl;
+ u_char proto;
+ u_short crc;
+ ip_address saddr;
+ ip_address daddr;
+ u_int op_pad;
+} ip_header;
+
+
+/* UDP header*/
+typedef struct udp_header
+{
+ u_short sport; // Source port
+ u_short dport; // Destination port
+ u_short len; // Datagram length
+ u_short crc; // Checksum
+} udp_header;
+
+
+/* Save results on file */
+void save_and_exit(int sig)
+{
+ write_file();
+ exit(0);
+}
+
+
+/*
+ * This callback function is called for each received packet
+ */
+void stats_collection(u_char *useless,
+ const struct pcap_pkthdr* pkthdr,
+ const u_char* packet)
+{
+ ip_header *ih;
+ udp_header *uh;
+ u_int ip_len;
+ ih = (ip_header *) (packet + 14);
+ ip_len = (ih->ver_ihl & 0xf) * 4;
+ u_char tos = ih->tos;
+ // Counter update
+ if(tos==expected_tos)
+ cmatch ++;
+}
+
+
+int main(int argc,char **argv)
+{
+ int i;
+ char *dev;
+ char errbuf[PCAP_ERRBUF_SIZE];
+ pcap_t* descr;
+ const u_char *packet;
+ struct pcap_pkthdr hdr;
+ struct ether_header *eptr;
+
+ if(argc != 3)
+ {
+ fprintf(stdout,"Usage: %s interface_name expected_tos\n", argv[0]);
+ exit(1);
+ }
+
+ expected_tos = atoi(argv[2]);
+
+ /* Setup signal to stop the sniffer */
+ signal(SIGTERM, save_and_exit);
+
+ /* Take a device to read from */
+ dev = argv[1];
+ if(dev == NULL)
+ {
+ printf("%s\n",errbuf);
+ exit(1);
+ }
+
+ /* Open device for reading */
+ descr = pcap_open_live(dev, BUFSIZ, 0, -1, errbuf);
+ if(descr == NULL)
+ {
+ printf("pcap_open_live(): %s\n", errbuf);
+ exit(1);
+ }
+
+ /* Start the loop to be run for each packet */
+ pcap_loop(descr, -1, stats_collection, NULL);
+ return 0;
+}
+
+
+int write_file()
+{
+ FILE *f = fopen("packet_checker.res", "w");
+ if (f == NULL)
+ {
+ printf("Error opening file!\n");
+ exit(1);
+ }
+ fprintf(f, "%d\n", cmatch);
+ fclose(f);
+}
diff --git a/yardstick/vTC/apexlake/tests/instantiation_validation_bench_test.py b/yardstick/vTC/apexlake/tests/instantiation_validation_bench_test.py
new file mode 100644
index 000000000..569d24c5a
--- /dev/null
+++ b/yardstick/vTC/apexlake/tests/instantiation_validation_bench_test.py
@@ -0,0 +1,322 @@
+# Copyright (c) 2015 Intel Research and Development Ireland Ltd.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import unittest
+import mock
+import experimental_framework.constants.conf_file_sections as cfs
+import experimental_framework.benchmarks.\
+ instantiation_validation_benchmark as iv_module
+from experimental_framework.benchmarks.\
+ instantiation_validation_benchmark import InstantiationValidationBenchmark
+
+
+kill_counter = [0, 0]
+command_counter = [0, 0, 0, 0, 0]
+replace_counter = [0, 0, 0]
+
+
+def dummy_os_kill(pid, signal, get_counters=None):
+ if get_counters:
+ return kill_counter
+ if pid == 1234:
+ kill_counter[0] += 1
+ return
+ if pid == 4321:
+ kill_counter[1] += 1
+ return
+ raise Exception(pid)
+
+
+def dummy_run_command(command, get_counters=None):
+ if get_counters:
+ return command_counter
+ if command == 'smcroute -k':
+ command_counter[0] += 1
+ return
+ elif command == 'ip link delete interface.100':
+ command_counter[1] += 1
+ return
+ raise Exception(command)
+
+
+def dummy_run_command_2(command, get_counters=None):
+ if get_counters:
+ return command_counter
+ if command == 'ip link add link interface name interface.' \
+ '100 type vlan id 100':
+ command_counter[0] += 1
+ return
+ elif command == 'ifconfig interface.100 10.254.254.254 up':
+ command_counter[1] += 1
+ return
+ elif command == "echo 'mgroup from interface.100 group 224.192.16.1' > " \
+ "/etc/smcroute.conf":
+ command_counter[2] += 1
+ return
+ elif command == "smcroute -d":
+ command_counter[3] += 1
+ return
+ elif command == "test_sniff interface.100 128 &":
+ command_counter[4] += 1
+ return
+ raise Exception(command)
+
+
+def dummy_replace_in_file(file, str_from, str_to, get_couters=None):
+ if get_couters:
+ return replace_counter
+ if file == 'file':
+ if str_from == 'local out_file = "result_file"':
+ if str_to == 'local out_file = ""':
+ replace_counter[0] += 1
+ return
+ if str_from == 'local traffic_rate = 100':
+ if str_to == 'local traffic_rate = 0':
+ replace_counter[1] += 1
+ return
+ if str_from == 'local traffic_delay = 60':
+ if str_to == 'local traffic_delay = 0':
+ replace_counter[2] += 1
+ return
+ if str_from == 'local out_file = ""':
+ if str_to == 'local out_file = "result_file"':
+ replace_counter[3] += 1
+ return
+ if str_from == 'local traffic_rate = 0':
+ if str_to == 'local traffic_rate = 100':
+ replace_counter[4] += 1
+ return
+ if str_from == 'local traffic_delay = 0':
+ if str_to == 'local traffic_delay = 60':
+ replace_counter[5] += 1
+ return
+ raise Exception(file + ' ' + str_from + ' ' + str_to)
+
+
+class DummyDpdkPacketGenerator():
+
+ counter = 0
+
+ def __init__(self):
+ DummyDpdkPacketGenerator.counter = [0, 0]
+
+ def init_dpdk_pktgen(self, dpdk_interfaces, lua_script, pcap_file_0,
+ pcap_file_1, vlan_0, vlan_1):
+ if dpdk_interfaces == 1:
+ if lua_script == 'constant_traffic.lua':
+ if pcap_file_0 == 'packet_512.pcap':
+ if pcap_file_1 == 'igmp.pcap':
+ if vlan_0 == '-1':
+ if vlan_1 == '-1':
+ DummyDpdkPacketGenerator.counter[0] += 1
+
+ def send_traffic(self):
+ DummyDpdkPacketGenerator.counter[1] += 1
+ return
+
+
+class DummyInstantiaionValidationBenchmark(InstantiationValidationBenchmark):
+
+ counter = [0, 0, 0, 0, 0]
+
+ def _configure_lua_file(self, traffic_rate_percentage, traffic_time):
+ DummyInstantiaionValidationBenchmark.counter[0] += 1
+
+ def _init_packet_checker(self):
+ DummyInstantiaionValidationBenchmark.counter[1] += 1
+
+ def _finalize_packet_checker(self):
+ DummyInstantiaionValidationBenchmark.counter[2] += 1
+
+ def _reset_lua_file(self, traffic_rate_percentage, traffic_time):
+ if traffic_rate_percentage == '1' and traffic_time == '10':
+ DummyInstantiaionValidationBenchmark.counter[3] += 1
+
+ def _get_results(self):
+ DummyInstantiaionValidationBenchmark.counter[4] += 1
+ res = {'test': 'result'}
+ return res
+
+
+class InstantiationValidationInitTest(unittest.TestCase):
+
+ def setUp(self):
+ self.iv = InstantiationValidationBenchmark('InstantiationValidation',
+ dict())
+
+ def tearDown(self):
+ pass
+
+ @mock.patch('experimental_framework.common.get_base_dir')
+ def test___init___for_success(self, mock_base_dir):
+ mock_base_dir.return_value = 'base_dir/'
+ iv = InstantiationValidationBenchmark('InstantiationValidation',
+ dict())
+ self.assertEqual(iv.base_dir,
+ 'base_dir/experimental_framework/'
+ 'packet_generators/dpdk_pktgen/')
+ self.assertEqual(iv.results_file,
+ 'base_dir/experimental_framework/'
+ 'packet_generators/dpdk_pktgen/packets.res')
+ self.assertEqual(iv.lua_file,
+ 'base_dir/experimental_framework/'
+ 'packet_generators/dpdk_pktgen/constant_traffic.lua')
+ self.assertEqual(iv.pkt_checker_command,
+ 'base_dir/experimental_framework/'
+ 'libraries/packet_checker/test_sniff ')
+ self.assertEqual(iv.res_dir, '')
+ self.assertEqual(iv.interface_name, '')
+
+ def test_init_for_success(self):
+ self.iv.init()
+
+ def test_finalize_for_success(self):
+ self.iv.finalize()
+
+ def test_get_features_for_success(self):
+
+ expected = dict()
+ expected['description'] = 'Instantiation Validation Benchmark'
+ expected['parameters'] = [
+ iv_module.THROUGHPUT,
+ iv_module.VLAN_SENDER,
+ iv_module.VLAN_RECEIVER
+ ]
+ expected['allowed_values'] = dict()
+ expected['allowed_values'][iv_module.THROUGHPUT] = \
+ map(str, range(0, 100))
+ expected['allowed_values'][iv_module.VLAN_SENDER] = \
+ map(str, range(-1, 4096))
+ expected['allowed_values'][iv_module.VLAN_RECEIVER] = \
+ map(str, range(-1, 4096))
+ expected['default_values'] = dict()
+ expected['default_values'][iv_module.THROUGHPUT] = '1'
+ expected['default_values'][iv_module.VLAN_SENDER] = '-1'
+ expected['default_values'][iv_module.VLAN_RECEIVER] = '-1'
+ output = self.iv.get_features()
+ self.assertEqual(expected, output)
+
+ @mock.patch('commands.getoutput')
+ def test__get_pids_for_success(self, mock_getoutput):
+ expected = [1234]
+ mock_getoutput.return_value = '1234'
+ output = self.iv._get_pids()
+ self.assertEqual(expected, output)
+
+ expected = [1234, 4321]
+ mock_getoutput.return_value = '1234\n4321'
+ output = self.iv._get_pids()
+ self.assertEqual(expected, output)
+
+ expected = []
+ mock_getoutput.return_value = None
+ output = self.iv._get_pids()
+ self.assertEqual(expected, output)
+
+ @mock.patch('experimental_framework.common.run_command',
+ side_effect=dummy_run_command)
+ @mock.patch('os.kill', side_effect=dummy_os_kill)
+ @mock.patch('experimental_framework.benchmarks.'
+ 'instantiation_validation_benchmark.'
+ 'InstantiationValidationBenchmark._get_pids')
+ def test__finalize_packet_checker_for_success(self,
+ mock_pids,
+ mock_os_kill,
+ mock_run_command):
+ global command_counter
+ global kill_counter
+ command_counter = [0, 0, 0, 0, 0]
+ kill_counter = [0, 0]
+ mock_pids.return_value = [1234, 4321]
+ self.iv.interface_name = 'interface'
+ self.iv.params[iv_module.VLAN_RECEIVER] = '100'
+ self.iv._finalize_packet_checker()
+ self.assertEqual(dummy_os_kill('', '', True), [1, 1])
+ self.assertEqual(dummy_run_command('', True), [1, 1, 0, 0, 0])
+
+ @mock.patch('experimental_framework.common.run_command',
+ side_effect=dummy_run_command_2)
+ @mock.patch('experimental_framework.benchmarks.'
+ 'instantiation_validation_benchmark.'
+ 'InstantiationValidationBenchmark._get_pids')
+ @mock.patch('os.kill', side_effect=dummy_os_kill)
+ def test__init_packet_checker_for_success(self, mock_kill,
+ mock_pids, mock_run_command):
+ global command_counter
+ command_counter = [0, 0, 0, 0, 0]
+ mock_pids.return_value = [1234, 4321]
+ self.iv.pkt_checker_command = 'test_sniff '
+ self.iv.interface_name = 'interface'
+ self.iv.params[iv_module.VLAN_RECEIVER] = '100'
+ self.iv._init_packet_checker()
+ self.assertEqual(dummy_run_command('', True), [1, 1, 1, 1, 1])
+
+ @mock.patch('experimental_framework.common.get_file_first_line')
+ def test__get_results_for_success(self, mock_get_file):
+ self.iv.res_dir = 'directory'
+ mock_get_file.side_effect = ['100', '50']
+ expected = {'failure': '0'}
+ output = self.iv._get_results()
+ self.assertEqual(expected, output)
+
+ mock_get_file.side_effect = ['10', '50']
+ expected = {'failure': '1'}
+ output = self.iv._get_results()
+ self.assertEqual(expected, output)
+
+ @mock.patch('experimental_framework.common.replace_in_file',
+ side_effect=dummy_replace_in_file)
+ def test__reset_lua_file_for_success(self, mock_replace):
+ global replace_counter
+ replace_counter = [0, 0, 0, 0, 0, 0]
+ traffic_rate_percentage = '100'
+ traffic_time = '60'
+ self.iv.lua_file = 'file'
+ self.iv.results_file = 'result_file'
+ self.iv._reset_lua_file(traffic_rate_percentage, traffic_time)
+ self.assertEqual(dummy_replace_in_file('', '', '', True),
+ [1, 1, 1, 0, 0, 0])
+
+ @mock.patch('experimental_framework.common.replace_in_file',
+ side_effect=dummy_replace_in_file)
+ def test__configure_lua_file_for_success(self, mock_replace):
+ global replace_counter
+ replace_counter = [0, 0, 0, 0, 0, 0]
+ traffic_rate_percentage = '100'
+ traffic_time = '60'
+ self.iv.lua_file = 'file'
+ self.iv.results_file = 'result_file'
+ self.iv._configure_lua_file(traffic_rate_percentage, traffic_time)
+ self.assertEqual(dummy_replace_in_file('', '', '', True),
+ [0, 0, 0, 1, 1, 1])
+
+ @mock.patch('experimental_framework.packet_generators.'
+ 'dpdk_packet_generator.DpdkPacketGenerator',
+ side_effect=DummyDpdkPacketGenerator)
+ @mock.patch('experimental_framework.common.get_dpdk_pktgen_vars')
+ def test_run_for_success(self, mock_common_get_vars, mock_pktgen):
+ rval = dict()
+ rval[cfs.CFSP_DPDK_BUS_SLOT_NIC_2] = 'bus_2'
+ rval[cfs.CFSP_DPDK_NAME_IF_2] = 'if_2'
+ mock_common_get_vars.return_value = rval
+ expected = {'test': 'result'}
+ iv = DummyInstantiaionValidationBenchmark('InstantiationValidation',
+ dict())
+ iv.params[iv_module.THROUGHPUT] = '1'
+ output = iv.run()
+ self.assertEqual(expected, output)
+ self.assertEqual(DummyDpdkPacketGenerator.counter,
+ [1, 1])
+ self.assertEqual(DummyInstantiaionValidationBenchmark.counter,
+ [1, 1, 1, 1, 1])