blob: 87507a54b85799cc725a926f6084ba2584854774 [file] [log] [blame]
mbligh44394242009-06-15 21:31:32 +00001import os, time, re, logging
mbligh67a72f92009-01-13 19:31:08 +00002from autotest_lib.client.bin import test, utils
mbligh44394242009-06-15 21:31:32 +00003from autotest_lib.client.bin.net import net_utils
mbligh67a72f92009-01-13 19:31:08 +00004from autotest_lib.client.common_lib import error
mbligh9f857922008-06-05 16:19:07 +00005
mbligh44394242009-06-15 21:31:32 +00006MPSTAT_IX = 0
7NETPERF_IX = 1
mbligh56a91f02006-09-14 17:55:19 +00008
9class netperf2(test.test):
Kelly Lucas8acfcfa2010-03-01 10:19:31 -080010 version = 4
mbligh56a91f02006-09-14 17:55:19 +000011
lmr0570b972010-05-25 20:07:00 +000012 # ftp://ftp.netperf.org/netperf/netperf-2.4.5.tar.bz2
13 def setup(self, tarball = 'netperf-2.4.5.tar.bz2'):
mbligh44394242009-06-15 21:31:32 +000014 self.job.require_gcc()
mbligh8b352852008-06-07 01:07:08 +000015 tarball = utils.unmap_url(self.bindir, tarball, self.tmpdir)
mbligh53da18e2009-01-05 21:13:26 +000016 utils.extract_tarball_to_dir(tarball, self.srcdir)
jadmanski0afbb632008-06-06 21:10:57 +000017 os.chdir(self.srcdir)
mbligh56a91f02006-09-14 17:55:19 +000018
mbligh44394242009-06-15 21:31:32 +000019 utils.system('patch -p0 < ../wait_before_data.patch')
Kenneth Watersf5ca5ac2010-03-24 11:28:55 -070020 utils.configure()
Eric Li6f27d4f2010-09-29 10:55:17 -070021 utils.make()
mbligh54e56842006-09-23 06:02:54 +000022
Kelly Lucas8acfcfa2010-03-01 10:19:31 -080023 self.job.setup_dep(['sysstat'])
24
mbligh54e56842006-09-23 06:02:54 +000025
jadmanski0afbb632008-06-06 21:10:57 +000026 def initialize(self):
mbligh44394242009-06-15 21:31:32 +000027 self.server_prog = '%s&' % os.path.join(self.srcdir, 'src/netserver')
28 self.client_prog = '%s' % os.path.join(self.srcdir, 'src/netperf')
29 self.valid_tests = ['TCP_STREAM', 'TCP_MAERTS', 'TCP_RR', 'TCP_CRR',
30 'TCP_SENDFILE', 'UDP_STREAM', 'UDP_RR']
mbligha5630a52008-09-03 22:09:50 +000031 self.results = []
mbligh865ee822008-10-03 16:03:34 +000032 self.actual_times = []
mbligh44394242009-06-15 21:31:32 +000033 self.netif = ''
34 self.network = net_utils.network()
35 self.network_utils = net_utils.network_utils()
mbligh56a91f02006-09-14 17:55:19 +000036
Kelly Lucasae352272010-03-05 15:42:10 -080037 dep = 'sysstat'
38 dep_dir = os.path.join(self.autodir, 'deps', dep)
39 self.job.install_pkg(dep, 'dep', dep_dir)
40
mbligh6f5bbce2007-08-10 19:18:37 +000041
mbligh44394242009-06-15 21:31:32 +000042 def run_once(self, server_ip, client_ip, role, test = 'TCP_STREAM',
43 test_time = 15, stream_list = [1], test_specific_args = '',
44 cpu_affinity = '', dev = '', bidi = False, wait_time = 5):
45 """
46 server_ip: IP address of host running netserver
47 client_ip: IP address of host running netperf client(s)
48 role: 'client' or 'server'
49 test: one of TCP_STREAM, TCP_MEARTS, TCP_RR, TCP_CRR, TCP_SENDFILE,
50 UDP_STREAM or UDP_RR
51 test_time: time to run the test for in seconds
52 stream_list: list of number of netperf streams to launch
53 test_specific_args: Optional test specific args. For example to set
54 the request,response size for RR tests to 200,100, set it
55 to: '-- -r 200,100'. Or, to set the send buffer size of STREAM
56 tests to 200, set it to: '-- -m 200'
57 cpu_affinity: netperf/netserver processes will get taskset to the
58 cpu_affinity. cpu_affinity is specified as a bitmask in hex
59 without the leading 0x. For example, to run on CPUs 0 & 5,
60 cpu_affinity needs to be '21'
61 dev: device on which to run traffic on. For example, to run on
62 inteface eth1, set it to 'eth1'.
63 bidi: bi-directional traffic. This is supported for TCP_STREAM
64 test only. The RR & CRR tests are bi-directional by nature.
65 wait_time: Time to wait after establishing data/control connections
66 but before sending data traffic.
67 """
mbligha5630a52008-09-03 22:09:50 +000068 if test not in self.valid_tests:
69 raise error.TestError('invalid test specified')
70 self.role = role
mbligh52fa6922008-09-05 20:37:08 +000071 self.test = test
mbligh865ee822008-10-03 16:03:34 +000072 self.test_time = test_time
mbligh44394242009-06-15 21:31:32 +000073 self.wait_time = wait_time
mbligh52fa6922008-09-05 20:37:08 +000074 self.stream_list = stream_list
mbligh44394242009-06-15 21:31:32 +000075 self.bidi = bidi
mbligha5630a52008-09-03 22:09:50 +000076
jadmanski0afbb632008-06-06 21:10:57 +000077 server_tag = server_ip + '#netperf-server'
78 client_tag = client_ip + '#netperf-client'
79 all = [server_tag, client_tag]
mbligha5630a52008-09-03 22:09:50 +000080
mbligh44394242009-06-15 21:31:32 +000081 # If a specific device has been requested, configure it.
82 if dev:
83 timeout = 60
84 if role == 'server':
85 self.configure_interface(dev, server_ip)
86 self.ping(client_ip, timeout)
87 else:
88 self.configure_interface(dev, client_ip)
89 self.ping(server_ip, timeout)
90
mbligha5630a52008-09-03 22:09:50 +000091 for num_streams in stream_list:
92 if role == 'server':
mbligh44394242009-06-15 21:31:32 +000093 self.server_start(cpu_affinity)
mbligha5630a52008-09-03 22:09:50 +000094 try:
mbligh15b8a262008-09-16 16:50:49 +000095 # Wait up to ten minutes for the client to reach this
mbligh52fa6922008-09-05 20:37:08 +000096 # point.
mbligh15b8a262008-09-16 16:50:49 +000097 self.job.barrier(server_tag, 'start_%d' % num_streams,
mbligh44394242009-06-15 21:31:32 +000098 600).rendezvous(*all)
mbligh15b8a262008-09-16 16:50:49 +000099 # Wait up to test_time + 5 minutes for the test to
mbligh52fa6922008-09-05 20:37:08 +0000100 # complete
mbligh15b8a262008-09-16 16:50:49 +0000101 self.job.barrier(server_tag, 'stop_%d' % num_streams,
mbligh44394242009-06-15 21:31:32 +0000102 test_time+300).rendezvous(*all)
mbligha5630a52008-09-03 22:09:50 +0000103 finally:
104 self.server_stop()
105
106 elif role == 'client':
mbligh15b8a262008-09-16 16:50:49 +0000107 # Wait up to ten minutes for the server to start
108 self.job.barrier(client_tag, 'start_%d' % num_streams,
mbligh44394242009-06-15 21:31:32 +0000109 600).rendezvous(*all)
110 self.client(server_ip, test, test_time, num_streams,
111 test_specific_args, cpu_affinity)
mbligh15b8a262008-09-16 16:50:49 +0000112 # Wait up to 5 minutes for the server to also reach this point
113 self.job.barrier(client_tag, 'stop_%d' % num_streams,
mbligh44394242009-06-15 21:31:32 +0000114 300).rendezvous(*all)
mbligha5630a52008-09-03 22:09:50 +0000115 else:
116 raise error.TestError('invalid role specified')
mbligh54e56842006-09-23 06:02:54 +0000117
mbligh44394242009-06-15 21:31:32 +0000118 self.restore_interface()
mbligh56a91f02006-09-14 17:55:19 +0000119
mbligh44394242009-06-15 21:31:32 +0000120
121 def configure_interface(self, dev, ip_addr):
122 self.netif = net_utils.netif(dev)
123 self.netif.up()
124 if self.netif.get_ipaddr() != ip_addr:
125 self.netif.set_ipaddr(ip_addr)
126
127
128 def restore_interface(self):
129 if self.netif:
130 self.netif.restore()
131
132
133 def server_start(self, cpu_affinity):
mbligh78be24a2008-06-13 21:40:08 +0000134 utils.system('killall netserver', ignore_status=True)
mbligh44394242009-06-15 21:31:32 +0000135 cmd = self.server_prog
136 if cpu_affinity:
137 cmd = 'taskset %s %s' % (cpu_affinity, cmd)
138
139 self.results.append(utils.system_output(cmd, retain_output=True))
mbligh56a91f02006-09-14 17:55:19 +0000140
mbligh54e56842006-09-23 06:02:54 +0000141
jadmanski0afbb632008-06-06 21:10:57 +0000142 def server_stop(self):
mbligha5630a52008-09-03 22:09:50 +0000143 utils.system('killall netserver', ignore_status=True)
mbligh56a91f02006-09-14 17:55:19 +0000144
mbligh54e56842006-09-23 06:02:54 +0000145
mbligh44394242009-06-15 21:31:32 +0000146 def client(self, server_ip, test, test_time, num_streams,
147 test_specific_args, cpu_affinity):
148 args = '-H %s -t %s -l %d' % (server_ip, test, test_time)
Kelly Lucas8acfcfa2010-03-01 10:19:31 -0800149
Kelly Lucasae352272010-03-05 15:42:10 -0800150 if os.path.exists('/usr/bin/mpstat'):
151 mpstat = '/usr/bin/mpstat'
152 else:
153 mpstat = os.path.join(self.autodir + '/deps/sysstat/src/mpstat')
Kelly Lucas8acfcfa2010-03-01 10:19:31 -0800154
mbligh44394242009-06-15 21:31:32 +0000155 if self.wait_time:
156 args += ' -s %d ' % self.wait_time
157
158 # Append the test specific arguments.
159 if test_specific_args:
160 args += ' ' + test_specific_args
161
162 cmd = '%s %s' % (self.client_prog, args)
163
164 if cpu_affinity:
165 cmd = 'taskset %s %s' % (cpu_affinity, cmd)
mbligh56a91f02006-09-14 17:55:19 +0000166
mbligha5630a52008-09-03 22:09:50 +0000167 try:
mbligh44394242009-06-15 21:31:32 +0000168 cmds = []
169
170 # Get 5 mpstat samples. Since tests with large number of streams
171 # take a long time to start up all the streams, we'll toss out the
172 # first and last sample when recording results
173 interval = max(1, test_time / 5)
Kelly Lucasae352272010-03-05 15:42:10 -0800174 cmds.append('sleep %d && %s -P ALL %s 5' % (self.wait_time, mpstat,
Eric Lia82dc352011-02-23 13:15:52 -0800175 interval))
mbligh44394242009-06-15 21:31:32 +0000176
177 # Add the netperf commands
178 for i in xrange(num_streams):
179 cmds.append(cmd)
180 if self.bidi and test == 'TCP_STREAM':
181 cmds.append(cmd.replace('TCP_STREAM', 'TCP_MAERTS'))
182
mbligh865ee822008-10-03 16:03:34 +0000183 t0 = time.time()
mbligh44394242009-06-15 21:31:32 +0000184 # Launch all commands in parallel
185 out = utils.run_parallel(cmds, timeout=test_time + 500,
186 ignore_status=True)
mbligh865ee822008-10-03 16:03:34 +0000187 t1 = time.time()
188
mbligh44394242009-06-15 21:31:32 +0000189 self.results.append(out)
190 self.actual_times.append(t1 - t0 - self.wait_time)
191 # Log test output
192 logging.info(out)
mbligh865ee822008-10-03 16:03:34 +0000193
mbligha5630a52008-09-03 22:09:50 +0000194 except error.CmdError, e:
195 """ Catch errors due to timeout, but raise others
196 The actual error string is:
197 "Command did not complete within %d seconds"
198 called in function join_bg_job in the file common_lib/utils.py
mblighe8fa3af2006-09-28 23:14:56 +0000199
mbligha5630a52008-09-03 22:09:50 +0000200 Looking for 'within' is probably not the best way to do this but
201 works for now"""
202
mbligh52fa6922008-09-05 20:37:08 +0000203 if ('within' in e.additional_text
204 or 'non-zero' in e.additional_text):
lmr4c607f22009-06-02 11:50:38 +0000205 logging.debug(e.additional_text)
mbligh44394242009-06-15 21:31:32 +0000206 self.results.append(None)
mbligh865ee822008-10-03 16:03:34 +0000207 self.actual_times.append(1)
mbligha5630a52008-09-03 22:09:50 +0000208 else:
209 raise
210
211
212 def postprocess(self):
mbligh52fa6922008-09-05 20:37:08 +0000213 if self.role == 'client':
mbligh44394242009-06-15 21:31:32 +0000214 # if profilers are enabled, the test gets runs twice
215 if (len(self.stream_list) != len(self.results) and
216 2*len(self.stream_list) != len(self.results)):
mbligh52fa6922008-09-05 20:37:08 +0000217 raise error.TestError('Mismatched number of results')
218
219 function = None
220 keys = None
221
222 # Each of the functions return tuples in which the keys define
223 # what that item in the tuple represents
mbligh44394242009-06-15 21:31:32 +0000224 if self.test in ['TCP_STREAM', 'TCP_MAERTS', 'TCP_SENDFILE']:
mbligh52fa6922008-09-05 20:37:08 +0000225 function = self.process_tcp_stream
226 keys = ('Throughput',)
227 elif self.test == 'UDP_STREAM':
228 function = self.process_udp_stream
229 keys = ('Throughput', 'Errors')
230 elif self.test in ['TCP_RR', 'TCP_CRR', 'UDP_RR']:
231 function = self.process_request_response
232 keys = ('Transfer_Rate',)
233 else:
234 raise error.TestError('Unhandled test')
235
mbligh52fa6922008-09-05 20:37:08 +0000236 for i, streams in enumerate(self.stream_list):
237 attr = {'stream_count':streams}
238 keyval = {}
239 temp_vals = []
mbligh52fa6922008-09-05 20:37:08 +0000240
241 # Short circuit to handle errors due to client timeouts
mbligh44394242009-06-15 21:31:32 +0000242 if not self.results[i]:
mbligh52fa6922008-09-05 20:37:08 +0000243 self.write_iteration_keyval(attr, keyval)
244 continue
245
mbligh44394242009-06-15 21:31:32 +0000246 # Collect output of netperf sessions
247 failed_streams_count = 0
248 for result in self.results[i][NETPERF_IX:]:
249 if result.exit_status:
250 failed_streams_count += 1
251 else:
252 temp_vals.append(function(result.stdout))
253
254 keyval['Failed_streams_count'] = failed_streams_count
255
256 # Process mpstat output
257 mpstat_out = self.results[i][MPSTAT_IX].stdout
258 cpu_stats = self.network_utils.process_mpstat(mpstat_out, 5)
259 keyval['CPU_C'] = 100 - cpu_stats['idle']
260 keyval['CPU_C_SYS'] = cpu_stats['sys']
261 keyval['CPU_C_HI'] = cpu_stats['irq']
262 keyval['CPU_C_SI'] = cpu_stats['soft']
263 keyval['INTRS_C'] = cpu_stats['intr/s']
264
265 actual_time = self.actual_times[i]
266 keyval['actual_time'] = actual_time
267 logging.info('actual_time: %f', actual_time)
mbligh52fa6922008-09-05 20:37:08 +0000268
mbligh6d858fa2008-09-19 21:19:03 +0000269 # Compute the sum of elements returned from function which
mbligh52fa6922008-09-05 20:37:08 +0000270 # represent the string contained in keys
271 for j, key in enumerate(keys):
272 vals = [x[j] for x in temp_vals]
mbligh865ee822008-10-03 16:03:34 +0000273 # scale result by the actual time taken
mbligh44394242009-06-15 21:31:32 +0000274 keyval[key] = sum(vals)
mbligh865ee822008-10-03 16:03:34 +0000275
276 # record 'Efficiency' as perf/CPU
mbligh44394242009-06-15 21:31:32 +0000277 if keyval['CPU_C'] != 0:
278 keyval['Efficieny_C'] = keyval[keys[0]]/keyval['CPU_C']
279 else:
280 keyval['Efficieny_C'] = keyval[keys[0]]
mbligh52fa6922008-09-05 20:37:08 +0000281
282 self.write_iteration_keyval(attr, keyval)
283
284
285 def process_tcp_stream(self, output):
mbligh44394242009-06-15 21:31:32 +0000286 """Parses the following (works for both TCP_STREAM, TCP_MAERTS and
287 TCP_SENDFILE) and returns a singleton containing throughput.
mbligh52fa6922008-09-05 20:37:08 +0000288
mbligh44394242009-06-15 21:31:32 +0000289 TCP STREAM TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to foo.bar.com \
290 (10.10.10.3) port 0 AF_INET
mbligh52fa6922008-09-05 20:37:08 +0000291 Recv Send Send
292 Socket Socket Message Elapsed
293 Size Size Size Time Throughput
294 bytes bytes bytes secs. 10^6bits/sec
295
296 87380 16384 16384 2.00 941.28
297 """
298
299 return float(output.splitlines()[6].split()[4]),
300
301
302 def process_udp_stream(self, output):
303 """Parses the following and returns a touple containing throughput
304 and the number of errors.
305
mbligh44394242009-06-15 21:31:32 +0000306 UDP UNIDIRECTIONAL SEND TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET \
307 to foo.bar.com (10.10.10.3) port 0 AF_INET
mbligh52fa6922008-09-05 20:37:08 +0000308 Socket Message Elapsed Messages
309 Size Size Time Okay Errors Throughput
310 bytes bytes secs # # 10^6bits/sec
311
312 129024 65507 2.00 3673 0 961.87
313 131072 2.00 3673 961.87
314 """
315
316 line_tokens = output.splitlines()[5].split()
317 return float(line_tokens[5]), int(line_tokens[4])
318
319
320 def process_request_response(self, output):
321 """Parses the following which works for both rr (TCP and UDP) and crr
322 tests and returns a singleton containing transfer rate.
323
mbligh44394242009-06-15 21:31:32 +0000324 TCP REQUEST/RESPONSE TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET \
325 to foo.bar.com (10.10.10.3) port 0 AF_INET
mbligh52fa6922008-09-05 20:37:08 +0000326 Local /Remote
327 Socket Size Request Resp. Elapsed Trans.
328 Send Recv Size Size Time Rate
329 bytes Bytes bytes bytes secs. per sec
330
331 16384 87380 1 1 2.00 14118.53
332 16384 87380
333 """
334
335 return float(output.splitlines()[6].split()[5]),
mbligh44394242009-06-15 21:31:32 +0000336
337
338 def ping(self, ip, timeout):
339 curr_time = time.time()
340 end_time = curr_time + timeout
341 while curr_time < end_time:
342 if not os.system('ping -c 1 ' + ip):
343 # Ping succeeded
344 return
345 # Ping failed. Lets sleep a bit and try again.
346 time.sleep(5)
347 curr_time = time.time()
348
349 return