Add the support of executing multiple netperf clients on hosts,
It can be used as a multi-nics stress test.

Signed-off-by: Amos Kong <ak...@redhat.com>
---
 client/tests/kvm/tests/netperf.py      |   49 +++++++++++++++++++++++---------
 client/tests/kvm/tests_base.cfg.sample |    1 +
 2 files changed, 36 insertions(+), 14 deletions(-)

diff --git a/client/tests/kvm/tests/netperf.py 
b/client/tests/kvm/tests/netperf.py
index df2c839..4f8b0a8 100644
--- a/client/tests/kvm/tests/netperf.py
+++ b/client/tests/kvm/tests/netperf.py
@@ -1,16 +1,17 @@
 import logging, os, signal
 from autotest_lib.client.common_lib import error
 from autotest_lib.client.bin import utils
-import kvm_subprocess
+import kvm_subprocess, kvm_utils
 
 
 def run_netperf(test, params, env):
     """
     Network stress test with netperf.
 
-    1) Boot up a VM.
+    1) Boot up a VM with multiple nics.
     2) Launch netserver on guest.
-    3) Execute netperf client on host with different protocols.
+    3) Execute multiple netperf clients on host in parallel
+       with different protocols.
     4) Output the test result.
 
     @param test: KVM test object.
@@ -20,12 +21,12 @@ def run_netperf(test, params, env):
     vm = env.get_vm(params["main_vm"])
     vm.verify_alive()
     login_timeout = int(params.get("login_timeout", 360))
+    session = vm.wait_for_login(timeout=login_timeout)
+    session.close()
     session_serial = vm.wait_for_serial_login(timeout=login_timeout)
 
     netperf_dir = os.path.join(os.environ['AUTODIR'], "tests/netperf2")
     setup_cmd = params.get("setup_cmd")
-    guest_ip = vm.get_address()
-    result_file = os.path.join(test.resultsdir, "output_%s" % test.iteration)
 
     firewall_flush = "iptables -F"
     session_serial.cmd_output(firewall_flush)
@@ -56,34 +57,54 @@ def run_netperf(test, params, env):
         except:
             pass
 
-    try:
-        logging.info("Setup and run netperf client on host")
-        utils.run(setup_cmd % netperf_dir)
+    def netperf(i=0):
+        guest_ip = vm.get_address(i)
+        logging.info("Netperf_%s: netserver %s" % (i, guest_ip))
+        result_file = os.path.join(test.resultsdir, "output_%s_%s"
+                                   % (test.iteration, i ))
         list_fail = []
         result = open(result_file, "w")
         result.write("Netperf test results\n")
 
-        for i in params.get("protocols").split():
+        for p in params.get("protocols").split():
             packet_size = params.get("packet_size", "1500")
             for size in packet_size.split():
-                cmd = params.get("netperf_cmd") % (netperf_dir, i,
+                cmd = params.get("netperf_cmd") % (netperf_dir, p,
                                                    guest_ip, size)
-                logging.info("Netperf: protocol %s", i)
+                logging.info("Netperf_%s: protocol %s" % (i, p))
                 try:
                     netperf_output = utils.system_output(cmd,
                                                          retain_output=True)
                     result.write("%s\n" % netperf_output)
                 except:
-                    logging.error("Test of protocol %s failed", i)
-                    list_fail.append(i)
+                    logging.error("Test of protocol %s failed", p)
+                    list_fail.append(p)
 
         result.close()
-
         if list_fail:
             raise error.TestFail("Some netperf tests failed: %s" %
                                  ", ".join(list_fail))
 
+    try:
+        logging.info("Setup and run netperf clients on host")
+        utils.run(setup_cmd % netperf_dir)
+
+        bg = []
+        nic_num = len(params.get("nics").split())
+        for i in range(nic_num):
+            bg.append(kvm_utils.Thread(netperf, (i,)))
+            bg[i].start()
+
+        completed = False
+        while not completed:
+            completed = True
+            for b in bg:
+                if b.is_alive():
+                   completed = False
     finally:
+        for b in bg:
+           if b:
+               b.join()
         session_serial.cmd_output("killall netserver")
         if tcpdump and pid:
             logging.debug("Resuming the background tcpdump")
diff --git a/client/tests/kvm/tests_base.cfg.sample 
b/client/tests/kvm/tests_base.cfg.sample
index c70c61b..89e2281 100644
--- a/client/tests/kvm/tests_base.cfg.sample
+++ b/client/tests/kvm/tests_base.cfg.sample
@@ -701,6 +701,7 @@ variants:
     - netperf: install setup unattended_install.cdrom
         only Linux
         type = netperf
+        nics += ' nic2 nic3 nic4'
         nic_mode = tap
         netperf_files = netperf-2.4.5.tar.bz2 wait_before_data.patch
         packet_size = 1500

_______________________________________________
Autotest mailing list
Autotest@test.kernel.org
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to