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