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