xref: /aosp_15_r20/tools/asuite/atest/test_finder_handler.py (revision c2e18aaa1096c836b086f94603d04f4eb9cf37f5)
1*c2e18aaaSAndroid Build Coastguard Worker# Copyright 2018, The Android Open Source Project
2*c2e18aaaSAndroid Build Coastguard Worker#
3*c2e18aaaSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License");
4*c2e18aaaSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License.
5*c2e18aaaSAndroid Build Coastguard Worker# You may obtain a copy of the License at
6*c2e18aaaSAndroid Build Coastguard Worker#
7*c2e18aaaSAndroid Build Coastguard Worker#     http://www.apache.org/licenses/LICENSE-2.0
8*c2e18aaaSAndroid Build Coastguard Worker#
9*c2e18aaaSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software
10*c2e18aaaSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS,
11*c2e18aaaSAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*c2e18aaaSAndroid Build Coastguard Worker# See the License for the specific language governing permissions and
13*c2e18aaaSAndroid Build Coastguard Worker# limitations under the License.
14*c2e18aaaSAndroid Build Coastguard Worker
15*c2e18aaaSAndroid Build Coastguard Worker"""Test Finder Handler module."""
16*c2e18aaaSAndroid Build Coastguard Worker
17*c2e18aaaSAndroid Build Coastguard Worker# pylint: disable=import-outside-toplevel
18*c2e18aaaSAndroid Build Coastguard Worker# pylint: disable=protected-access
19*c2e18aaaSAndroid Build Coastguard Worker
20*c2e18aaaSAndroid Build Coastguard Workerfrom enum import Enum, unique
21*c2e18aaaSAndroid Build Coastguard Workerimport inspect
22*c2e18aaaSAndroid Build Coastguard Workerimport logging
23*c2e18aaaSAndroid Build Coastguard Workerimport re
24*c2e18aaaSAndroid Build Coastguard Workerimport sys
25*c2e18aaaSAndroid Build Coastguard Worker
26*c2e18aaaSAndroid Build Coastguard Workerfrom atest import atest_utils, constants
27*c2e18aaaSAndroid Build Coastguard Workerfrom atest.atest_enum import ExitCode
28*c2e18aaaSAndroid Build Coastguard Workerfrom atest.test_finders import cache_finder
29*c2e18aaaSAndroid Build Coastguard Workerfrom atest.test_finders import module_finder
30*c2e18aaaSAndroid Build Coastguard Workerfrom atest.test_finders import suite_plan_finder
31*c2e18aaaSAndroid Build Coastguard Workerfrom atest.test_finders import test_finder_base
32*c2e18aaaSAndroid Build Coastguard Workerfrom atest.test_finders import test_finder_utils
33*c2e18aaaSAndroid Build Coastguard Workerfrom atest.test_finders import tf_integration_finder
34*c2e18aaaSAndroid Build Coastguard Worker
35*c2e18aaaSAndroid Build Coastguard Worker# List of default test finder classes.
36*c2e18aaaSAndroid Build Coastguard Worker_TEST_FINDERS = {
37*c2e18aaaSAndroid Build Coastguard Worker    suite_plan_finder.SuitePlanFinder,
38*c2e18aaaSAndroid Build Coastguard Worker    tf_integration_finder.TFIntegrationFinder,
39*c2e18aaaSAndroid Build Coastguard Worker    module_finder.ModuleFinder,
40*c2e18aaaSAndroid Build Coastguard Worker    cache_finder.CacheFinder,
41*c2e18aaaSAndroid Build Coastguard Worker}
42*c2e18aaaSAndroid Build Coastguard Worker
43*c2e18aaaSAndroid Build Coastguard Worker
44*c2e18aaaSAndroid Build Coastguard Worker@unique
45*c2e18aaaSAndroid Build Coastguard Workerclass FinderMethod(Enum):
46*c2e18aaaSAndroid Build Coastguard Worker  """An enum object for test finders.
47*c2e18aaaSAndroid Build Coastguard Worker
48*c2e18aaaSAndroid Build Coastguard Worker  Explanation of FinderMethod:
49*c2e18aaaSAndroid Build Coastguard Worker  0. MODULE: LOCAL_MODULE or LOCAL_PACKAGE_NAME value in Android.mk/Android.bp.
50*c2e18aaaSAndroid Build Coastguard Worker  1. MAINLINE_MODULE: module[mod1.apk+mod2.apex] pattern in TEST_MAPPING files.
51*c2e18aaaSAndroid Build Coastguard Worker  2. CLASS: Names which the same with a ClassName.java/kt file.
52*c2e18aaaSAndroid Build Coastguard Worker  3. QUALIFIED_CLASS: String like "a.b.c.ClassName".
53*c2e18aaaSAndroid Build Coastguard Worker  4. MODULE_CLASS: Combo of MODULE and CLASS as "module:class".
54*c2e18aaaSAndroid Build Coastguard Worker  5. PACKAGE: Package in java file. Same as file path to java file.
55*c2e18aaaSAndroid Build Coastguard Worker  6. MODULE_PACKAGE: Combo of MODULE and PACKAGE as "module:package".
56*c2e18aaaSAndroid Build Coastguard Worker  7. MODULE_FILE_PATH: File path to dir of tests or test itself.
57*c2e18aaaSAndroid Build Coastguard Worker  8. INTEGRATION_FILE_PATH: File path to config xml in one of the 4 integration
58*c2e18aaaSAndroid Build Coastguard Worker                            config directories.
59*c2e18aaaSAndroid Build Coastguard Worker  9. INTEGRATION: xml file name in one of the 4 integration config directories.
60*c2e18aaaSAndroid Build Coastguard Worker  10. SUITE: Value of the "run-suite-tag" in xml config file in 4 config dirs.
61*c2e18aaaSAndroid Build Coastguard Worker             Same as value of "test-suite-tag" in AndroidTest.xml files.
62*c2e18aaaSAndroid Build Coastguard Worker  11. CC_CLASS: Test case in cc file.
63*c2e18aaaSAndroid Build Coastguard Worker  12. SUITE_PLAN: Suite name such as cts.
64*c2e18aaaSAndroid Build Coastguard Worker  13. SUITE_PLAN_FILE_PATH: File path to config xml in the suite config
65*c2e18aaaSAndroid Build Coastguard Worker                            directories.
66*c2e18aaaSAndroid Build Coastguard Worker  14. CACHE: A pseudo type that runs cache_finder without finding test in real.
67*c2e18aaaSAndroid Build Coastguard Worker  15: CONFIG: Find tests by the given AndroidTest.xml file path.
68*c2e18aaaSAndroid Build Coastguard Worker  """
69*c2e18aaaSAndroid Build Coastguard Worker
70*c2e18aaaSAndroid Build Coastguard Worker  MODULE = ('MODULE', module_finder.ModuleFinder.find_test_by_module_name)
71*c2e18aaaSAndroid Build Coastguard Worker  MAINLINE_MODULE = (
72*c2e18aaaSAndroid Build Coastguard Worker      'MAINLINE_MODULE',
73*c2e18aaaSAndroid Build Coastguard Worker      module_finder.MainlineModuleFinder.find_test_by_module_name,
74*c2e18aaaSAndroid Build Coastguard Worker  )
75*c2e18aaaSAndroid Build Coastguard Worker  CLASS = ('CLASS', module_finder.ModuleFinder.find_test_by_class_name)
76*c2e18aaaSAndroid Build Coastguard Worker  MODULE_CLASS = (
77*c2e18aaaSAndroid Build Coastguard Worker      'MODULE_CLASS',
78*c2e18aaaSAndroid Build Coastguard Worker      module_finder.ModuleFinder.find_test_by_module_and_class,
79*c2e18aaaSAndroid Build Coastguard Worker  )
80*c2e18aaaSAndroid Build Coastguard Worker  QUALIFIED_CLASS = (
81*c2e18aaaSAndroid Build Coastguard Worker      'QUALIFIED_CLASS',
82*c2e18aaaSAndroid Build Coastguard Worker      module_finder.ModuleFinder.find_test_by_class_name,
83*c2e18aaaSAndroid Build Coastguard Worker  )
84*c2e18aaaSAndroid Build Coastguard Worker  PACKAGE = ('PACKAGE', module_finder.ModuleFinder.find_test_by_package_name)
85*c2e18aaaSAndroid Build Coastguard Worker  MODULE_PACKAGE = (
86*c2e18aaaSAndroid Build Coastguard Worker      'MODULE_PACKAGE',
87*c2e18aaaSAndroid Build Coastguard Worker      module_finder.ModuleFinder.find_test_by_module_and_package,
88*c2e18aaaSAndroid Build Coastguard Worker  )
89*c2e18aaaSAndroid Build Coastguard Worker  MODULE_FILE_PATH = (
90*c2e18aaaSAndroid Build Coastguard Worker      'MODULE_FILE_PATH',
91*c2e18aaaSAndroid Build Coastguard Worker      module_finder.ModuleFinder.find_test_by_path,
92*c2e18aaaSAndroid Build Coastguard Worker  )
93*c2e18aaaSAndroid Build Coastguard Worker  INTEGRATION_FILE_PATH = (
94*c2e18aaaSAndroid Build Coastguard Worker      'INTEGRATION_FILE_PATH',
95*c2e18aaaSAndroid Build Coastguard Worker      tf_integration_finder.TFIntegrationFinder.find_int_test_by_path,
96*c2e18aaaSAndroid Build Coastguard Worker  )
97*c2e18aaaSAndroid Build Coastguard Worker  INTEGRATION = (
98*c2e18aaaSAndroid Build Coastguard Worker      'INTEGRATION',
99*c2e18aaaSAndroid Build Coastguard Worker      tf_integration_finder.TFIntegrationFinder.find_test_by_integration_name,
100*c2e18aaaSAndroid Build Coastguard Worker  )
101*c2e18aaaSAndroid Build Coastguard Worker  CC_CLASS = ('CC_CLASS', module_finder.ModuleFinder.find_test_by_cc_class_name)
102*c2e18aaaSAndroid Build Coastguard Worker  SUITE_PLAN = (
103*c2e18aaaSAndroid Build Coastguard Worker      'SUITE_PLAN',
104*c2e18aaaSAndroid Build Coastguard Worker      suite_plan_finder.SuitePlanFinder.find_test_by_suite_name,
105*c2e18aaaSAndroid Build Coastguard Worker  )
106*c2e18aaaSAndroid Build Coastguard Worker  SUITE_PLAN_FILE_PATH = (
107*c2e18aaaSAndroid Build Coastguard Worker      'SUITE_PLAN_FILE_PATH',
108*c2e18aaaSAndroid Build Coastguard Worker      suite_plan_finder.SuitePlanFinder.find_test_by_suite_path,
109*c2e18aaaSAndroid Build Coastguard Worker  )
110*c2e18aaaSAndroid Build Coastguard Worker  CACHE = ('CACHE', cache_finder.CacheFinder.find_test_by_cache)
111*c2e18aaaSAndroid Build Coastguard Worker  CONFIG = ('CONFIG', module_finder.ModuleFinder.find_test_by_config_name)
112*c2e18aaaSAndroid Build Coastguard Worker
113*c2e18aaaSAndroid Build Coastguard Worker  def __init__(self, name, method):
114*c2e18aaaSAndroid Build Coastguard Worker    self._name = name
115*c2e18aaaSAndroid Build Coastguard Worker    self._method = method
116*c2e18aaaSAndroid Build Coastguard Worker
117*c2e18aaaSAndroid Build Coastguard Worker  def get_name(self):
118*c2e18aaaSAndroid Build Coastguard Worker    """Return finder's name."""
119*c2e18aaaSAndroid Build Coastguard Worker    return self._name
120*c2e18aaaSAndroid Build Coastguard Worker
121*c2e18aaaSAndroid Build Coastguard Worker  def get_method(self):
122*c2e18aaaSAndroid Build Coastguard Worker    """Return finder's method."""
123*c2e18aaaSAndroid Build Coastguard Worker    return self._method
124*c2e18aaaSAndroid Build Coastguard Worker
125*c2e18aaaSAndroid Build Coastguard Worker
126*c2e18aaaSAndroid Build Coastguard Workerdef _get_finder_instance_dict(module_info):
127*c2e18aaaSAndroid Build Coastguard Worker  """Return dict of finder instances.
128*c2e18aaaSAndroid Build Coastguard Worker
129*c2e18aaaSAndroid Build Coastguard Worker  Args:
130*c2e18aaaSAndroid Build Coastguard Worker      module_info: ModuleInfo for finder classes to use.
131*c2e18aaaSAndroid Build Coastguard Worker
132*c2e18aaaSAndroid Build Coastguard Worker  Returns:
133*c2e18aaaSAndroid Build Coastguard Worker      Dict of finder instances keyed by their name.
134*c2e18aaaSAndroid Build Coastguard Worker  """
135*c2e18aaaSAndroid Build Coastguard Worker  instance_dict = {}
136*c2e18aaaSAndroid Build Coastguard Worker  for finder in _get_test_finders():
137*c2e18aaaSAndroid Build Coastguard Worker    instance_dict[finder.NAME] = finder(module_info=module_info)
138*c2e18aaaSAndroid Build Coastguard Worker  return instance_dict
139*c2e18aaaSAndroid Build Coastguard Worker
140*c2e18aaaSAndroid Build Coastguard Worker
141*c2e18aaaSAndroid Build Coastguard Workerdef _get_test_finders():
142*c2e18aaaSAndroid Build Coastguard Worker  """Returns the test finders.
143*c2e18aaaSAndroid Build Coastguard Worker
144*c2e18aaaSAndroid Build Coastguard Worker  If external test types are defined outside atest, they can be try-except
145*c2e18aaaSAndroid Build Coastguard Worker  imported into here.
146*c2e18aaaSAndroid Build Coastguard Worker
147*c2e18aaaSAndroid Build Coastguard Worker  Returns:
148*c2e18aaaSAndroid Build Coastguard Worker      Set of test finder classes.
149*c2e18aaaSAndroid Build Coastguard Worker  """
150*c2e18aaaSAndroid Build Coastguard Worker  test_finders_list = _TEST_FINDERS
151*c2e18aaaSAndroid Build Coastguard Worker  # Example import of external test finder:
152*c2e18aaaSAndroid Build Coastguard Worker  try:
153*c2e18aaaSAndroid Build Coastguard Worker    from test_finders import example_finder
154*c2e18aaaSAndroid Build Coastguard Worker
155*c2e18aaaSAndroid Build Coastguard Worker    test_finders_list.add(example_finder.ExampleFinder)
156*c2e18aaaSAndroid Build Coastguard Worker  except ImportError:
157*c2e18aaaSAndroid Build Coastguard Worker    pass
158*c2e18aaaSAndroid Build Coastguard Worker  return test_finders_list
159*c2e18aaaSAndroid Build Coastguard Worker
160*c2e18aaaSAndroid Build Coastguard Worker
161*c2e18aaaSAndroid Build Coastguard Workerdef _validate_ref(ref: str):
162*c2e18aaaSAndroid Build Coastguard Worker  # Filter out trailing dot but keeping `.` and `..` in ref.
163*c2e18aaaSAndroid Build Coastguard Worker  if '..' not in ref:
164*c2e18aaaSAndroid Build Coastguard Worker    if re.match(r'(?:[\w\.\d-]+)\.$', ref):
165*c2e18aaaSAndroid Build Coastguard Worker      atest_utils.colorful_print(
166*c2e18aaaSAndroid Build Coastguard Worker          f'Found trailing dot({ref}). Please correct it and try again.',
167*c2e18aaaSAndroid Build Coastguard Worker          constants.RED,
168*c2e18aaaSAndroid Build Coastguard Worker      )
169*c2e18aaaSAndroid Build Coastguard Worker      sys.exit(ExitCode.INPUT_TEST_REFERENCE_ERROR)
170*c2e18aaaSAndroid Build Coastguard Worker
171*c2e18aaaSAndroid Build Coastguard Worker
172*c2e18aaaSAndroid Build Coastguard Worker# pylint: disable=too-many-branches
173*c2e18aaaSAndroid Build Coastguard Worker# pylint: disable=too-many-return-statements
174*c2e18aaaSAndroid Build Coastguard Workerdef _get_test_reference_types(ref):
175*c2e18aaaSAndroid Build Coastguard Worker  """Determine type of test reference based on the content of string.
176*c2e18aaaSAndroid Build Coastguard Worker
177*c2e18aaaSAndroid Build Coastguard Worker  Examples:
178*c2e18aaaSAndroid Build Coastguard Worker      The string 'SequentialRWTest' could be a reference to
179*c2e18aaaSAndroid Build Coastguard Worker      a Module or a Class name.
180*c2e18aaaSAndroid Build Coastguard Worker
181*c2e18aaaSAndroid Build Coastguard Worker      The string 'cts/tests/filesystem' could be a Path, Integration
182*c2e18aaaSAndroid Build Coastguard Worker      or Suite reference.
183*c2e18aaaSAndroid Build Coastguard Worker
184*c2e18aaaSAndroid Build Coastguard Worker  Args:
185*c2e18aaaSAndroid Build Coastguard Worker      ref: A string referencing a test.
186*c2e18aaaSAndroid Build Coastguard Worker
187*c2e18aaaSAndroid Build Coastguard Worker  Returns:
188*c2e18aaaSAndroid Build Coastguard Worker      A list of possible REFERENCE_TYPEs (ints) for reference string.
189*c2e18aaaSAndroid Build Coastguard Worker  """
190*c2e18aaaSAndroid Build Coastguard Worker  _validate_ref(ref)
191*c2e18aaaSAndroid Build Coastguard Worker  if ref.startswith('.') or '..' in ref:
192*c2e18aaaSAndroid Build Coastguard Worker    return [
193*c2e18aaaSAndroid Build Coastguard Worker        FinderMethod.CACHE,
194*c2e18aaaSAndroid Build Coastguard Worker        FinderMethod.MODULE_FILE_PATH,
195*c2e18aaaSAndroid Build Coastguard Worker        FinderMethod.INTEGRATION_FILE_PATH,
196*c2e18aaaSAndroid Build Coastguard Worker        FinderMethod.SUITE_PLAN_FILE_PATH,
197*c2e18aaaSAndroid Build Coastguard Worker    ]
198*c2e18aaaSAndroid Build Coastguard Worker  if '/' in ref:
199*c2e18aaaSAndroid Build Coastguard Worker    if ref.startswith('/'):
200*c2e18aaaSAndroid Build Coastguard Worker      return [
201*c2e18aaaSAndroid Build Coastguard Worker          FinderMethod.CACHE,
202*c2e18aaaSAndroid Build Coastguard Worker          FinderMethod.MODULE_FILE_PATH,
203*c2e18aaaSAndroid Build Coastguard Worker          FinderMethod.INTEGRATION_FILE_PATH,
204*c2e18aaaSAndroid Build Coastguard Worker          FinderMethod.SUITE_PLAN_FILE_PATH,
205*c2e18aaaSAndroid Build Coastguard Worker      ]
206*c2e18aaaSAndroid Build Coastguard Worker    if ':' in ref:
207*c2e18aaaSAndroid Build Coastguard Worker      return [
208*c2e18aaaSAndroid Build Coastguard Worker          FinderMethod.CACHE,
209*c2e18aaaSAndroid Build Coastguard Worker          FinderMethod.MODULE_FILE_PATH,
210*c2e18aaaSAndroid Build Coastguard Worker          FinderMethod.INTEGRATION_FILE_PATH,
211*c2e18aaaSAndroid Build Coastguard Worker          FinderMethod.INTEGRATION,
212*c2e18aaaSAndroid Build Coastguard Worker          FinderMethod.SUITE_PLAN_FILE_PATH,
213*c2e18aaaSAndroid Build Coastguard Worker          FinderMethod.MODULE_CLASS,
214*c2e18aaaSAndroid Build Coastguard Worker      ]
215*c2e18aaaSAndroid Build Coastguard Worker    return [
216*c2e18aaaSAndroid Build Coastguard Worker        FinderMethod.CACHE,
217*c2e18aaaSAndroid Build Coastguard Worker        FinderMethod.MODULE_FILE_PATH,
218*c2e18aaaSAndroid Build Coastguard Worker        FinderMethod.INTEGRATION_FILE_PATH,
219*c2e18aaaSAndroid Build Coastguard Worker        FinderMethod.INTEGRATION,
220*c2e18aaaSAndroid Build Coastguard Worker        FinderMethod.SUITE_PLAN_FILE_PATH,
221*c2e18aaaSAndroid Build Coastguard Worker        FinderMethod.CC_CLASS,
222*c2e18aaaSAndroid Build Coastguard Worker        # TODO: Uncomment in SUITE when it's supported
223*c2e18aaaSAndroid Build Coastguard Worker        # FinderMethod.SUITE
224*c2e18aaaSAndroid Build Coastguard Worker    ]
225*c2e18aaaSAndroid Build Coastguard Worker  if atest_utils.get_test_and_mainline_modules(ref):
226*c2e18aaaSAndroid Build Coastguard Worker    return [FinderMethod.CACHE, FinderMethod.MAINLINE_MODULE]
227*c2e18aaaSAndroid Build Coastguard Worker  if '.' in ref:
228*c2e18aaaSAndroid Build Coastguard Worker    ref_end = ref.rsplit('.', 1)[-1]
229*c2e18aaaSAndroid Build Coastguard Worker    ref_end_is_upper = ref_end[0].isupper()
230*c2e18aaaSAndroid Build Coastguard Worker  # parse_test_reference() will return none empty dictionary if input test
231*c2e18aaaSAndroid Build Coastguard Worker  # reference match $module:$package_class.
232*c2e18aaaSAndroid Build Coastguard Worker  if test_finder_utils.parse_test_reference(ref):
233*c2e18aaaSAndroid Build Coastguard Worker    if '.' in ref:
234*c2e18aaaSAndroid Build Coastguard Worker      if ref_end_is_upper:
235*c2e18aaaSAndroid Build Coastguard Worker        # Possible types:
236*c2e18aaaSAndroid Build Coastguard Worker        # Module:fully.qualified.Class
237*c2e18aaaSAndroid Build Coastguard Worker        # Module:filly.qualifiled.(P|p)ackage (b/289515000)
238*c2e18aaaSAndroid Build Coastguard Worker        # Integration:fully.q.Class
239*c2e18aaaSAndroid Build Coastguard Worker        return [
240*c2e18aaaSAndroid Build Coastguard Worker            FinderMethod.CACHE,
241*c2e18aaaSAndroid Build Coastguard Worker            FinderMethod.MODULE_CLASS,
242*c2e18aaaSAndroid Build Coastguard Worker            FinderMethod.MODULE_PACKAGE,
243*c2e18aaaSAndroid Build Coastguard Worker            FinderMethod.INTEGRATION,
244*c2e18aaaSAndroid Build Coastguard Worker        ]
245*c2e18aaaSAndroid Build Coastguard Worker      # Module:some.package
246*c2e18aaaSAndroid Build Coastguard Worker      return [
247*c2e18aaaSAndroid Build Coastguard Worker          FinderMethod.CACHE,
248*c2e18aaaSAndroid Build Coastguard Worker          FinderMethod.MODULE_PACKAGE,
249*c2e18aaaSAndroid Build Coastguard Worker          FinderMethod.MODULE_CLASS,
250*c2e18aaaSAndroid Build Coastguard Worker      ]
251*c2e18aaaSAndroid Build Coastguard Worker    # Module:Class or IntegrationName:Class
252*c2e18aaaSAndroid Build Coastguard Worker    return [
253*c2e18aaaSAndroid Build Coastguard Worker        FinderMethod.CACHE,
254*c2e18aaaSAndroid Build Coastguard Worker        FinderMethod.MODULE_CLASS,
255*c2e18aaaSAndroid Build Coastguard Worker        FinderMethod.INTEGRATION,
256*c2e18aaaSAndroid Build Coastguard Worker    ]
257*c2e18aaaSAndroid Build Coastguard Worker  if '.' in ref:
258*c2e18aaaSAndroid Build Coastguard Worker    # The string of ref_end possibly includes specific mathods, e.g.
259*c2e18aaaSAndroid Build Coastguard Worker    # foo.java#method, so let ref_end be the first part of splitting '#'.
260*c2e18aaaSAndroid Build Coastguard Worker    if '#' in ref_end:
261*c2e18aaaSAndroid Build Coastguard Worker      ref_end = ref_end.split('#')[0]
262*c2e18aaaSAndroid Build Coastguard Worker    if ref_end in ('java', 'kt', 'bp', 'mk', 'cc', 'cpp'):
263*c2e18aaaSAndroid Build Coastguard Worker      return [FinderMethod.CACHE, FinderMethod.MODULE_FILE_PATH]
264*c2e18aaaSAndroid Build Coastguard Worker    if ref_end == 'xml':
265*c2e18aaaSAndroid Build Coastguard Worker      return [
266*c2e18aaaSAndroid Build Coastguard Worker          FinderMethod.CACHE,
267*c2e18aaaSAndroid Build Coastguard Worker          FinderMethod.INTEGRATION_FILE_PATH,
268*c2e18aaaSAndroid Build Coastguard Worker          FinderMethod.SUITE_PLAN_FILE_PATH,
269*c2e18aaaSAndroid Build Coastguard Worker      ]
270*c2e18aaaSAndroid Build Coastguard Worker    # (b/207327349) ref_end_is_upper does not guarantee a classname anymore.
271*c2e18aaaSAndroid Build Coastguard Worker    return [
272*c2e18aaaSAndroid Build Coastguard Worker        FinderMethod.CACHE,
273*c2e18aaaSAndroid Build Coastguard Worker        FinderMethod.MODULE,
274*c2e18aaaSAndroid Build Coastguard Worker        FinderMethod.QUALIFIED_CLASS,
275*c2e18aaaSAndroid Build Coastguard Worker        FinderMethod.PACKAGE,
276*c2e18aaaSAndroid Build Coastguard Worker    ]
277*c2e18aaaSAndroid Build Coastguard Worker  # Note: We assume that if you're referencing a file in your cwd,
278*c2e18aaaSAndroid Build Coastguard Worker  # that file must have a '.' in its name, i.e. foo.java, foo.xml.
279*c2e18aaaSAndroid Build Coastguard Worker  # If this ever becomes not the case, then we need to include path below.
280*c2e18aaaSAndroid Build Coastguard Worker  return [
281*c2e18aaaSAndroid Build Coastguard Worker      FinderMethod.CACHE,
282*c2e18aaaSAndroid Build Coastguard Worker      FinderMethod.MODULE,
283*c2e18aaaSAndroid Build Coastguard Worker      FinderMethod.INTEGRATION,
284*c2e18aaaSAndroid Build Coastguard Worker      # TODO: Uncomment in SUITE when it's supported
285*c2e18aaaSAndroid Build Coastguard Worker      # FinderMethod.SUITE,
286*c2e18aaaSAndroid Build Coastguard Worker      FinderMethod.CONFIG,
287*c2e18aaaSAndroid Build Coastguard Worker      FinderMethod.SUITE_PLAN,
288*c2e18aaaSAndroid Build Coastguard Worker      FinderMethod.CLASS,
289*c2e18aaaSAndroid Build Coastguard Worker      FinderMethod.CC_CLASS,
290*c2e18aaaSAndroid Build Coastguard Worker  ]
291*c2e18aaaSAndroid Build Coastguard Worker
292*c2e18aaaSAndroid Build Coastguard Worker
293*c2e18aaaSAndroid Build Coastguard Workerdef _get_registered_find_methods(module_info):
294*c2e18aaaSAndroid Build Coastguard Worker  """Return list of registered find methods.
295*c2e18aaaSAndroid Build Coastguard Worker
296*c2e18aaaSAndroid Build Coastguard Worker  This is used to return find methods that were not listed in the
297*c2e18aaaSAndroid Build Coastguard Worker  default find methods but just registered in the finder classes. These
298*c2e18aaaSAndroid Build Coastguard Worker  find methods will run before the default find methods.
299*c2e18aaaSAndroid Build Coastguard Worker
300*c2e18aaaSAndroid Build Coastguard Worker  Args:
301*c2e18aaaSAndroid Build Coastguard Worker      module_info: ModuleInfo for finder classes to instantiate with.
302*c2e18aaaSAndroid Build Coastguard Worker
303*c2e18aaaSAndroid Build Coastguard Worker  Returns:
304*c2e18aaaSAndroid Build Coastguard Worker      List of registered find methods.
305*c2e18aaaSAndroid Build Coastguard Worker  """
306*c2e18aaaSAndroid Build Coastguard Worker  find_methods = []
307*c2e18aaaSAndroid Build Coastguard Worker  finder_instance_dict = _get_finder_instance_dict(module_info)
308*c2e18aaaSAndroid Build Coastguard Worker  for finder in _get_test_finders():
309*c2e18aaaSAndroid Build Coastguard Worker    finder_instance = finder_instance_dict[finder.NAME]
310*c2e18aaaSAndroid Build Coastguard Worker    for find_method_info in finder_instance.get_all_find_methods():
311*c2e18aaaSAndroid Build Coastguard Worker      find_methods.append(
312*c2e18aaaSAndroid Build Coastguard Worker          test_finder_base.Finder(
313*c2e18aaaSAndroid Build Coastguard Worker              finder_instance, find_method_info.find_method, finder.NAME
314*c2e18aaaSAndroid Build Coastguard Worker          )
315*c2e18aaaSAndroid Build Coastguard Worker      )
316*c2e18aaaSAndroid Build Coastguard Worker  return find_methods
317*c2e18aaaSAndroid Build Coastguard Worker
318*c2e18aaaSAndroid Build Coastguard Worker
319*c2e18aaaSAndroid Build Coastguard Workerdef _get_default_find_methods(module_info, test):
320*c2e18aaaSAndroid Build Coastguard Worker  """Default find methods to be used based on the given test name.
321*c2e18aaaSAndroid Build Coastguard Worker
322*c2e18aaaSAndroid Build Coastguard Worker  Args:
323*c2e18aaaSAndroid Build Coastguard Worker      module_info: ModuleInfo for finder instances to use.
324*c2e18aaaSAndroid Build Coastguard Worker      test: String of test name to help determine which find methods to utilize.
325*c2e18aaaSAndroid Build Coastguard Worker
326*c2e18aaaSAndroid Build Coastguard Worker  Returns:
327*c2e18aaaSAndroid Build Coastguard Worker      List of find methods to use.
328*c2e18aaaSAndroid Build Coastguard Worker  """
329*c2e18aaaSAndroid Build Coastguard Worker  find_methods = []
330*c2e18aaaSAndroid Build Coastguard Worker  finder_instance_dict = _get_finder_instance_dict(module_info)
331*c2e18aaaSAndroid Build Coastguard Worker  test_ref_types = _get_test_reference_types(test)
332*c2e18aaaSAndroid Build Coastguard Worker  logging.debug(
333*c2e18aaaSAndroid Build Coastguard Worker      'Resolved input to possible references: %s',
334*c2e18aaaSAndroid Build Coastguard Worker      ', '.join([t.get_name() for t in test_ref_types]),
335*c2e18aaaSAndroid Build Coastguard Worker  )
336*c2e18aaaSAndroid Build Coastguard Worker  for test_ref_type in test_ref_types:
337*c2e18aaaSAndroid Build Coastguard Worker    find_method = test_ref_type.get_method()
338*c2e18aaaSAndroid Build Coastguard Worker    finder_instance = finder_instance_dict[inspect._findclass(find_method).NAME]
339*c2e18aaaSAndroid Build Coastguard Worker    finder_info = test_ref_type.get_name()
340*c2e18aaaSAndroid Build Coastguard Worker    find_methods.append(
341*c2e18aaaSAndroid Build Coastguard Worker        test_finder_base.Finder(finder_instance, find_method, finder_info)
342*c2e18aaaSAndroid Build Coastguard Worker    )
343*c2e18aaaSAndroid Build Coastguard Worker  return find_methods
344*c2e18aaaSAndroid Build Coastguard Worker
345*c2e18aaaSAndroid Build Coastguard Worker
346*c2e18aaaSAndroid Build Coastguard Workerdef get_find_methods_for_test(module_info, test):
347*c2e18aaaSAndroid Build Coastguard Worker  """Return a list of ordered find methods.
348*c2e18aaaSAndroid Build Coastguard Worker
349*c2e18aaaSAndroid Build Coastguard Worker  Args:
350*c2e18aaaSAndroid Build Coastguard Worker    test: String of test name to get find methods for.
351*c2e18aaaSAndroid Build Coastguard Worker
352*c2e18aaaSAndroid Build Coastguard Worker  Returns:
353*c2e18aaaSAndroid Build Coastguard Worker      List of ordered find methods.
354*c2e18aaaSAndroid Build Coastguard Worker  """
355*c2e18aaaSAndroid Build Coastguard Worker  registered_find_methods = _get_registered_find_methods(module_info)
356*c2e18aaaSAndroid Build Coastguard Worker  default_find_methods = _get_default_find_methods(module_info, test)
357*c2e18aaaSAndroid Build Coastguard Worker  return registered_find_methods + default_find_methods
358