• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2021 The Chromium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import argparse
6
7
8def ParseArgs():
9  parser = argparse.ArgumentParser(
10      description=('Script for automatically suppressing flaky/failing '
11                   'tests.'))
12  parser.add_argument('--project',
13                      required=True,
14                      help=('The billing project to use for BigQuery queries. '
15                            'Must have access to the ResultDB BQ tables, e.g. '
16                            '"chrome-luci-data.chromium.gpu_ci_test_results".'))
17  parser.add_argument('--sample-period',
18                      type=int,
19                      default=1,
20                      help=('The number of days to sample data from.'))
21  parser.add_argument('--no-group-by-tags',
22                      action='store_false',
23                      default=True,
24                      dest='group_by_tags',
25                      help=('Append added expectations to the end of the file '
26                            'instead of attempting to automatically group with '
27                            'similar expectations.'))
28  parser.add_argument('--no-prompt-for-user-input',
29                      action='store_false',
30                      default=True,
31                      dest='prompt_for_user_input',
32                      help=('Generate expectations automatically based on '
33                            'thresholds instead of prompting the user each '
34                            'time. The user will still need to add associated '
35                            'bugs to generated expectations afterwards.'))
36  parser.add_argument('--ignore-threshold',
37                      type=float,
38                      default=0.01,
39                      help=('The fraction of failed tests under which flakes '
40                            'will be ignored instead of having an expectation '
41                            'added when --no-prompt-for-user-input is used.'))
42  parser.add_argument('--flaky-threshold',
43                      type=float,
44                      default=0.5,
45                      help=('The fraction of failed tests under which flakes '
46                            'will be marked as RetryOnFailure when '
47                            '--no-prompt-for-user-input is used. Above this, '
48                            'failures will be marked as Failure.'))
49  parser.add_argument('--include-all-tags',
50                      action='store_true',
51                      default=False,
52                      help=('Use all tags generated by a configuration when '
53                            'creating an expectation rather than attempting '
54                            'to only use the most specific one. This should '
55                            'only need to be passed if the tags in the '
56                            'expectation files are not ordered from least '
57                            'specific to most specific.'))
58  parser.add_argument('--result-output-file',
59                      help=('Output file to store the generated results. If '
60                            'not specified, will use a temporary file.'))
61  parser.add_argument('--bypass-up-to-date-check',
62                      action='store_true',
63                      default=False,
64                      help=('Bypasses the check that the local expectation '
65                            'files are up to date. Only intended for use on '
66                            'bots to avoid failures due to potential race '
67                            'conditions between updating the checkout and '
68                            'running the script.'))
69  parser.add_argument(
70      '--non-hidden-failures',
71      action='store_true',
72      default=False,
73      help=
74      ('Enable this option to only targeting visible failures on CI builders. '
75       'The test results will fail the builder runs, flaky results will '
76       'consider as pass in this option.'))
77  args = parser.parse_args()
78
79  if not args.prompt_for_user_input:
80    if args.ignore_threshold < 0:
81      raise ValueError('--ignore-threshold must be positive')
82    if args.flaky_threshold < 0:
83      raise ValueError('--flaky-threshold must be positive')
84    if args.flaky_threshold <= args.ignore_threshold:
85      raise ValueError(
86          '--flaky-threshold must be greater than --ignore-threshold')
87
88  return args
89