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