mbligh | 34d0117 | 2008-06-05 16:26:31 +0000 | [diff] [blame] | 1 | import os |
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 | 56a91f0 | 2006-09-14 17:55:19 +0000 | [diff] [blame] | 31 | |
mbligh | 6f5bbce | 2007-08-10 19:18:37 +0000 | [diff] [blame] | 32 | |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 33 | 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 |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 38 | self.test = test |
| 39 | self.stream_list = stream_list |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 40 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 41 | server_tag = server_ip + '#netperf-server' |
| 42 | client_tag = client_ip + '#netperf-client' |
| 43 | all = [server_tag, client_tag] |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 44 | |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 45 | for num_streams in stream_list: |
| 46 | if role == 'server': |
| 47 | self.server_start() |
| 48 | try: |
mbligh | 15b8a26 | 2008-09-16 16:50:49 +0000 | [diff] [blame] | 49 | # Wait up to ten minutes for the client to reach this |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 50 | # point. |
mbligh | 15b8a26 | 2008-09-16 16:50:49 +0000 | [diff] [blame] | 51 | self.job.barrier(server_tag, 'start_%d' % num_streams, |
| 52 | 600).rendevous(*all) |
| 53 | # Wait up to test_time + 5 minutes for the test to |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 54 | # complete |
mbligh | 15b8a26 | 2008-09-16 16:50:49 +0000 | [diff] [blame] | 55 | self.job.barrier(server_tag, 'stop_%d' % num_streams, |
| 56 | test_time+300).rendevous(*all) |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 57 | finally: |
| 58 | self.server_stop() |
| 59 | |
| 60 | elif role == 'client': |
mbligh | 15b8a26 | 2008-09-16 16:50:49 +0000 | [diff] [blame] | 61 | # Wait up to ten minutes for the server to start |
| 62 | self.job.barrier(client_tag, 'start_%d' % num_streams, |
| 63 | 600).rendevous(*all) |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 64 | self.client(server_ip, test, test_time, num_streams) |
mbligh | 15b8a26 | 2008-09-16 16:50:49 +0000 | [diff] [blame] | 65 | # Wait up to 5 minutes for the server to also reach this point |
| 66 | self.job.barrier(client_tag, 'stop_%d' % num_streams, |
| 67 | 300).rendevous(*all) |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 68 | else: |
| 69 | raise error.TestError('invalid role specified') |
mbligh | 54e5684 | 2006-09-23 06:02:54 +0000 | [diff] [blame] | 70 | |
mbligh | 56a91f0 | 2006-09-14 17:55:19 +0000 | [diff] [blame] | 71 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 72 | def server_start(self): |
mbligh | 78be24a | 2008-06-13 21:40:08 +0000 | [diff] [blame] | 73 | utils.system('killall netserver', ignore_status=True) |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 74 | self.results.append(utils.system_output(self.server_path, |
| 75 | retain_output=True)) |
mbligh | 56a91f0 | 2006-09-14 17:55:19 +0000 | [diff] [blame] | 76 | |
mbligh | 54e5684 | 2006-09-23 06:02:54 +0000 | [diff] [blame] | 77 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 78 | def server_stop(self): |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 79 | utils.system('killall netserver', ignore_status=True) |
mbligh | 56a91f0 | 2006-09-14 17:55:19 +0000 | [diff] [blame] | 80 | |
mbligh | 54e5684 | 2006-09-23 06:02:54 +0000 | [diff] [blame] | 81 | |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 82 | def client(self, server_ip, test, test_time, num_streams): |
| 83 | args = '-t %s -l %d' % (test, test_time) |
| 84 | cmd = self.client_path % (server_ip, args) |
mbligh | 56a91f0 | 2006-09-14 17:55:19 +0000 | [diff] [blame] | 85 | |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 86 | try: |
| 87 | self.results.append(utils.get_cpu_percentage( |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 88 | utils.system_output_parallel, [cmd]*num_streams, |
| 89 | timeout=test_time+60, retain_output=True)) |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 90 | except error.CmdError, e: |
| 91 | """ Catch errors due to timeout, but raise others |
| 92 | The actual error string is: |
| 93 | "Command did not complete within %d seconds" |
| 94 | called in function join_bg_job in the file common_lib/utils.py |
mbligh | e8fa3af | 2006-09-28 23:14:56 +0000 | [diff] [blame] | 95 | |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 96 | Looking for 'within' is probably not the best way to do this but |
| 97 | works for now""" |
| 98 | |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 99 | if ('within' in e.additional_text |
| 100 | or 'non-zero' in e.additional_text): |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 101 | print e.additional_text |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 102 | # Results are cpu%, outputs |
| 103 | self.results.append((0, None)) |
mbligh | a5630a5 | 2008-09-03 22:09:50 +0000 | [diff] [blame] | 104 | else: |
| 105 | raise |
| 106 | |
| 107 | |
| 108 | def postprocess(self): |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 109 | if self.role == 'client': |
| 110 | if len(self.stream_list) != len(self.results): |
| 111 | raise error.TestError('Mismatched number of results') |
| 112 | |
| 113 | function = None |
| 114 | keys = None |
| 115 | |
| 116 | # Each of the functions return tuples in which the keys define |
| 117 | # what that item in the tuple represents |
mbligh | b405b98 | 2008-09-10 20:35:52 +0000 | [diff] [blame] | 118 | if self.test in ['TCP_STREAM', 'TCP_SENDFILE']: |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 119 | function = self.process_tcp_stream |
| 120 | keys = ('Throughput',) |
| 121 | elif self.test == 'UDP_STREAM': |
| 122 | function = self.process_udp_stream |
| 123 | keys = ('Throughput', 'Errors') |
| 124 | elif self.test in ['TCP_RR', 'TCP_CRR', 'UDP_RR']: |
| 125 | function = self.process_request_response |
| 126 | keys = ('Transfer_Rate',) |
| 127 | else: |
| 128 | raise error.TestError('Unhandled test') |
| 129 | |
| 130 | # self.results is a list of tuples. The first element in each |
| 131 | # tuple is the cpu utilization for that run, and the second |
| 132 | # element is a list containing the output for each stream in that |
| 133 | # run. |
| 134 | for i, streams in enumerate(self.stream_list): |
| 135 | attr = {'stream_count':streams} |
| 136 | keyval = {} |
| 137 | temp_vals = [] |
| 138 | keyval['CPU'], outputs = self.results[i] |
| 139 | |
| 140 | # Short circuit to handle errors due to client timeouts |
| 141 | if not outputs: |
| 142 | for key in keys: |
| 143 | keyval[key] = 0 |
| 144 | self.write_iteration_keyval(attr, keyval) |
| 145 | continue |
| 146 | |
| 147 | for result in outputs: |
| 148 | temp_vals.append(function(result)) |
| 149 | |
mbligh | 6d858fa | 2008-09-19 21:19:03 +0000 | [diff] [blame^] | 150 | # Compute the sum of elements returned from function which |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 151 | # represent the string contained in keys |
| 152 | for j, key in enumerate(keys): |
| 153 | vals = [x[j] for x in temp_vals] |
mbligh | 6d858fa | 2008-09-19 21:19:03 +0000 | [diff] [blame^] | 154 | keyval[key] = sum(vals) |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 155 | |
| 156 | self.write_iteration_keyval(attr, keyval) |
| 157 | |
| 158 | |
| 159 | def process_tcp_stream(self, output): |
mbligh | b405b98 | 2008-09-10 20:35:52 +0000 | [diff] [blame] | 160 | """Parses the following (works for both TCP_STREAM and TCP_SENDFILE) |
| 161 | and returns a singleton containing throughput. |
mbligh | 52fa692 | 2008-09-05 20:37:08 +0000 | [diff] [blame] | 162 | |
| 163 | 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 |
| 164 | Recv Send Send |
| 165 | Socket Socket Message Elapsed |
| 166 | Size Size Size Time Throughput |
| 167 | bytes bytes bytes secs. 10^6bits/sec |
| 168 | |
| 169 | 87380 16384 16384 2.00 941.28 |
| 170 | """ |
| 171 | |
| 172 | return float(output.splitlines()[6].split()[4]), |
| 173 | |
| 174 | |
| 175 | def process_udp_stream(self, output): |
| 176 | """Parses the following and returns a touple containing throughput |
| 177 | and the number of errors. |
| 178 | |
| 179 | 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 |
| 180 | Socket Message Elapsed Messages |
| 181 | Size Size Time Okay Errors Throughput |
| 182 | bytes bytes secs # # 10^6bits/sec |
| 183 | |
| 184 | 129024 65507 2.00 3673 0 961.87 |
| 185 | 131072 2.00 3673 961.87 |
| 186 | """ |
| 187 | |
| 188 | line_tokens = output.splitlines()[5].split() |
| 189 | return float(line_tokens[5]), int(line_tokens[4]) |
| 190 | |
| 191 | |
| 192 | def process_request_response(self, output): |
| 193 | """Parses the following which works for both rr (TCP and UDP) and crr |
| 194 | tests and returns a singleton containing transfer rate. |
| 195 | |
| 196 | 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 |
| 197 | Local /Remote |
| 198 | Socket Size Request Resp. Elapsed Trans. |
| 199 | Send Recv Size Size Time Rate |
| 200 | bytes Bytes bytes bytes secs. per sec |
| 201 | |
| 202 | 16384 87380 1 1 2.00 14118.53 |
| 203 | 16384 87380 |
| 204 | """ |
| 205 | |
| 206 | return float(output.splitlines()[6].split()[5]), |