blob: 99374569069288ec788ceb460a5e7d195936f85e [file] [log] [blame]
lmr4c607f22009-06-02 11:50:38 +00001import os, time, logging
mbligh53da18e2009-01-05 21:13:26 +00002from autotest_lib.client.bin import test, utils
3from autotest_lib.client.common_lib import error
mblighcf8e0b72008-09-12 02:14:29 +00004
5
6class netpipe(test.test):
7 version = 1
8 NP_FILE = '/tmp/np.out'
9
10 # http://www.scl.ameslab.gov/netpipe/code/NetPIPE-3.7.1.tar.gz
11 def setup(self, tarball='NetPIPE-3.7.1.tar.gz'):
12 tarball = utils.unmap_url(self.bindir, tarball, self.tmpdir)
mbligh53da18e2009-01-05 21:13:26 +000013 utils.extract_tarball_to_dir(tarball, self.srcdir)
mblighcf8e0b72008-09-12 02:14:29 +000014 os.chdir(self.srcdir)
mbligh97590302010-03-11 17:42:46 +000015 utils.system('patch -p1 < ../makefile.patch')
mblighcf8e0b72008-09-12 02:14:29 +000016 utils.system('make')
17
18
19 def initialize(self):
20 self.job.require_gcc()
21
22 # Add arguments later
23 self.server_path = '%s %%s' % os.path.join(self.srcdir, 'NPtcp')
24 # Add server_ip and arguments later
25 base_path = os.path.join(self.srcdir, 'NPtcp -h')
26 self.client_path = '%s %%s -o %s %%s' % (base_path, self.NP_FILE)
27 self.results = []
28
29 def cleanup(self):
30 # Just in case...
31 utils.system('killall -9 NPtcp', ignore_status=True)
32
33
34 def run_once(self, server_ip, client_ip, role, bidirectional=False,
35 buffer_size=None, upper_bound=None,
36 perturbation_size=3):
37 self.role = role
38
39 # Any arguments used must be the same on both the client and the server
40 args = '-p %d ' % perturbation_size
41 if bidirectional:
42 args += '-2 '
43 if buffer_size:
44 args += '-b %d ' % buffer_size
45 if upper_bound:
46 args += '-u %d ' % upper_bound
47
48
49 server_tag = server_ip + '#netpipe-server'
50 client_tag = client_ip + '#netpipe-client'
51 all = [server_tag, client_tag]
52
53 if role == 'server':
mbligh15b8a262008-09-16 16:50:49 +000054 # Wait up to ten minutes for both to reach this point.
mbligh9c12f772009-06-22 19:03:55 +000055 self.job.barrier(server_tag, 'start', 600).rendezvous(*all)
mblighcf8e0b72008-09-12 02:14:29 +000056 self.server_start(args)
57 # Both the client and server should be closed so just to make
mbligh15b8a262008-09-16 16:50:49 +000058 # sure they are both at the same point wait at most five minutes.
mbligh9c12f772009-06-22 19:03:55 +000059 self.job.barrier(server_tag, 'stop', 300).rendezvous(*all)
mblighcf8e0b72008-09-12 02:14:29 +000060 elif role == 'client':
mbligh15b8a262008-09-16 16:50:49 +000061 # Wait up to ten minutes for the server to start
mbligh9c12f772009-06-22 19:03:55 +000062 self.job.barrier(client_tag, 'start', 600).rendezvous(*all)
mblighcf8e0b72008-09-12 02:14:29 +000063 # Sleep 10 seconds to make sure the server is started
64 time.sleep(10)
65 self.client(server_ip, args)
mbligh15b8a262008-09-16 16:50:49 +000066 # Wait up to five minutes for the server to also reach this point
mbligh9c12f772009-06-22 19:03:55 +000067 self.job.barrier(client_tag, 'stop', 300).rendezvous(*all)
mblighcf8e0b72008-09-12 02:14:29 +000068 else:
69 raise error.TestError('invalid role specified')
70
71
72 def server_start(self, args):
73 cmd = self.server_path % args
74 self.results.append(utils.system_output(cmd, retain_output=True))
75
76
77 def client(self, server_ip, args):
78 cmd = self.client_path % (server_ip, args)
79
80 try:
81 # We don't care about the actual output since the important stuff
82 # goes to self.NP_FILE
83 utils.system(cmd)
84 except error.CmdError, e:
85 """ Catch errors due to timeout, but raise others
86 The actual error string is:
87 "Command did not complete within %d seconds"
88 called in function join_bg_job in the file common_lib/utils.py
89
90 Looking for 'within' is probably not the best way to do this but
91 works for now"""
92
93 if ('within' in e.additional_text
94 or 'non-zero' in e.additional_text):
lmr4c607f22009-06-02 11:50:38 +000095 logging.debug(e.additional_text)
mblighcf8e0b72008-09-12 02:14:29 +000096 else:
97 raise
98
99
100 def postprocess(self):
101 if self.role == 'client':
102 try:
103 output = open(self.NP_FILE)
104 for line in output.readlines():
105 buff, bandwidth, latency = line.split()
106 attr = {'buffer_size':buff}
107 keyval = {'bandwidth':bandwidth, 'latency':latency}
108 self.write_iteration_keyval(attr, keyval)
109 finally:
110 output.close()
111 os.remove(self.NP_FILE)