1#!/usr/bin/python -u
2#
3# autotest <control file> - run the autotest control file specified.
4#
5import os, sys
6import common
7from optparse import OptionParser
8from autotest_lib.client.bin import job
9from 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.
15autodirbin = os.path.dirname(os.path.realpath(sys.argv[0]))
16autodir = os.path.dirname(autodirbin)
17
18sys.path.insert(0, autodirbin)
19
20os.environ['AUTODIR'] = autodir
21os.environ['AUTODIRBIN'] = autodirbin
22os.environ['PYTHONPATH'] = autodirbin
23
24parser = OptionParser(usage='Usage: %prog [options] <control-file>')
25
26parser.add_option("-a", "--args", dest='args',
27                        help="additional args to pass to control file")
28
29parser.add_option("-c", "--continue", dest="cont", action="store_true",
30                        default=False, help="continue previously started job")
31
32parser.add_option("-t", "--tag", dest="tag", type="string", default="default",
33                        help="set the job tag")
34
35parser.add_option("-H", "--harness", dest="harness", type="string", default='',
36                        help="set the harness type")
37
38parser.add_option("-P", "--harness_args", dest="harness_args", type="string", default='',
39                        help="arguments delivered to harness")
40
41parser.add_option("-U", "--user", dest="user", type="string",
42                        default='', help="set the job username")
43
44parser.add_option("-l", "--external_logging", dest="log", action="store_true",
45                        default=False, help="enable external logging")
46
47parser.add_option('--verbose', dest='verbose', action='store_true',
48                  help='Include DEBUG messages in console output')
49
50parser.add_option('--quiet', dest='verbose', action='store_false',
51                  help='Not include DEBUG messages in console output')
52
53parser.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
58parser.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
62parser.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
67parser.add_option('--tap', dest='tap_report', action='store_true',
68                  default=None, help='Deprecated, do not use.')
69
70def usage():
71    parser.print_help()
72    sys.exit(1)
73
74options, args = parser.parse_args()
75
76# Check for a control file if not in prebuild mode.
77if len(args) != 1 and options.client_test_setup is None:
78    print "Missing control file!"
79    usage()
80
81drop_caches = global_config.global_config.get_config_value('CLIENT',
82                                                           'drop_caches',
83                                                           type=bool,
84                                                           default=True)
85
86if 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.
96job.runjob(os.path.realpath(args[0]), drop_caches, options)
97