lmr | 4c607f2 | 2009-06-02 11:50:38 +0000 | [diff] [blame] | 1 | import os, time, logging |
mbligh | 53da18e | 2009-01-05 21:13:26 +0000 | [diff] [blame] | 2 | from autotest_lib.client.bin import test, utils |
| 3 | from autotest_lib.client.common_lib import error |
mbligh | cf8e0b7 | 2008-09-12 02:14:29 +0000 | [diff] [blame] | 4 | |
| 5 | |
| 6 | class netpipe(test.test): |
| 7 | version = 1 |
| 8 | NP_FILE = '/tmp/np.out' |
| 9 | |
| 10 | # http://www.scl.ameslab.gov/netpipe/code/NetPIPE-3.7.1.tar.gz |
| 11 | def setup(self, tarball='NetPIPE-3.7.1.tar.gz'): |
| 12 | tarball = utils.unmap_url(self.bindir, tarball, self.tmpdir) |
mbligh | 53da18e | 2009-01-05 21:13:26 +0000 | [diff] [blame] | 13 | utils.extract_tarball_to_dir(tarball, self.srcdir) |
mbligh | cf8e0b7 | 2008-09-12 02:14:29 +0000 | [diff] [blame] | 14 | os.chdir(self.srcdir) |
| 15 | utils.system('make') |
| 16 | |
| 17 | |
| 18 | def initialize(self): |
| 19 | self.job.require_gcc() |
| 20 | |
| 21 | # Add arguments later |
| 22 | self.server_path = '%s %%s' % os.path.join(self.srcdir, 'NPtcp') |
| 23 | # Add server_ip and arguments later |
| 24 | base_path = os.path.join(self.srcdir, 'NPtcp -h') |
| 25 | self.client_path = '%s %%s -o %s %%s' % (base_path, self.NP_FILE) |
| 26 | self.results = [] |
| 27 | |
| 28 | def cleanup(self): |
| 29 | # Just in case... |
| 30 | utils.system('killall -9 NPtcp', ignore_status=True) |
| 31 | |
| 32 | |
| 33 | def run_once(self, server_ip, client_ip, role, bidirectional=False, |
| 34 | buffer_size=None, upper_bound=None, |
| 35 | perturbation_size=3): |
| 36 | self.role = role |
| 37 | |
| 38 | # Any arguments used must be the same on both the client and the server |
| 39 | args = '-p %d ' % perturbation_size |
| 40 | if bidirectional: |
| 41 | args += '-2 ' |
| 42 | if buffer_size: |
| 43 | args += '-b %d ' % buffer_size |
| 44 | if upper_bound: |
| 45 | args += '-u %d ' % upper_bound |
| 46 | |
| 47 | |
| 48 | server_tag = server_ip + '#netpipe-server' |
| 49 | client_tag = client_ip + '#netpipe-client' |
| 50 | all = [server_tag, client_tag] |
| 51 | |
| 52 | if role == 'server': |
mbligh | 15b8a26 | 2008-09-16 16:50:49 +0000 | [diff] [blame] | 53 | # Wait up to ten minutes for both to reach this point. |
mbligh | 9c12f77 | 2009-06-22 19:03:55 +0000 | [diff] [blame^] | 54 | self.job.barrier(server_tag, 'start', 600).rendezvous(*all) |
mbligh | cf8e0b7 | 2008-09-12 02:14:29 +0000 | [diff] [blame] | 55 | self.server_start(args) |
| 56 | # Both the client and server should be closed so just to make |
mbligh | 15b8a26 | 2008-09-16 16:50:49 +0000 | [diff] [blame] | 57 | # sure they are both at the same point wait at most five minutes. |
mbligh | 9c12f77 | 2009-06-22 19:03:55 +0000 | [diff] [blame^] | 58 | self.job.barrier(server_tag, 'stop', 300).rendezvous(*all) |
mbligh | cf8e0b7 | 2008-09-12 02:14:29 +0000 | [diff] [blame] | 59 | elif role == 'client': |
mbligh | 15b8a26 | 2008-09-16 16:50:49 +0000 | [diff] [blame] | 60 | # Wait up to ten minutes for the server to start |
mbligh | 9c12f77 | 2009-06-22 19:03:55 +0000 | [diff] [blame^] | 61 | self.job.barrier(client_tag, 'start', 600).rendezvous(*all) |
mbligh | cf8e0b7 | 2008-09-12 02:14:29 +0000 | [diff] [blame] | 62 | # Sleep 10 seconds to make sure the server is started |
| 63 | time.sleep(10) |
| 64 | self.client(server_ip, args) |
mbligh | 15b8a26 | 2008-09-16 16:50:49 +0000 | [diff] [blame] | 65 | # Wait up to five minutes for the server to also reach this point |
mbligh | 9c12f77 | 2009-06-22 19:03:55 +0000 | [diff] [blame^] | 66 | self.job.barrier(client_tag, 'stop', 300).rendezvous(*all) |
mbligh | cf8e0b7 | 2008-09-12 02:14:29 +0000 | [diff] [blame] | 67 | else: |
| 68 | raise error.TestError('invalid role specified') |
| 69 | |
| 70 | |
| 71 | def server_start(self, args): |
| 72 | cmd = self.server_path % args |
| 73 | self.results.append(utils.system_output(cmd, retain_output=True)) |
| 74 | |
| 75 | |
| 76 | def client(self, server_ip, args): |
| 77 | cmd = self.client_path % (server_ip, args) |
| 78 | |
| 79 | try: |
| 80 | # We don't care about the actual output since the important stuff |
| 81 | # goes to self.NP_FILE |
| 82 | utils.system(cmd) |
| 83 | except error.CmdError, e: |
| 84 | """ Catch errors due to timeout, but raise others |
| 85 | The actual error string is: |
| 86 | "Command did not complete within %d seconds" |
| 87 | called in function join_bg_job in the file common_lib/utils.py |
| 88 | |
| 89 | Looking for 'within' is probably not the best way to do this but |
| 90 | works for now""" |
| 91 | |
| 92 | if ('within' in e.additional_text |
| 93 | or 'non-zero' in e.additional_text): |
lmr | 4c607f2 | 2009-06-02 11:50:38 +0000 | [diff] [blame] | 94 | logging.debug(e.additional_text) |
mbligh | cf8e0b7 | 2008-09-12 02:14:29 +0000 | [diff] [blame] | 95 | else: |
| 96 | raise |
| 97 | |
| 98 | |
| 99 | def postprocess(self): |
| 100 | if self.role == 'client': |
| 101 | try: |
| 102 | output = open(self.NP_FILE) |
| 103 | for line in output.readlines(): |
| 104 | buff, bandwidth, latency = line.split() |
| 105 | attr = {'buffer_size':buff} |
| 106 | keyval = {'bandwidth':bandwidth, 'latency':latency} |
| 107 | self.write_iteration_keyval(attr, keyval) |
| 108 | finally: |
| 109 | output.close() |
| 110 | os.remove(self.NP_FILE) |