Home | History | Annotate | Download | only in bin
      1 #!/usr/bin/python -u
      2 #
      3 # autotest <control file> - run the autotest control file specified.
      4 #
      5 import os, sys
      6 import common
      7 from optparse import OptionParser
      8 from autotest_lib.client.bin import job
      9 from autotest_lib.client.common_lib import global_config
     10 
     11 
     12 # Use the name of the binary to find the real installation directory
     13 # aka $AUTODIR.  Update our path to include the $AUTODIR/bin/tests
     14 # directory and ensure we have $AUTODIR in our environment.
     15 autodirbin = os.path.dirname(os.path.realpath(sys.argv[0]))
     16 autodir = os.path.dirname(autodirbin)
     17 
     18 sys.path.insert(0, autodirbin)
     19 
     20 os.environ['AUTODIR'] = autodir
     21 os.environ['AUTODIRBIN'] = autodirbin
     22 os.environ['PYTHONPATH'] = autodirbin
     23 
     24 parser = OptionParser(usage='Usage: %prog [options] <control-file>')
     25 
     26 parser.add_option("-a", "--args", dest='args',
     27                         help="additional args to pass to control file")
     28 
     29 parser.add_option("-c", "--continue", dest="cont", action="store_true",
     30                         default=False, help="continue previously started job")
     31 
     32 parser.add_option("-t", "--tag", dest="tag", type="string", default="default",
     33                         help="set the job tag")
     34 
     35 parser.add_option("-H", "--harness", dest="harness", type="string", default='',
     36                         help="set the harness type")
     37 
     38 parser.add_option("-P", "--harness_args", dest="harness_args", type="string", default='',
     39                         help="arguments delivered to harness")
     40 
     41 parser.add_option("-U", "--user", dest="user", type="string",
     42                         default='', help="set the job username")
     43 
     44 parser.add_option("-l", "--external_logging", dest="log", action="store_true",
     45                         default=False, help="enable external logging")
     46 
     47 parser.add_option('--verbose', dest='verbose', action='store_true',
     48                   help='Include DEBUG messages in console output')
     49 
     50 parser.add_option('--quiet', dest='verbose', action='store_false',
     51                   help='Not include DEBUG messages in console output')
     52 
     53 parser.add_option('--hostname', dest='hostname', type='string',
     54                   default=None, action='store',
     55                   help='Take this as the hostname of this machine '
     56                        '(given by autoserv)')
     57 
     58 parser.add_option('--output_dir', dest='output_dir',
     59                   type='string', default="", action='store',
     60                   help='Specify an alternate path to store test result logs')
     61 
     62 parser.add_option('--client_test_setup', dest='client_test_setup',
     63                   type='string', default=None, action='store',
     64                   help='a comma seperated list of client tests to prebuild on '
     65                        'the server. Use all to prebuild all of them.')
     66 
     67 parser.add_option('--tap', dest='tap_report', action='store_true',
     68                   default=None, help='Deprecated, do not use.')
     69 
     70 def usage():
     71     parser.print_help()
     72     sys.exit(1)
     73 
     74 options, args = parser.parse_args()
     75 
     76 # Check for a control file if not in prebuild mode.
     77 if len(args) != 1 and options.client_test_setup is None:
     78     print "Missing control file!"
     79     usage()
     80 
     81 drop_caches = global_config.global_config.get_config_value('CLIENT',
     82                                                            'drop_caches',
     83                                                            type=bool,
     84                                                            default=True)
     85 
     86 if options.client_test_setup:
     87     from autotest_lib.client.bin import setup_job
     88     exit_code = 0
     89     try:
     90         setup_job.setup_tests(options)
     91     except:
     92         exit_code = 1
     93     sys.exit(exit_code)
     94 
     95 # JOB: run the specified job control file.
     96 job.runjob(os.path.realpath(args[0]), drop_caches, options)
     97