blob: d17466441c1c65109b416f5b5e180f934c3151f3 [file] [log] [blame]
mbligh865ee822008-10-03 16:03:34 +00001import os,time
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 = []
mbligh865ee822008-10-03 16:03:34 +000031 self.actual_times = []
mbligh56a91f02006-09-14 17:55:19 +000032
mbligh6f5bbce2007-08-10 19:18:37 +000033
mbligha5630a52008-09-03 22:09:50 +000034 def run_once(self, server_ip, client_ip, role, test='TCP_STREAM',
35 test_time=10, stream_list=[1]):
36 if test not in self.valid_tests:
37 raise error.TestError('invalid test specified')
38 self.role = role
mbligh52fa6922008-09-05 20:37:08 +000039 self.test = test
mbligh865ee822008-10-03 16:03:34 +000040 self.test_time = test_time
mbligh52fa6922008-09-05 20:37:08 +000041 self.stream_list = stream_list
mbligha5630a52008-09-03 22:09:50 +000042
jadmanski0afbb632008-06-06 21:10:57 +000043 server_tag = server_ip + '#netperf-server'
44 client_tag = client_ip + '#netperf-client'
45 all = [server_tag, client_tag]
mbligha5630a52008-09-03 22:09:50 +000046
mbligha5630a52008-09-03 22:09:50 +000047 for num_streams in stream_list:
48 if role == 'server':
49 self.server_start()
50 try:
mbligh15b8a262008-09-16 16:50:49 +000051 # Wait up to ten minutes for the client to reach this
mbligh52fa6922008-09-05 20:37:08 +000052 # point.
mbligh15b8a262008-09-16 16:50:49 +000053 self.job.barrier(server_tag, 'start_%d' % num_streams,
54 600).rendevous(*all)
55 # Wait up to test_time + 5 minutes for the test to
mbligh52fa6922008-09-05 20:37:08 +000056 # complete
mbligh15b8a262008-09-16 16:50:49 +000057 self.job.barrier(server_tag, 'stop_%d' % num_streams,
58 test_time+300).rendevous(*all)
mbligha5630a52008-09-03 22:09:50 +000059 finally:
60 self.server_stop()
61
62 elif role == 'client':
mbligh15b8a262008-09-16 16:50:49 +000063 # Wait up to ten minutes for the server to start
64 self.job.barrier(client_tag, 'start_%d' % num_streams,
65 600).rendevous(*all)
mbligha5630a52008-09-03 22:09:50 +000066 self.client(server_ip, test, test_time, num_streams)
mbligh15b8a262008-09-16 16:50:49 +000067 # Wait up to 5 minutes for the server to also reach this point
68 self.job.barrier(client_tag, 'stop_%d' % num_streams,
69 300).rendevous(*all)
mbligha5630a52008-09-03 22:09:50 +000070 else:
71 raise error.TestError('invalid role specified')
mbligh54e56842006-09-23 06:02:54 +000072
mbligh56a91f02006-09-14 17:55:19 +000073
jadmanski0afbb632008-06-06 21:10:57 +000074 def server_start(self):
mbligh78be24a2008-06-13 21:40:08 +000075 utils.system('killall netserver', ignore_status=True)
mbligha5630a52008-09-03 22:09:50 +000076 self.results.append(utils.system_output(self.server_path,
77 retain_output=True))
mbligh56a91f02006-09-14 17:55:19 +000078
mbligh54e56842006-09-23 06:02:54 +000079
jadmanski0afbb632008-06-06 21:10:57 +000080 def server_stop(self):
mbligha5630a52008-09-03 22:09:50 +000081 utils.system('killall netserver', ignore_status=True)
mbligh56a91f02006-09-14 17:55:19 +000082
mbligh54e56842006-09-23 06:02:54 +000083
mbligha5630a52008-09-03 22:09:50 +000084 def client(self, server_ip, test, test_time, num_streams):
85 args = '-t %s -l %d' % (test, test_time)
86 cmd = self.client_path % (server_ip, args)
mbligh56a91f02006-09-14 17:55:19 +000087
mbligha5630a52008-09-03 22:09:50 +000088 try:
mbligh865ee822008-10-03 16:03:34 +000089 t0 = time.time()
mbligha5630a52008-09-03 22:09:50 +000090 self.results.append(utils.get_cpu_percentage(
mbligh52fa6922008-09-05 20:37:08 +000091 utils.system_output_parallel, [cmd]*num_streams,
92 timeout=test_time+60, retain_output=True))
mbligh865ee822008-10-03 16:03:34 +000093 t1 = time.time()
94
95 self.actual_times.append(t1 - t0)
96
mbligha5630a52008-09-03 22:09:50 +000097 except error.CmdError, e:
98 """ Catch errors due to timeout, but raise others
99 The actual error string is:
100 "Command did not complete within %d seconds"
101 called in function join_bg_job in the file common_lib/utils.py
mblighe8fa3af2006-09-28 23:14:56 +0000102
mbligha5630a52008-09-03 22:09:50 +0000103 Looking for 'within' is probably not the best way to do this but
104 works for now"""
105
mbligh52fa6922008-09-05 20:37:08 +0000106 if ('within' in e.additional_text
107 or 'non-zero' in e.additional_text):
mbligha5630a52008-09-03 22:09:50 +0000108 print e.additional_text
mbligh52fa6922008-09-05 20:37:08 +0000109 # Results are cpu%, outputs
110 self.results.append((0, None))
mbligh865ee822008-10-03 16:03:34 +0000111 self.actual_times.append(1)
mbligha5630a52008-09-03 22:09:50 +0000112 else:
113 raise
114
115
116 def postprocess(self):
mbligh52fa6922008-09-05 20:37:08 +0000117 if self.role == 'client':
118 if len(self.stream_list) != len(self.results):
119 raise error.TestError('Mismatched number of results')
120
121 function = None
122 keys = None
123
124 # Each of the functions return tuples in which the keys define
125 # what that item in the tuple represents
mblighb405b982008-09-10 20:35:52 +0000126 if self.test in ['TCP_STREAM', 'TCP_SENDFILE']:
mbligh52fa6922008-09-05 20:37:08 +0000127 function = self.process_tcp_stream
128 keys = ('Throughput',)
129 elif self.test == 'UDP_STREAM':
130 function = self.process_udp_stream
131 keys = ('Throughput', 'Errors')
132 elif self.test in ['TCP_RR', 'TCP_CRR', 'UDP_RR']:
133 function = self.process_request_response
134 keys = ('Transfer_Rate',)
135 else:
136 raise error.TestError('Unhandled test')
137
138 # self.results is a list of tuples. The first element in each
139 # tuple is the cpu utilization for that run, and the second
140 # element is a list containing the output for each stream in that
141 # run.
142 for i, streams in enumerate(self.stream_list):
143 attr = {'stream_count':streams}
144 keyval = {}
145 temp_vals = []
146 keyval['CPU'], outputs = self.results[i]
mbligh865ee822008-10-03 16:03:34 +0000147 actual_time = self.actual_times[i]
mbligh52fa6922008-09-05 20:37:08 +0000148
149 # Short circuit to handle errors due to client timeouts
150 if not outputs:
mbligh52fa6922008-09-05 20:37:08 +0000151 self.write_iteration_keyval(attr, keyval)
152 continue
153
154 for result in outputs:
155 temp_vals.append(function(result))
156
mbligh6d858fa2008-09-19 21:19:03 +0000157 # Compute the sum of elements returned from function which
mbligh52fa6922008-09-05 20:37:08 +0000158 # represent the string contained in keys
159 for j, key in enumerate(keys):
160 vals = [x[j] for x in temp_vals]
mbligh865ee822008-10-03 16:03:34 +0000161 # scale result by the actual time taken
162 keyval[key] = sum(vals)*self.test_time/actual_time
163
164 # record 'Efficiency' as perf/CPU
165 keyval['Efficieny'] = keyval[keys[0]]/keyval['CPU']
mbligh52fa6922008-09-05 20:37:08 +0000166
167 self.write_iteration_keyval(attr, keyval)
168
169
170 def process_tcp_stream(self, output):
mblighb405b982008-09-10 20:35:52 +0000171 """Parses the following (works for both TCP_STREAM and TCP_SENDFILE)
172 and returns a singleton containing throughput.
mbligh52fa6922008-09-05 20:37:08 +0000173
174 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
175 Recv Send Send
176 Socket Socket Message Elapsed
177 Size Size Size Time Throughput
178 bytes bytes bytes secs. 10^6bits/sec
179
180 87380 16384 16384 2.00 941.28
181 """
182
183 return float(output.splitlines()[6].split()[4]),
184
185
186 def process_udp_stream(self, output):
187 """Parses the following and returns a touple containing throughput
188 and the number of errors.
189
190 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
191 Socket Message Elapsed Messages
192 Size Size Time Okay Errors Throughput
193 bytes bytes secs # # 10^6bits/sec
194
195 129024 65507 2.00 3673 0 961.87
196 131072 2.00 3673 961.87
197 """
198
199 line_tokens = output.splitlines()[5].split()
200 return float(line_tokens[5]), int(line_tokens[4])
201
202
203 def process_request_response(self, output):
204 """Parses the following which works for both rr (TCP and UDP) and crr
205 tests and returns a singleton containing transfer rate.
206
207 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
208 Local /Remote
209 Socket Size Request Resp. Elapsed Trans.
210 Send Recv Size Size Time Rate
211 bytes Bytes bytes bytes secs. per sec
212
213 16384 87380 1 1 2.00 14118.53
214 16384 87380
215 """
216
217 return float(output.splitlines()[6].split()[5]),