mbligh | 865ee82 | 2008-10-03 16:03:34 +0000 | [diff] [blame^] | 1 | import os,time |
mbligh | 9f85792 | 2008-06-05 16:19:07 +0000 | [diff] [blame] | 2 | from autotest_lib.client.bin import test, autotest_utils |
| 3 | from autotest_lib.client.common_lib import utils, error |
| 4 | |
mbligh | 56a91f0 | 2006-09-14 17:55:19 +0000 | [diff] [blame] | 5 | |
| 6 | class netperf2(test.test): |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 7 | version = 2 |
mbligh | 56a91f0 | 2006-09-14 17:55:19 +0000 | [diff] [blame] | 8 | |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 9 | # ftp://ftp.netperf.org/netperf/netperf-2.4.4.tar.gz |
| 10 | def setup(self, tarball = 'netperf-2.4.4.tar.gz'): |
mbligh | 8b35285 | 2008-06-07 01:07:08 +0000 | [diff] [blame] | 11 | tarball = utils.unmap_url(self.bindir, tarball, self.tmpdir) |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 12 | autotest_utils.extract_tarball_to_dir(tarball, self.srcdir) |
| 13 | os.chdir(self.srcdir) |
mbligh | 56a91f0 | 2006-09-14 17:55:19 +0000 | [diff] [blame] | 14 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 15 | utils.system('./configure') |
| 16 | utils.system('make') |
mbligh | 54e5684 | 2006-09-23 06:02:54 +0000 | [diff] [blame] | 17 | |
| 18 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 19 | def initialize(self): |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 20 | 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 | |
mbligh | b405b98 | 2008-09-10 20:35:52 +0000 | [diff] [blame] | 28 | self.valid_tests = ['TCP_STREAM', 'TCP_RR', 'TCP_CRR', 'TCP_SENDFILE', |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 29 | 'UDP_STREAM', 'UDP_RR'] |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 30 | self.results = [] |
mbligh | 865ee82 | 2008-10-03 16:03:34 +0000 | [diff] [blame^] | 31 | self.actual_times = [] |
mbligh | 56a91f0 | 2006-09-14 17:55:19 +0000 | [diff] [blame] | 32 | |
mbligh | 6f5bbce | 2007-08-10 19:18:37 +0000 | [diff] [blame] | 33 | |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 34 | 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 |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 39 | self.test = test |
mbligh | 865ee82 | 2008-10-03 16:03:34 +0000 | [diff] [blame^] | 40 | self.test_time = test_time |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 41 | self.stream_list = stream_list |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 42 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 43 | server_tag = server_ip + '#netperf-server' |
| 44 | client_tag = client_ip + '#netperf-client' |
| 45 | all = [server_tag, client_tag] |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 46 | |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 47 | for num_streams in stream_list: |
| 48 | if role == 'server': |
| 49 | self.server_start() |
| 50 | try: |
mbligh | 15b8a26 | 2008-09-16 16:50:49 +0000 | [diff] [blame] | 51 | # Wait up to ten minutes for the client to reach this |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 52 | # point. |
mbligh | 15b8a26 | 2008-09-16 16:50:49 +0000 | [diff] [blame] | 53 | 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 |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 56 | # complete |
mbligh | 15b8a26 | 2008-09-16 16:50:49 +0000 | [diff] [blame] | 57 | self.job.barrier(server_tag, 'stop_%d' % num_streams, |
| 58 | test_time+300).rendevous(*all) |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 59 | finally: |
| 60 | self.server_stop() |
| 61 | |
| 62 | elif role == 'client': |
mbligh | 15b8a26 | 2008-09-16 16:50:49 +0000 | [diff] [blame] | 63 | # Wait up to ten minutes for the server to start |
| 64 | self.job.barrier(client_tag, 'start_%d' % num_streams, |
| 65 | 600).rendevous(*all) |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 66 | self.client(server_ip, test, test_time, num_streams) |
mbligh | 15b8a26 | 2008-09-16 16:50:49 +0000 | [diff] [blame] | 67 | # 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) |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 70 | else: |
| 71 | raise error.TestError('invalid role specified') |
mbligh | 54e5684 | 2006-09-23 06:02:54 +0000 | [diff] [blame] | 72 | |
mbligh | 56a91f0 | 2006-09-14 17:55:19 +0000 | [diff] [blame] | 73 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 74 | def server_start(self): |
mbligh | 78be24a | 2008-06-13 21:40:08 +0000 | [diff] [blame] | 75 | utils.system('killall netserver', ignore_status=True) |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 76 | self.results.append(utils.system_output(self.server_path, |
| 77 | retain_output=True)) |
mbligh | 56a91f0 | 2006-09-14 17:55:19 +0000 | [diff] [blame] | 78 | |
mbligh | 54e5684 | 2006-09-23 06:02:54 +0000 | [diff] [blame] | 79 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 80 | def server_stop(self): |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 81 | utils.system('killall netserver', ignore_status=True) |
mbligh | 56a91f0 | 2006-09-14 17:55:19 +0000 | [diff] [blame] | 82 | |
mbligh | 54e5684 | 2006-09-23 06:02:54 +0000 | [diff] [blame] | 83 | |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 84 | 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) |
mbligh | 56a91f0 | 2006-09-14 17:55:19 +0000 | [diff] [blame] | 87 | |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 88 | try: |
mbligh | 865ee82 | 2008-10-03 16:03:34 +0000 | [diff] [blame^] | 89 | t0 = time.time() |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 90 | self.results.append(utils.get_cpu_percentage( |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 91 | utils.system_output_parallel, [cmd]*num_streams, |
| 92 | timeout=test_time+60, retain_output=True)) |
mbligh | 865ee82 | 2008-10-03 16:03:34 +0000 | [diff] [blame^] | 93 | t1 = time.time() |
| 94 | |
| 95 | self.actual_times.append(t1 - t0) |
| 96 | |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 97 | 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 |
mbligh | e8fa3af | 2006-09-28 23:14:56 +0000 | [diff] [blame] | 102 | |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 103 | Looking for 'within' is probably not the best way to do this but |
| 104 | works for now""" |
| 105 | |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 106 | if ('within' in e.additional_text |
| 107 | or 'non-zero' in e.additional_text): |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 108 | print e.additional_text |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 109 | # Results are cpu%, outputs |
| 110 | self.results.append((0, None)) |
mbligh | 865ee82 | 2008-10-03 16:03:34 +0000 | [diff] [blame^] | 111 | self.actual_times.append(1) |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 112 | else: |
| 113 | raise |
| 114 | |
| 115 | |
| 116 | def postprocess(self): |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 117 | 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 |
mbligh | b405b98 | 2008-09-10 20:35:52 +0000 | [diff] [blame] | 126 | if self.test in ['TCP_STREAM', 'TCP_SENDFILE']: |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 127 | 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] |
mbligh | 865ee82 | 2008-10-03 16:03:34 +0000 | [diff] [blame^] | 147 | actual_time = self.actual_times[i] |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 148 | |
| 149 | # Short circuit to handle errors due to client timeouts |
| 150 | if not outputs: |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 151 | self.write_iteration_keyval(attr, keyval) |
| 152 | continue |
| 153 | |
| 154 | for result in outputs: |
| 155 | temp_vals.append(function(result)) |
| 156 | |
mbligh | 6d858fa | 2008-09-19 21:19:03 +0000 | [diff] [blame] | 157 | # Compute the sum of elements returned from function which |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 158 | # represent the string contained in keys |
| 159 | for j, key in enumerate(keys): |
| 160 | vals = [x[j] for x in temp_vals] |
mbligh | 865ee82 | 2008-10-03 16:03:34 +0000 | [diff] [blame^] | 161 | # 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'] |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 166 | |
| 167 | self.write_iteration_keyval(attr, keyval) |
| 168 | |
| 169 | |
| 170 | def process_tcp_stream(self, output): |
mbligh | b405b98 | 2008-09-10 20:35:52 +0000 | [diff] [blame] | 171 | """Parses the following (works for both TCP_STREAM and TCP_SENDFILE) |
| 172 | and returns a singleton containing throughput. |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 173 | |
| 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]), |