blob: 33996125e28a81e2603f097fcad573d86c5092e3 [file] [log] [blame]
mbligh34d01172008-06-05 16:26:31 +00001import os
mbligh9f857922008-06-05 16:19:07 +00002from autotest_lib.client.bin import test, autotest_utils
3from autotest_lib.client.common_lib import utils, error
4
mbligh56a91f02006-09-14 17:55:19 +00005
6class netperf2(test.test):
mbligha5630a52008-09-03 22:09:50 +00007 version = 2
mbligh56a91f02006-09-14 17:55:19 +00008
mbligha5630a52008-09-03 22:09:50 +00009 # ftp://ftp.netperf.org/netperf/netperf-2.4.4.tar.gz
10 def setup(self, tarball = 'netperf-2.4.4.tar.gz'):
mbligh8b352852008-06-07 01:07:08 +000011 tarball = utils.unmap_url(self.bindir, tarball, self.tmpdir)
jadmanski0afbb632008-06-06 21:10:57 +000012 autotest_utils.extract_tarball_to_dir(tarball, self.srcdir)
13 os.chdir(self.srcdir)
mbligh56a91f02006-09-14 17:55:19 +000014
jadmanski0afbb632008-06-06 21:10:57 +000015 utils.system('./configure')
16 utils.system('make')
mbligh54e56842006-09-23 06:02:54 +000017
18
jadmanski0afbb632008-06-06 21:10:57 +000019 def initialize(self):
mbligha5630a52008-09-03 22:09:50 +000020 self.job.require_gcc()
21
22 self.server_path = '%s&' % os.path.join(self.srcdir,
23 'src/netserver')
24 # Add server_ip and arguments later
25 self.client_path = '%s %%s %%s' % os.path.join(self.srcdir,
26 'src/netperf -H')
27
mblighb405b982008-09-10 20:35:52 +000028 self.valid_tests = ['TCP_STREAM', 'TCP_RR', 'TCP_CRR', 'TCP_SENDFILE',
mbligh52fa6922008-09-05 20:37:08 +000029 'UDP_STREAM', 'UDP_RR']
mbligha5630a52008-09-03 22:09:50 +000030 self.results = []
mbligh56a91f02006-09-14 17:55:19 +000031
mbligh6f5bbce2007-08-10 19:18:37 +000032
mbligha5630a52008-09-03 22:09:50 +000033 def run_once(self, server_ip, client_ip, role, test='TCP_STREAM',
34 test_time=10, stream_list=[1]):
35 if test not in self.valid_tests:
36 raise error.TestError('invalid test specified')
37 self.role = role
mbligh52fa6922008-09-05 20:37:08 +000038 self.test = test
39 self.stream_list = stream_list
mbligha5630a52008-09-03 22:09:50 +000040
jadmanski0afbb632008-06-06 21:10:57 +000041 server_tag = server_ip + '#netperf-server'
42 client_tag = client_ip + '#netperf-client'
43 all = [server_tag, client_tag]
mbligha5630a52008-09-03 22:09:50 +000044
mbligha5630a52008-09-03 22:09:50 +000045 for num_streams in stream_list:
46 if role == 'server':
47 self.server_start()
48 try:
mbligh52fa6922008-09-05 20:37:08 +000049 # Wait up to five minutes for the client to reach this
50 # point.
51 self.job.barrier(server_tag, 'start', 300).rendevous(*all)
52 # Wait up to test_time + 1 minute for the test to
53 # complete
54 self.job.barrier(server_tag, 'stop',
55 test_time+60).rendevous(*all)
mbligha5630a52008-09-03 22:09:50 +000056 finally:
57 self.server_stop()
58
59 elif role == 'client':
mbligh52fa6922008-09-05 20:37:08 +000060 # Wait up to five minutes for the server to start
61 self.job.barrier(client_tag, 'start', 300).rendevous(*all)
mbligha5630a52008-09-03 22:09:50 +000062 self.client(server_ip, test, test_time, num_streams)
mbligh52fa6922008-09-05 20:37:08 +000063 # Wait up to 1 minute for the server to also reach this point
64 self.job.barrier(client_tag, 'stop', 60).rendevous(*all)
mbligha5630a52008-09-03 22:09:50 +000065 else:
66 raise error.TestError('invalid role specified')
mbligh54e56842006-09-23 06:02:54 +000067
mbligh56a91f02006-09-14 17:55:19 +000068
jadmanski0afbb632008-06-06 21:10:57 +000069 def server_start(self):
mbligh78be24a2008-06-13 21:40:08 +000070 utils.system('killall netserver', ignore_status=True)
mbligha5630a52008-09-03 22:09:50 +000071 self.results.append(utils.system_output(self.server_path,
72 retain_output=True))
mbligh56a91f02006-09-14 17:55:19 +000073
mbligh54e56842006-09-23 06:02:54 +000074
jadmanski0afbb632008-06-06 21:10:57 +000075 def server_stop(self):
mbligha5630a52008-09-03 22:09:50 +000076 utils.system('killall netserver', ignore_status=True)
mbligh56a91f02006-09-14 17:55:19 +000077
mbligh54e56842006-09-23 06:02:54 +000078
mbligha5630a52008-09-03 22:09:50 +000079 def client(self, server_ip, test, test_time, num_streams):
80 args = '-t %s -l %d' % (test, test_time)
81 cmd = self.client_path % (server_ip, args)
mbligh56a91f02006-09-14 17:55:19 +000082
mbligha5630a52008-09-03 22:09:50 +000083 try:
84 self.results.append(utils.get_cpu_percentage(
mbligh52fa6922008-09-05 20:37:08 +000085 utils.system_output_parallel, [cmd]*num_streams,
86 timeout=test_time+60, retain_output=True))
mbligha5630a52008-09-03 22:09:50 +000087 except error.CmdError, e:
88 """ Catch errors due to timeout, but raise others
89 The actual error string is:
90 "Command did not complete within %d seconds"
91 called in function join_bg_job in the file common_lib/utils.py
mblighe8fa3af2006-09-28 23:14:56 +000092
mbligha5630a52008-09-03 22:09:50 +000093 Looking for 'within' is probably not the best way to do this but
94 works for now"""
95
mbligh52fa6922008-09-05 20:37:08 +000096 if ('within' in e.additional_text
97 or 'non-zero' in e.additional_text):
mbligha5630a52008-09-03 22:09:50 +000098 print e.additional_text
mbligh52fa6922008-09-05 20:37:08 +000099 # Results are cpu%, outputs
100 self.results.append((0, None))
mbligha5630a52008-09-03 22:09:50 +0000101 else:
102 raise
103
104
105 def postprocess(self):
mbligh52fa6922008-09-05 20:37:08 +0000106 if self.role == 'client':
107 if len(self.stream_list) != len(self.results):
108 raise error.TestError('Mismatched number of results')
109
110 function = None
111 keys = None
112
113 # Each of the functions return tuples in which the keys define
114 # what that item in the tuple represents
mblighb405b982008-09-10 20:35:52 +0000115 if self.test in ['TCP_STREAM', 'TCP_SENDFILE']:
mbligh52fa6922008-09-05 20:37:08 +0000116 function = self.process_tcp_stream
117 keys = ('Throughput',)
118 elif self.test == 'UDP_STREAM':
119 function = self.process_udp_stream
120 keys = ('Throughput', 'Errors')
121 elif self.test in ['TCP_RR', 'TCP_CRR', 'UDP_RR']:
122 function = self.process_request_response
123 keys = ('Transfer_Rate',)
124 else:
125 raise error.TestError('Unhandled test')
126
127 # self.results is a list of tuples. The first element in each
128 # tuple is the cpu utilization for that run, and the second
129 # element is a list containing the output for each stream in that
130 # run.
131 for i, streams in enumerate(self.stream_list):
132 attr = {'stream_count':streams}
133 keyval = {}
134 temp_vals = []
135 keyval['CPU'], outputs = self.results[i]
136
137 # Short circuit to handle errors due to client timeouts
138 if not outputs:
139 for key in keys:
140 keyval[key] = 0
141 self.write_iteration_keyval(attr, keyval)
142 continue
143
144 for result in outputs:
145 temp_vals.append(function(result))
146
147 # Compute the average of elements returned from function which
148 # represent the string contained in keys
149 for j, key in enumerate(keys):
150 vals = [x[j] for x in temp_vals]
151 keyval[key] = sum(vals) / len(vals)
152
153 self.write_iteration_keyval(attr, keyval)
154
155
156 def process_tcp_stream(self, output):
mblighb405b982008-09-10 20:35:52 +0000157 """Parses the following (works for both TCP_STREAM and TCP_SENDFILE)
158 and returns a singleton containing throughput.
mbligh52fa6922008-09-05 20:37:08 +0000159
160 TCP STREAM TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to kcqz13.prod.google.com (10.75.222.13) port 0 AF_INET
161 Recv Send Send
162 Socket Socket Message Elapsed
163 Size Size Size Time Throughput
164 bytes bytes bytes secs. 10^6bits/sec
165
166 87380 16384 16384 2.00 941.28
167 """
168
169 return float(output.splitlines()[6].split()[4]),
170
171
172 def process_udp_stream(self, output):
173 """Parses the following and returns a touple containing throughput
174 and the number of errors.
175
176 UDP UNIDIRECTIONAL SEND TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to kcqz13.prod.google.com (10.75.222.13) port 0 AF_INET
177 Socket Message Elapsed Messages
178 Size Size Time Okay Errors Throughput
179 bytes bytes secs # # 10^6bits/sec
180
181 129024 65507 2.00 3673 0 961.87
182 131072 2.00 3673 961.87
183 """
184
185 line_tokens = output.splitlines()[5].split()
186 return float(line_tokens[5]), int(line_tokens[4])
187
188
189 def process_request_response(self, output):
190 """Parses the following which works for both rr (TCP and UDP) and crr
191 tests and returns a singleton containing transfer rate.
192
193 TCP REQUEST/RESPONSE TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to kcqz13.prod.google.com (10.75.222.13) port 0 AF_INET
194 Local /Remote
195 Socket Size Request Resp. Elapsed Trans.
196 Send Recv Size Size Time Rate
197 bytes Bytes bytes bytes secs. per sec
198
199 16384 87380 1 1 2.00 14118.53
200 16384 87380
201 """
202
203 return float(output.splitlines()[6].split()[5]),