blob: 4cf517f5d7afcb5fe710ae93fcea115ee6280f77 [file] [log] [blame]
Xixuan Wu17c8f7b2018-04-19 14:43:33 -07001# Copyright 2018 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""Parse & Validate CLI arguments for run_suite_skylab.py."""
6
7from __future__ import absolute_import
8from __future__ import division
9from __future__ import print_function
10
11import argparse
Xixuan Wu2406be32018-05-14 13:51:30 -070012import ast
Xixuan Wu52e396e2018-07-19 17:02:04 -070013import sys
Xixuan Wu17c8f7b2018-04-19 14:43:33 -070014
Xixuan Wu53d15712018-06-12 10:52:55 -070015from lucifer import autotest
16from skylab_suite import cros_suite
Xixuan Wu89300762018-07-13 14:58:46 -070017from skylab_suite import swarming_lib
Xixuan Wu17c8f7b2018-04-19 14:43:33 -070018
19
20def make_parser():
21 """Make ArgumentParser instance for run_suite_skylab.py."""
22 parser = argparse.ArgumentParser(prog='run_suite_skylab',
23 description=__doc__)
24
25 # Suite-related parameters.
26 parser.add_argument('--board', required=True)
27 parser.add_argument(
28 '--model',
29 help=('The device model to run tests against. For non-unified '
30 'builds, model and board are synonymous, but board is more '
31 'accurate in some cases. Only pass this option if your build '
32 'is a unified build.'))
33 parser.add_argument(
34 '--pool', default='suites',
35 help=('Specify the pool of DUTs to run this suite. If you want no '
36 'pool, you can specify it with --pool="". USE WITH CARE.'))
37 parser.add_argument(
38 '--suite_name', required=True,
39 help='Specify the suite to run.')
40 parser.add_argument(
41 '--build', required=True,
42 help='Specify the build to run the suite with.')
43 parser.add_argument(
44 '--cheets_build', default=None,
45 help='ChromeOS Android build to be installed on dut.')
46 parser.add_argument(
47 '--firmware_rw_build', default=None,
48 help='Firmware build to be installed in dut RW firmware.')
49 parser.add_argument(
50 '--firmware_ro_build', default=None,
51 help='Firmware build to be installed in dut RO firmware.')
52 parser.add_argument(
53 '--test_source_build', default=None,
54 help=('Build that contains the test code. It can be the value '
55 'of arguments "--build", "--firmware_rw_build" or '
56 '"--firmware_ro_build". Default is to use test code from '
57 'the "--build" version (CrOS image)'))
58 parser.add_argument(
Xixuan Wu89300762018-07-13 14:58:46 -070059 '--priority', type=int,
60 default=swarming_lib.SKYLAB_HWTEST_PRIORITIES_MAP['Default'],
61 choices=[value for name, value in
62 swarming_lib.SORTED_SKYLAB_HWTEST_PRIORITY],
63 help=('The priority to run the suite. A high value means this suite '
Xixuan Wu17c8f7b2018-04-19 14:43:33 -070064 'will be executed in a low priority, e.g. being delayed to '
65 'execute. Each numerical value represents: '+ ', '.join([
Xixuan Wu89300762018-07-13 14:58:46 -070066 '(%s: %d)' % (name, value) for name, value in
67 swarming_lib.SORTED_SKYLAB_HWTEST_PRIORITY])))
Xixuan Wu2406be32018-05-14 13:51:30 -070068 parser.add_argument(
69 "--suite_args", type=ast.literal_eval, default=None,
70 action="store",
71 help="A dict of args passed to the suite control file.")
Xixuan Wub2795662018-06-28 16:02:53 -070072 parser.add_argument(
73 "--job_keyvals", type=ast.literal_eval, default={},
74 action="store",
75 help="A dict of job keyvals to be passed to child jobs.")
Xixuan Wu0956b632018-08-06 14:40:23 -070076 parser.add_argument(
77 "--minimum_duts", type=int, default=1, action="store",
78 help="A minimum required numbers of DUTs to run this suite.")
Allen Lib5888f02018-09-04 18:14:45 -070079 # TODO(ayatane): Make sure no callers pass --use_fallback before removing.
Xixuan Wuc79b1b72018-08-06 17:03:43 -070080 parser.add_argument(
Allen Lib5888f02018-09-04 18:14:45 -070081 "--use_fallback", action="store_true", help='Deprecated')
Xixuan Wu17c8f7b2018-04-19 14:43:33 -070082
83 # Swarming-related parameters.
84 parser.add_argument(
Xixuan Wu88c697b2018-05-30 16:35:25 -070085 '--execution_timeout_seconds', type=int, default=30,
Xixuan Wu17c8f7b2018-04-19 14:43:33 -070086 help='Seconds to allow a task to complete, once execution beings.')
87
88 # logic-related parameters.
89 parser.add_argument(
Xixuan Wu88c697b2018-05-30 16:35:25 -070090 '--create_and_return', action='store_true',
Xixuan Wu17c8f7b2018-04-19 14:43:33 -070091 help='Create the child jobs of a suite, then finish immediately.')
92 parser.add_argument(
Xixuan Wuc7430712018-07-10 12:04:34 -070093 '--suite_id', default=None,
94 help='A suite ID, wait for whose child tests to finish.')
95 parser.add_argument(
Xixuan Wu56424bc2018-05-15 11:03:27 -070096 '--test_retry', default=False, action='store_true',
97 help='Enable test-level retry.')
98 parser.add_argument(
Xixuan Wu88c697b2018-05-30 16:35:25 -070099 '--max_retries', default=0, type=int, action='store',
Xixuan Wu17c8f7b2018-04-19 14:43:33 -0700100 help='Maximum retries allowed at suite level. No retry if it is 0.')
101 parser.add_argument(
Xixuan Wu2406be32018-05-14 13:51:30 -0700102 '--timeout_mins', default=90, type=int, action='store',
103 help='Maximum minutes to wait for a suite to finish.')
104 parser.add_argument(
Xixuan Wub0983632018-08-17 17:54:42 -0700105 '--passed_mins', default=0, type=int, action='store',
106 help='The minutes that this suite already runs for.')
107 parser.add_argument(
Xixuan Wu88c697b2018-05-30 16:35:25 -0700108 '--run_prod_code', action='store_true', default=False,
Xixuan Wu17c8f7b2018-04-19 14:43:33 -0700109 help='Run the test code that lives in prod aka the test '
110 'code currently on the lab servers.')
111 parser.add_argument(
Xixuan Wue71c8932018-05-07 17:18:34 -0700112 '--dry_run', action='store_true',
113 help=('Used for kicking off a run of suite with fake commands.'))
114 parser.add_argument(
Xixuan Wu85653172018-08-22 16:52:32 -0700115 '--pre_check', action='store_true',
116 help=('Used for checking whether a same suite is already kicked off'
117 'to Skylab.'))
118 parser.add_argument(
Xixuan Wu17c8f7b2018-04-19 14:43:33 -0700119 '--do_nothing', action='store_true',
120 help=('Used for monitoring purposes, to measure no-op swarming proxy '
121 'latency or create a dummy run_suite_skylab run.'))
122
Xixuan Wu53d15712018-06-12 10:52:55 -0700123 # Abort-related parameters.
124 parser.add_argument(
Xixuan Wu52e396e2018-07-19 17:02:04 -0700125 '--abort_limit', default=sys.maxint, type=int, action='store',
Xixuan Wu53d15712018-06-12 10:52:55 -0700126 help=('Only abort first N parent tasks which fulfill the search '
127 'requirements.'))
Xixuan Wuae8bfd22018-06-15 10:29:42 -0700128 parser.add_argument(
129 '--suite_task_ids', nargs='*', default=[],
130 help=('Specify the parent swarming task id to abort.'))
Xixuan Wu53d15712018-06-12 10:52:55 -0700131
Xixuan Wu17c8f7b2018-04-19 14:43:33 -0700132 return parser
133
134
135def verify_and_clean_options(options):
136 """Validate options."""
Xixuan Wu2406be32018-05-14 13:51:30 -0700137 if options.suite_args is None:
138 options.suite_args = {}
139
Xixuan Wu17c8f7b2018-04-19 14:43:33 -0700140 return True
Xixuan Wu53d15712018-06-12 10:52:55 -0700141
142
Xixuan Wu9287fda2018-07-12 16:22:06 -0700143def parse_suite_spec(options):
144 """Parse options to suite_spec."""
Xixuan Wu53d15712018-06-12 10:52:55 -0700145 suite_common = autotest.load('server.cros.dynamic_suite.suite_common')
146 builds = suite_common.make_builds_from_options(options)
Xixuan Wu9287fda2018-07-12 16:22:06 -0700147 return cros_suite.SuiteSpec(
Xixuan Wu53d15712018-06-12 10:52:55 -0700148 builds=builds,
149 suite_name=options.suite_name,
150 suite_file_name=suite_common.canonicalize_suite_name(
151 options.suite_name),
152 test_source_build=suite_common.get_test_source_build(
153 builds, test_source_build=options.test_source_build),
154 suite_args=options.suite_args,
155 priority=options.priority,
156 board=options.board,
157 pool=options.pool,
Xixuan Wub2795662018-06-28 16:02:53 -0700158 job_keyvals=options.job_keyvals,
Xixuan Wu0956b632018-08-06 14:40:23 -0700159 minimum_duts=options.minimum_duts,
Xixuan Wuba0276c2018-08-10 09:36:23 -0700160 timeout_mins=options.timeout_mins,
Xixuan Wu53d15712018-06-12 10:52:55 -0700161 )