Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(237)

Side by Side Diff: client/tests/kvm/tests/netperf.py

Issue 6246035: Merge remote branch 'cros/upstream' into master (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/autotest.git@master
Patch Set: patch Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 import logging, commands, os 1 import logging, os
2 from autotest_lib.client.common_lib import error 2 from autotest_lib.client.common_lib import error
3 from autotest_lib.client.bin import utils 3 from autotest_lib.client.bin import utils
4 import kvm_test_utils 4 import kvm_subprocess
5
5 6
6 def run_netperf(test, params, env): 7 def run_netperf(test, params, env):
7 """ 8 """
8 Network stress test with netperf. 9 Network stress test with netperf.
9 10
10 1) Boot up a VM. 11 1) Boot up a VM.
11 2) Launch netserver on guest. 12 2) Launch netserver on guest.
12 3) Execute netperf client on host with different protocols. 13 3) Execute netperf client on host with different protocols.
13 4) Output the test result. 14 4) Output the test result.
14 15
15 @param test: KVM test object. 16 @param test: KVM test object.
16 @param params: Dictionary with the test parameters. 17 @param params: Dictionary with the test parameters.
17 @param env: Dictionary with test environment. 18 @param env: Dictionary with test environment.
18 """ 19 """
19 vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) 20 vm = env.get_vm(params["main_vm"])
21 vm.verify_alive()
20 login_timeout = int(params.get("login_timeout", 360)) 22 login_timeout = int(params.get("login_timeout", 360))
21 session = kvm_test_utils.wait_for_login(vm, timeout=login_timeout) 23 session = vm.wait_for_login(timeout=login_timeout)
22 24
23 netperf_dir = os.path.join(os.environ['AUTODIR'], "tests/netperf2") 25 netperf_dir = os.path.join(os.environ['AUTODIR'], "tests/netperf2")
24 setup_cmd = params.get("setup_cmd") 26 setup_cmd = params.get("setup_cmd")
25 guest_ip = vm.get_address() 27 guest_ip = vm.get_address()
26 result_file = os.path.join(test.resultsdir, "output_%s" % test.iteration) 28 result_file = os.path.join(test.resultsdir, "output_%s" % test.iteration)
27 29
28 firewall_flush = "iptables -F" 30 firewall_flush = "iptables -F"
29 session.get_command_output(firewall_flush) 31 session.cmd_output(firewall_flush)
30 32
31 for i in params.get("netperf_files").split(): 33 for i in params.get("netperf_files").split():
32 if not vm.copy_files_to(os.path.join(netperf_dir, i), "/tmp"): 34 vm.copy_files_to(os.path.join(netperf_dir, i), "/tmp")
33 raise error.TestError("Could not copy file %s to guest" % i)
34 35
35 if session.get_command_status(firewall_flush): 36 try:
37 session.cmd(firewall_flush)
38 except kvm_subprocess.ShellError:
36 logging.warning("Could not flush firewall rules on guest") 39 logging.warning("Could not flush firewall rules on guest")
37 40
38 if session.get_command_status(setup_cmd % "/tmp", timeout=200): 41 session.cmd(setup_cmd % "/tmp", timeout=200)
39 raise error.TestFail("Fail to setup netperf on guest") 42 session.cmd(params.get("netserver_cmd") % "/tmp")
40
41 if session.get_command_status(params.get("netserver_cmd") % "/tmp"):
42 raise error.TestFail("Fail to start netperf server on guest")
43 43
44 try: 44 try:
45 logging.info("Setup and run netperf client on host") 45 logging.info("Setup and run netperf client on host")
46 utils.run(setup_cmd % netperf_dir) 46 utils.run(setup_cmd % netperf_dir)
47 list_fail = [] 47 list_fail = []
48 result = open(result_file, "w") 48 result = open(result_file, "w")
49 result.write("Netperf test results\n") 49 result.write("Netperf test results\n")
50 50
51 for i in params.get("protocols").split(): 51 for i in params.get("protocols").split():
52 cmd = params.get("netperf_cmd") % (netperf_dir, i, guest_ip) 52 packet_size = params.get("packet_size", "1500")
53 logging.info("Netperf: protocol %s", i) 53 for size in packet_size.split():
54 try: 54 cmd = params.get("netperf_cmd") % (netperf_dir, i,
55 netperf_output = utils.system_output(cmd, 55 guest_ip, size)
56 retain_output=True) 56 logging.info("Netperf: protocol %s", i)
57 result.write("%s\n" % netperf_output) 57 try:
58 except: 58 netperf_output = utils.system_output(cmd,
59 logging.error("Test of protocol %s failed", i) 59 retain_output=True)
60 list_fail.append(i) 60 result.write("%s\n" % netperf_output)
61 except:
62 logging.error("Test of protocol %s failed", i)
63 list_fail.append(i)
61 64
62 result.close() 65 result.close()
63 66
64 if list_fail: 67 if list_fail:
65 raise error.TestFail("Some netperf tests failed: %s" % 68 raise error.TestFail("Some netperf tests failed: %s" %
66 ", ".join(list_fail)) 69 ", ".join(list_fail))
67 70
68 finally: 71 finally:
69 session.get_command_output("killall netserver") 72 session.cmd_output("killall netserver")
70 session.close() 73 session.close()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698