• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2018, The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15"""Unittest constants.
16
17Unittest constants get their own file since they're used purely for testing and
18should not be combined with constants_defaults as part of normal atest
19operation. These constants are used commonly as test data so when updating a
20constant, do so with care and run all unittests to make sure nothing breaks.
21"""
22
23import os
24from pathlib import Path
25import zipfile
26
27from atest import constants
28from atest.test_finders import test_info
29from atest.test_runners import atest_tf_test_runner as atf_tr
30
31ROOT = '/'
32MODULE_DIR = 'foo/bar/jank'
33MODULE2_DIR = 'foo/bar/hello'
34MODULE_NAME = 'CtsJankDeviceTestCases'
35MODULE_CONFIG_NAME = 'CtsJankDeviceTestCases2'
36HOST_UNIT_TEST_NAME_1 = 'host_unit_test1'
37HOST_UNIT_TEST_NAME_2 = 'host_unit_test2'
38TYPO_MODULE_NAME = 'CtsJankDeviceTestCase'
39MODULE2_NAME = 'HelloWorldTests'
40CLASS_NAME = 'CtsDeviceJankUi'
41FULL_CLASS_NAME = 'android.jank.cts.ui.CtsDeviceJankUi'
42PACKAGE = 'android.jank.cts.ui'
43FIND_ONE = ROOT + 'foo/bar/jank/src/android/jank/cts/ui/CtsDeviceJankUi.java\n'
44FIND_TWO = ROOT + 'other/dir/test.java\n' + FIND_ONE
45FIND_PKG = ROOT + 'foo/bar/jank/src/android/jank/cts/ui\n'
46INT_NAME = 'example/reboot'
47GTF_INT_NAME = 'some/gtf_int_test'
48
49
50def get_atest_package():
51  """Get Atest directory."""
52  package = os.path.dirname(os.path.realpath(__file__))
53  if not os.path.isdir(package):
54    par_file_path = os.path.dirname(package)
55
56    if os.path.isfile(par_file_path):
57      destination_path = os.path.join(
58          '/tmp/atest_extract/', str(os.path.getmtime(par_file_path))
59      )
60
61      if not os.path.isdir(destination_path):
62        Path(destination_path).mkdir(parents=True, exist_ok=True)
63
64      with zipfile.ZipFile(par_file_path, 'r') as zip_ref:
65        zip_ref.extractall(destination_path)
66      package = os.path.join(destination_path, 'atest')
67
68  return package
69
70
71ATEST_PKG_DIR = get_atest_package()
72TEST_DATA_DIR = os.path.join(ATEST_PKG_DIR, 'unittest_data')
73TEST_CONFIG_DATA_DIR = os.path.join(TEST_DATA_DIR, 'test_config')
74
75INT_DIR = 'tf/contrib/res/config'
76GTF_INT_DIR = 'gtf/core/res/config'
77
78CONFIG_FILE = os.path.join(MODULE_DIR, constants.MODULE_CONFIG)
79EXTRA_CONFIG_FILE = os.path.join(MODULE_DIR, MODULE_CONFIG_NAME + '.xml')
80CONFIG2_FILE = os.path.join(MODULE2_DIR, constants.MODULE_CONFIG)
81JSON_FILE = 'module-info.json'
82MODULE_INFO_TARGET = '/out/%s' % JSON_FILE
83CC_DEP_FILE = 'module_bp_cc_deps.json'
84JAVA_DEP_FILE = 'module_bp_java_deps.json'
85MERGED_DEP_FILE = 'atest_merged_dep.json'
86MODULE_BUILD_TARGETS = {
87    'tradefed-core',
88    MODULE_INFO_TARGET,
89    'MODULES-IN-%s' % MODULE_DIR.replace('/', '-'),
90    'module-specific-target',
91}
92MODULE_BUILD_TARGETS_W_DALVIK = MODULE_BUILD_TARGETS | {
93    'cts-dalvik-device-test-runner',
94    'cts-dalvik-host-test-runner',
95    'cts-tradefed',
96}
97MODULE_BUILD_TARGETS2 = {'build-target2'}
98MODULE_DATA = {
99    constants.TI_REL_CONFIG: CONFIG_FILE,
100    constants.TI_FILTER: frozenset(),
101}
102MODULE_DATA2 = {
103    constants.TI_REL_CONFIG: CONFIG_FILE,
104    constants.TI_FILTER: frozenset(),
105}
106MODULE_DATA_W_CONFIG = {
107    constants.TI_REL_CONFIG: EXTRA_CONFIG_FILE,
108    constants.TI_FILTER: frozenset(),
109}
110MODULE_INFO = test_info.TestInfo(
111    MODULE_NAME,
112    atf_tr.AtestTradefedTestRunner.NAME,
113    MODULE_BUILD_TARGETS,
114    MODULE_DATA,
115)
116MODULE_INFO_W_DALVIK = test_info.TestInfo(
117    MODULE_NAME,
118    atf_tr.AtestTradefedTestRunner.NAME,
119    MODULE_BUILD_TARGETS_W_DALVIK,
120    MODULE_DATA,
121    module_class=[constants.MODULE_CLASS_JAVA_LIBRARIES],
122)
123MODULE_INFO_W_CONFIG = test_info.TestInfo(
124    MODULE_CONFIG_NAME,
125    atf_tr.AtestTradefedTestRunner.NAME,
126    MODULE_BUILD_TARGETS,
127    MODULE_DATA_W_CONFIG,
128)
129MODULE_INFO2 = test_info.TestInfo(
130    MODULE2_NAME,
131    atf_tr.AtestTradefedTestRunner.NAME,
132    MODULE_BUILD_TARGETS2,
133    MODULE_DATA2,
134)
135TEST_CONFIG_MODULE_INFO = test_info.TestInfo(
136    MODULE_CONFIG_NAME,
137    atf_tr.AtestTradefedTestRunner.NAME,
138    MODULE_BUILD_TARGETS,
139    MODULE_DATA_W_CONFIG,
140)
141MODULE_INFO_HOST_1 = test_info.TestInfo(
142    HOST_UNIT_TEST_NAME_1,
143    atf_tr.AtestTradefedTestRunner.NAME,
144    MODULE_BUILD_TARGETS,
145    MODULE_DATA,
146)
147MODULE_INFO_HOST_2 = test_info.TestInfo(
148    HOST_UNIT_TEST_NAME_2,
149    atf_tr.AtestTradefedTestRunner.NAME,
150    MODULE_BUILD_TARGETS,
151    MODULE_DATA,
152)
153MODULE_INFOS = [MODULE_INFO]
154MODULE_INFOS2 = [MODULE_INFO, MODULE_INFO2]
155CLASS_FILTER = test_info.TestFilter(FULL_CLASS_NAME, frozenset())
156CLASS_DATA = {
157    constants.TI_REL_CONFIG: CONFIG_FILE,
158    constants.TI_FILTER: frozenset([CLASS_FILTER]),
159}
160PACKAGE_FILTER = test_info.TestFilter(PACKAGE, frozenset())
161PACKAGE_DATA = {
162    constants.TI_REL_CONFIG: CONFIG_FILE,
163    constants.TI_FILTER: frozenset([PACKAGE_FILTER]),
164}
165TEST_DATA_CONFIG = os.path.relpath(
166    os.path.join(TEST_DATA_DIR, constants.MODULE_CONFIG), ROOT
167)
168PATH_DATA = {
169    constants.TI_REL_CONFIG: TEST_DATA_CONFIG,
170    constants.TI_FILTER: frozenset([PACKAGE_FILTER]),
171}
172EMPTY_PATH_DATA = {
173    constants.TI_REL_CONFIG: TEST_DATA_CONFIG,
174    constants.TI_FILTER: frozenset(),
175}
176
177CLASS_BUILD_TARGETS = {'class-specific-target'}
178CLASS_INFO = test_info.TestInfo(
179    MODULE_NAME,
180    atf_tr.AtestTradefedTestRunner.NAME,
181    CLASS_BUILD_TARGETS,
182    CLASS_DATA,
183)
184CLASS_INFOS = [CLASS_INFO]
185
186CLASS_BUILD_TARGETS2 = {'class-specific-target2'}
187CLASS_DATA2 = {
188    constants.TI_REL_CONFIG: CONFIG_FILE,
189    constants.TI_FILTER: frozenset([CLASS_FILTER]),
190}
191CLASS_INFO2 = test_info.TestInfo(
192    MODULE2_NAME,
193    atf_tr.AtestTradefedTestRunner.NAME,
194    CLASS_BUILD_TARGETS2,
195    CLASS_DATA2,
196)
197CLASS_INFOS = [CLASS_INFO]
198CLASS_INFOS2 = [CLASS_INFO, CLASS_INFO2]
199PACKAGE_INFO = test_info.TestInfo(
200    MODULE_NAME,
201    atf_tr.AtestTradefedTestRunner.NAME,
202    CLASS_BUILD_TARGETS,
203    PACKAGE_DATA,
204)
205PATH_INFO = test_info.TestInfo(
206    MODULE_NAME,
207    atf_tr.AtestTradefedTestRunner.NAME,
208    MODULE_BUILD_TARGETS,
209    PATH_DATA,
210)
211EMPTY_PATH_INFO = test_info.TestInfo(
212    MODULE_NAME,
213    atf_tr.AtestTradefedTestRunner.NAME,
214    MODULE_BUILD_TARGETS,
215    EMPTY_PATH_DATA,
216)
217MODULE_CLASS_COMBINED_BUILD_TARGETS = MODULE_BUILD_TARGETS | CLASS_BUILD_TARGETS
218INT_CONFIG = os.path.join(INT_DIR, INT_NAME + '.xml')
219GTF_INT_CONFIG = os.path.join(GTF_INT_DIR, GTF_INT_NAME + '.xml')
220METHOD_NAME = 'method1'
221METHOD_FILTER = test_info.TestFilter(FULL_CLASS_NAME, frozenset([METHOD_NAME]))
222METHOD_INFO = test_info.TestInfo(
223    MODULE_NAME,
224    atf_tr.AtestTradefedTestRunner.NAME,
225    MODULE_BUILD_TARGETS,
226    data={
227        constants.TI_FILTER: frozenset([METHOD_FILTER]),
228        constants.TI_REL_CONFIG: CONFIG_FILE,
229    },
230)
231METHOD2_NAME = 'method2'
232FLAT_METHOD_FILTER = test_info.TestFilter(
233    FULL_CLASS_NAME, frozenset([METHOD_NAME, METHOD2_NAME])
234)
235INT_INFO = test_info.TestInfo(
236    INT_NAME,
237    atf_tr.AtestTradefedTestRunner.NAME,
238    set(),
239    data={
240        constants.TI_REL_CONFIG: INT_CONFIG,
241        constants.TI_FILTER: frozenset(),
242    },
243)
244# Golden sample test filter for method under parameterized java.
245PARAMETERIZED_METHOD_FILTER = test_info.TestFilter(
246    FULL_CLASS_NAME, frozenset([METHOD_NAME + '*'])
247)
248PARAMETERIZED_METHOD_INFO = test_info.TestInfo(
249    MODULE_NAME,
250    atf_tr.AtestTradefedTestRunner.NAME,
251    MODULE_BUILD_TARGETS,
252    data={
253        constants.TI_FILTER: frozenset([PARAMETERIZED_METHOD_FILTER]),
254        constants.TI_REL_CONFIG: CONFIG_FILE,
255    },
256)
257PARAMETERIZED_FLAT_METHOD_FILTER = test_info.TestFilter(
258    FULL_CLASS_NAME, frozenset([METHOD_NAME + '*', METHOD2_NAME + '*'])
259)
260PARAMETERIZED_FLAT_METHOD_INFO = test_info.TestInfo(
261    MODULE_NAME,
262    atf_tr.AtestTradefedTestRunner.NAME,
263    MODULE_BUILD_TARGETS,
264    data={
265        constants.TI_FILTER: frozenset([PARAMETERIZED_FLAT_METHOD_FILTER]),
266        constants.TI_REL_CONFIG: CONFIG_FILE,
267    },
268)
269GTF_INT_INFO = test_info.TestInfo(
270    GTF_INT_NAME,
271    atf_tr.AtestTradefedTestRunner.NAME,
272    set(),
273    data={
274        constants.TI_FILTER: frozenset(),
275        constants.TI_REL_CONFIG: GTF_INT_CONFIG,
276    },
277)
278
279# Sample test configurations in TEST_MAPPING file.
280TEST_MAPPING_TEST = {'name': MODULE_NAME, 'host': True}
281TEST_MAPPING_TEST_WITH_OPTION = {
282    'name': CLASS_NAME,
283    'options': [{'arg1': 'val1'}, {'arg2': ''}],
284}
285TEST_MAPPING_TEST_WITH_OPTION_STR = '%s (arg1: val1, arg2:)' % CLASS_NAME
286TEST_MAPPING_TEST_WITH_BAD_OPTION = {
287    'name': CLASS_NAME,
288    'options': [{'arg1': 'val1', 'arg2': ''}],
289}
290TEST_MAPPING_TEST_WITH_BAD_HOST_VALUE = {'name': CLASS_NAME, 'host': 'true'}
291# Constrants of cc test unittest
292FIND_CC_ONE = ROOT + 'foo/bt/hci/test/pf_test.cc\n'
293CC_MODULE_NAME = 'net_test_hci'
294CC_CLASS_NAME = 'PFTest'
295CC_MODULE_DIR = 'system/bt/hci'
296CC_CLASS_FILTER = test_info.TestFilter(CC_CLASS_NAME, frozenset())
297CC_CONFIG_FILE = os.path.join(CC_MODULE_DIR, constants.MODULE_CONFIG)
298CC_MODULE_CLASS_DATA = {
299    constants.TI_REL_CONFIG: CC_CONFIG_FILE,
300    constants.TI_FILTER: frozenset([CC_CLASS_FILTER]),
301}
302CC_MODULE_CLASS_INFO = test_info.TestInfo(
303    CC_MODULE_NAME,
304    atf_tr.AtestTradefedTestRunner.NAME,
305    CLASS_BUILD_TARGETS,
306    CC_MODULE_CLASS_DATA,
307)
308CC_MODULE2_DIR = 'foo/bar/hello'
309CC_MODULE2_NAME = 'hello_world_test'
310CC_PATH = 'pf_test.cc'
311CC_FIND_ONE = (
312    ROOT
313    + 'system/bt/hci/test/pf_test.cc:TEST_F(PFTest, test1) {\n'
314    + ROOT
315    + 'system/bt/hci/test/pf_test.cc:TEST_F(PFTest, test2) {\n'
316)
317CC_FIND_TWO = (
318    ROOT
319    + 'other/dir/test.cpp:TEST(PFTest, test_f) {\n'
320    + ROOT
321    + 'other/dir/test.cpp:TEST(PFTest, test_p) {\n'
322)
323CC_CONFIG2_FILE = os.path.join(CC_MODULE2_DIR, constants.MODULE_CONFIG)
324CC_CLASS_FILTER = test_info.TestFilter(CC_CLASS_NAME + '.*', frozenset())
325CC_CLASS_DATA = {
326    constants.TI_REL_CONFIG: CC_CONFIG_FILE,
327    constants.TI_FILTER: frozenset([CC_CLASS_FILTER]),
328}
329CC_CLASS_INFO = test_info.TestInfo(
330    CC_MODULE_NAME,
331    atf_tr.AtestTradefedTestRunner.NAME,
332    CLASS_BUILD_TARGETS,
333    CC_CLASS_DATA,
334)
335CC_METHOD_NAME = 'test1'
336CC_METHOD2_NAME = 'test2'
337CC_METHOD_FILTER = test_info.TestFilter(
338    CC_CLASS_NAME + '.' + CC_METHOD_NAME, frozenset()
339)
340CC_METHOD2_FILTER = test_info.TestFilter(
341    CC_CLASS_NAME
342    + '.'
343    + CC_METHOD_NAME
344    + ':'
345    + CC_CLASS_NAME
346    + '.'
347    + CC_METHOD2_NAME,
348    frozenset(),
349)
350CC_METHOD3_FILTER = test_info.TestFilter(
351    CC_CLASS_NAME, frozenset([CC_METHOD_NAME])
352)
353CC_METHOD_INFO = test_info.TestInfo(
354    CC_MODULE_NAME,
355    atf_tr.AtestTradefedTestRunner.NAME,
356    MODULE_BUILD_TARGETS,
357    data={
358        constants.TI_REL_CONFIG: CC_CONFIG_FILE,
359        constants.TI_FILTER: frozenset([CC_METHOD_FILTER]),
360    },
361)
362CC_METHOD2_INFO = test_info.TestInfo(
363    CC_MODULE_NAME,
364    atf_tr.AtestTradefedTestRunner.NAME,
365    MODULE_BUILD_TARGETS,
366    data={
367        constants.TI_REL_CONFIG: CC_CONFIG_FILE,
368        constants.TI_FILTER: frozenset([CC_METHOD2_FILTER]),
369    },
370)
371CC_METHOD3_INFO = test_info.TestInfo(
372    CC_MODULE_NAME,
373    atf_tr.AtestTradefedTestRunner.NAME,
374    MODULE_BUILD_TARGETS,
375    data={
376        constants.TI_REL_CONFIG: CC_CONFIG_FILE,
377        constants.TI_FILTER: frozenset([CC_METHOD3_FILTER]),
378    },
379)
380CC_PATH_DATA = {
381    constants.TI_REL_CONFIG: TEST_DATA_CONFIG,
382    constants.TI_FILTER: frozenset(),
383}
384CC_PATH_INFO = test_info.TestInfo(
385    CC_MODULE_NAME,
386    atf_tr.AtestTradefedTestRunner.NAME,
387    MODULE_BUILD_TARGETS,
388    CC_PATH_DATA,
389)
390CC_PATH_DATA2 = {
391    constants.TI_REL_CONFIG: CC_CONFIG_FILE,
392    constants.TI_FILTER: frozenset(),
393}
394CC_PATH_INFO2 = test_info.TestInfo(
395    CC_MODULE_NAME,
396    atf_tr.AtestTradefedTestRunner.NAME,
397    CLASS_BUILD_TARGETS,
398    CC_PATH_DATA2,
399)
400CTS_INT_DIR = 'test/suite_harness/tools/cts-tradefed/res/config'
401# Constrants of java, kt, cc, cpp test_find_class_file() unittest
402FIND_PATH_TESTCASE_JAVA = 'hello_world_test'
403FIND_PATH_FILENAME_CC = 'hello_world_test'
404FIND_PATH_TESTCASE_CC = 'HelloWorldTest'
405FIND_PATH_FOLDER = 'class_file_path_testing'
406FIND_PATH = os.path.join(TEST_DATA_DIR, FIND_PATH_FOLDER)
407
408DEFAULT_INSTALL_PATH = ['/path/to/install']
409# Module names
410MOD1 = 'mod1'
411MOD2 = 'mod2'
412MOD3 = 'mod3'
413FUZZY_MOD1 = 'Mod1'
414FUZZY_MOD2 = 'nod2'
415FUZZY_MOD3 = 'mod3mod3'
416
417INDEX_DIR = os.path.join('/tmp', 'indices')
418LOCATE_CACHE = os.path.join(INDEX_DIR, 'plocate.db')
419LOCATE_CACHE_MD5 = os.path.join(INDEX_DIR, 'plocate.md5')
420CLASS_INDEX = os.path.join(INDEX_DIR, 'classes.idx')
421QCLASS_INDEX = os.path.join(INDEX_DIR, 'fqcn.idx')
422CC_CLASS_INDEX = os.path.join(INDEX_DIR, 'cc_classes.idx')
423PACKAGE_INDEX = os.path.join(INDEX_DIR, 'packages.idx')
424MODULE_INFO_MD5 = os.path.join(INDEX_DIR, 'module-info.md5')
425
426# TF's log dir
427TEST_INFO_DIR = '/tmp/atest_run_1510085893_pi_Nbi'
428
429# Constants for get_test_config unit tests.
430ANDTEST_CONFIG_PATH = 'my/android/config/path'
431SINGLE_CONFIG_PATH = 'my/single/config/path'
432MULTIPLE_CONFIG_PATH = 'my/multiple/config/path'
433MAIN_CONFIG_NAME = 'main_test_config.xml'
434SINGLE_CONFIG_NAME = 'test_config.xml'
435SUB_CONFIG_NAME_2 = 'Multiple2.xml'
436