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"""
16Unittest constants.
17
18Unittest constants get their own file since they're used purely for testing and
19should not be combined with constants_defaults as part of normal atest
20operation. These constants are used commonly as test data so when updating a
21constant, do so with care and run all unittests to make sure nothing breaks.
22"""
23
24import os
25
26import constants
27from test_finders import test_info
28from test_runners import atest_tf_test_runner as atf_tr
29
30ROOT = '/'
31MODULE_DIR = 'foo/bar/jank'
32MODULE2_DIR = 'foo/bar/hello'
33MODULE_NAME = 'CtsJankDeviceTestCases'
34MODULE2_NAME = 'HelloWorldTests'
35CLASS_NAME = 'CtsDeviceJankUi'
36FULL_CLASS_NAME = 'android.jank.cts.ui.CtsDeviceJankUi'
37PACKAGE = 'android.jank.cts.ui'
38FIND_ONE = ROOT + 'foo/bar/jank/src/android/jank/cts/ui/CtsDeviceJankUi.java\n'
39FIND_TWO = ROOT + 'other/dir/test.java\n' + FIND_ONE
40FIND_PKG = ROOT + 'foo/bar/jank/src/android/jank/cts/ui\n'
41INT_NAME = 'example/reboot'
42GTF_INT_NAME = 'some/gtf_int_test'
43TEST_DATA_DIR = os.path.join(os.path.dirname(__file__), 'unittest_data')
44RELATIVE_TEST_DATA_DIR = 'relative_test_data_dir'
45
46INT_DIR = 'tf/contrib/res/config'
47GTF_INT_DIR = 'gtf/core/res/config'
48
49CONFIG_FILE = os.path.join(MODULE_DIR, constants.MODULE_CONFIG)
50CONFIG2_FILE = os.path.join(MODULE2_DIR, constants.MODULE_CONFIG)
51JSON_FILE = 'module-info.json'
52MODULE_INFO_TARGET = '/out/%s' % JSON_FILE
53MODULE_BUILD_TARGETS = {'tradefed-core', MODULE_INFO_TARGET,
54                        'MODULES-IN-%s' % MODULE_DIR.replace('/', '-'),
55                        'module-specific-target'}
56MODULE_DATA = {constants.TI_REL_CONFIG: CONFIG_FILE,
57               constants.TI_FILTER: frozenset()}
58MODULE_INFO = test_info.TestInfo(MODULE_NAME,
59                                 atf_tr.AtestTradefedTestRunner.NAME,
60                                 MODULE_BUILD_TARGETS,
61                                 MODULE_DATA)
62CLASS_FILTER = test_info.TestFilter(FULL_CLASS_NAME, frozenset())
63CLASS_DATA = {constants.TI_REL_CONFIG: CONFIG_FILE,
64              constants.TI_FILTER: frozenset([CLASS_FILTER])}
65PACKAGE_FILTER = test_info.TestFilter(PACKAGE, frozenset())
66PACKAGE_DATA = {constants.TI_REL_CONFIG: CONFIG_FILE,
67                constants.TI_FILTER: frozenset([PACKAGE_FILTER])}
68TEST_DATA_CONFIG = os.path.relpath(os.path.join(TEST_DATA_DIR,
69                                                constants.MODULE_CONFIG), ROOT)
70PATH_DATA = {
71    constants.TI_REL_CONFIG: TEST_DATA_CONFIG,
72    constants.TI_FILTER: frozenset([PACKAGE_FILTER])}
73EMPTY_PATH_DATA = {
74    constants.TI_REL_CONFIG: TEST_DATA_CONFIG,
75    constants.TI_FILTER: frozenset()}
76
77CLASS_BUILD_TARGETS = {'class-specific-target'}
78CLASS_INFO = test_info.TestInfo(MODULE_NAME,
79                                atf_tr.AtestTradefedTestRunner.NAME,
80                                CLASS_BUILD_TARGETS,
81                                CLASS_DATA)
82PACKAGE_INFO = test_info.TestInfo(MODULE_NAME,
83                                  atf_tr.AtestTradefedTestRunner.NAME,
84                                  CLASS_BUILD_TARGETS,
85                                  PACKAGE_DATA)
86PATH_INFO = test_info.TestInfo(MODULE_NAME,
87                               atf_tr.AtestTradefedTestRunner.NAME,
88                               MODULE_BUILD_TARGETS,
89                               PATH_DATA)
90EMPTY_PATH_INFO = test_info.TestInfo(MODULE_NAME,
91                                     atf_tr.AtestTradefedTestRunner.NAME,
92                                     MODULE_BUILD_TARGETS,
93                                     EMPTY_PATH_DATA)
94MODULE_CLASS_COMBINED_BUILD_TARGETS = MODULE_BUILD_TARGETS | CLASS_BUILD_TARGETS
95INT_CONFIG = os.path.join(INT_DIR, INT_NAME + '.xml')
96GTF_INT_CONFIG = os.path.join(GTF_INT_DIR, GTF_INT_NAME + '.xml')
97METHOD_NAME = 'method1'
98METHOD_FILTER = test_info.TestFilter(FULL_CLASS_NAME, frozenset([METHOD_NAME]))
99METHOD_INFO = test_info.TestInfo(
100    MODULE_NAME,
101    atf_tr.AtestTradefedTestRunner.NAME,
102    MODULE_BUILD_TARGETS,
103    data={constants.TI_FILTER: frozenset([METHOD_FILTER]),
104          constants.TI_REL_CONFIG: CONFIG_FILE})
105METHOD2_NAME = 'method2'
106FLAT_METHOD_FILTER = test_info.TestFilter(
107    FULL_CLASS_NAME, frozenset([METHOD_NAME, METHOD2_NAME]))
108INT_INFO = test_info.TestInfo(INT_NAME,
109                              atf_tr.AtestTradefedTestRunner.NAME,
110                              set(),
111                              data={constants.TI_REL_CONFIG: INT_CONFIG,
112                                    constants.TI_FILTER: frozenset()})
113GTF_INT_INFO = test_info.TestInfo(
114    GTF_INT_NAME,
115    atf_tr.AtestTradefedTestRunner.NAME,
116    set(),
117    data={constants.TI_FILTER: frozenset(),
118          constants.TI_REL_CONFIG: GTF_INT_CONFIG})
119
120# Sample test configurations in TEST_MAPPING file.
121TEST_MAPPING_TEST = {'name': MODULE_NAME}
122TEST_MAPPING_TEST_WITH_OPTION = {
123    'name': CLASS_NAME,
124    'options': [
125        {
126            'arg1': 'val1'
127        },
128        {
129            'arg2': ''
130        }
131    ]
132}
133TEST_MAPPING_TEST_WITH_OPTION_STR = '%s (arg1: val1, arg2:)' % CLASS_NAME
134TEST_MAPPING_TEST_WITH_BAD_OPTION = {
135    'name': CLASS_NAME,
136    'options': [
137        {
138            'arg1': 'val1',
139            'arg2': ''
140        }
141    ]
142}
143