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' 34TYPO_MODULE_NAME = 'CtsJankDeviceTestCase' 35MODULE2_NAME = 'HelloWorldTests' 36CLASS_NAME = 'CtsDeviceJankUi' 37FULL_CLASS_NAME = 'android.jank.cts.ui.CtsDeviceJankUi' 38PACKAGE = 'android.jank.cts.ui' 39FIND_ONE = ROOT + 'foo/bar/jank/src/android/jank/cts/ui/CtsDeviceJankUi.java\n' 40FIND_TWO = ROOT + 'other/dir/test.java\n' + FIND_ONE 41FIND_PKG = ROOT + 'foo/bar/jank/src/android/jank/cts/ui\n' 42INT_NAME = 'example/reboot' 43GTF_INT_NAME = 'some/gtf_int_test' 44TEST_DATA_DIR = os.path.join(os.path.dirname(__file__), 'unittest_data') 45TEST_CONFIG_DATA_DIR = os.path.join(TEST_DATA_DIR, 'test_config') 46 47INT_DIR = 'tf/contrib/res/config' 48GTF_INT_DIR = 'gtf/core/res/config' 49 50CONFIG_FILE = os.path.join(MODULE_DIR, constants.MODULE_CONFIG) 51CONFIG2_FILE = os.path.join(MODULE2_DIR, constants.MODULE_CONFIG) 52JSON_FILE = 'module-info.json' 53MODULE_INFO_TARGET = '/out/%s' % JSON_FILE 54MODULE_BUILD_TARGETS = {'tradefed-core', MODULE_INFO_TARGET, 55 'MODULES-IN-%s' % MODULE_DIR.replace('/', '-'), 56 'module-specific-target'} 57MODULE_BUILD_TARGETS2 = {'build-target2'} 58MODULE_DATA = {constants.TI_REL_CONFIG: CONFIG_FILE, 59 constants.TI_FILTER: frozenset()} 60MODULE_DATA2 = {constants.TI_REL_CONFIG: CONFIG_FILE, 61 constants.TI_FILTER: frozenset()} 62MODULE_INFO = test_info.TestInfo(MODULE_NAME, 63 atf_tr.AtestTradefedTestRunner.NAME, 64 MODULE_BUILD_TARGETS, 65 MODULE_DATA) 66MODULE_INFO2 = test_info.TestInfo(MODULE2_NAME, 67 atf_tr.AtestTradefedTestRunner.NAME, 68 MODULE_BUILD_TARGETS2, 69 MODULE_DATA2) 70MODULE_INFOS = [MODULE_INFO] 71MODULE_INFOS2 = [MODULE_INFO, MODULE_INFO2] 72CLASS_FILTER = test_info.TestFilter(FULL_CLASS_NAME, frozenset()) 73CLASS_DATA = {constants.TI_REL_CONFIG: CONFIG_FILE, 74 constants.TI_FILTER: frozenset([CLASS_FILTER])} 75PACKAGE_FILTER = test_info.TestFilter(PACKAGE, frozenset()) 76PACKAGE_DATA = {constants.TI_REL_CONFIG: CONFIG_FILE, 77 constants.TI_FILTER: frozenset([PACKAGE_FILTER])} 78TEST_DATA_CONFIG = os.path.relpath(os.path.join(TEST_DATA_DIR, 79 constants.MODULE_CONFIG), ROOT) 80PATH_DATA = { 81 constants.TI_REL_CONFIG: TEST_DATA_CONFIG, 82 constants.TI_FILTER: frozenset([PACKAGE_FILTER])} 83EMPTY_PATH_DATA = { 84 constants.TI_REL_CONFIG: TEST_DATA_CONFIG, 85 constants.TI_FILTER: frozenset()} 86 87CLASS_BUILD_TARGETS = {'class-specific-target'} 88CLASS_INFO = test_info.TestInfo(MODULE_NAME, 89 atf_tr.AtestTradefedTestRunner.NAME, 90 CLASS_BUILD_TARGETS, 91 CLASS_DATA) 92CLASS_INFOS = [CLASS_INFO] 93 94CLASS_BUILD_TARGETS2 = {'class-specific-target2'} 95CLASS_DATA2 = {constants.TI_REL_CONFIG: CONFIG_FILE, 96 constants.TI_FILTER: frozenset([CLASS_FILTER])} 97CLASS_INFO2 = test_info.TestInfo(MODULE2_NAME, 98 atf_tr.AtestTradefedTestRunner.NAME, 99 CLASS_BUILD_TARGETS2, 100 CLASS_DATA2) 101CLASS_INFOS = [CLASS_INFO] 102CLASS_INFOS2 = [CLASS_INFO, CLASS_INFO2] 103PACKAGE_INFO = test_info.TestInfo(MODULE_NAME, 104 atf_tr.AtestTradefedTestRunner.NAME, 105 CLASS_BUILD_TARGETS, 106 PACKAGE_DATA) 107PATH_INFO = test_info.TestInfo(MODULE_NAME, 108 atf_tr.AtestTradefedTestRunner.NAME, 109 MODULE_BUILD_TARGETS, 110 PATH_DATA) 111EMPTY_PATH_INFO = test_info.TestInfo(MODULE_NAME, 112 atf_tr.AtestTradefedTestRunner.NAME, 113 MODULE_BUILD_TARGETS, 114 EMPTY_PATH_DATA) 115MODULE_CLASS_COMBINED_BUILD_TARGETS = MODULE_BUILD_TARGETS | CLASS_BUILD_TARGETS 116INT_CONFIG = os.path.join(INT_DIR, INT_NAME + '.xml') 117GTF_INT_CONFIG = os.path.join(GTF_INT_DIR, GTF_INT_NAME + '.xml') 118METHOD_NAME = 'method1' 119METHOD_FILTER = test_info.TestFilter(FULL_CLASS_NAME, frozenset([METHOD_NAME])) 120METHOD_INFO = test_info.TestInfo( 121 MODULE_NAME, 122 atf_tr.AtestTradefedTestRunner.NAME, 123 MODULE_BUILD_TARGETS, 124 data={constants.TI_FILTER: frozenset([METHOD_FILTER]), 125 constants.TI_REL_CONFIG: CONFIG_FILE}) 126METHOD2_NAME = 'method2' 127FLAT_METHOD_FILTER = test_info.TestFilter( 128 FULL_CLASS_NAME, frozenset([METHOD_NAME, METHOD2_NAME])) 129INT_INFO = test_info.TestInfo(INT_NAME, 130 atf_tr.AtestTradefedTestRunner.NAME, 131 set(), 132 data={constants.TI_REL_CONFIG: INT_CONFIG, 133 constants.TI_FILTER: frozenset()}) 134GTF_INT_INFO = test_info.TestInfo( 135 GTF_INT_NAME, 136 atf_tr.AtestTradefedTestRunner.NAME, 137 set(), 138 data={constants.TI_FILTER: frozenset(), 139 constants.TI_REL_CONFIG: GTF_INT_CONFIG}) 140 141# Sample test configurations in TEST_MAPPING file. 142TEST_MAPPING_TEST = {'name': MODULE_NAME, 'host': True} 143TEST_MAPPING_TEST_WITH_OPTION = { 144 'name': CLASS_NAME, 145 'options': [ 146 { 147 'arg1': 'val1' 148 }, 149 { 150 'arg2': '' 151 } 152 ] 153} 154TEST_MAPPING_TEST_WITH_OPTION_STR = '%s (arg1: val1, arg2:)' % CLASS_NAME 155TEST_MAPPING_TEST_WITH_BAD_OPTION = { 156 'name': CLASS_NAME, 157 'options': [ 158 { 159 'arg1': 'val1', 160 'arg2': '' 161 } 162 ] 163} 164TEST_MAPPING_TEST_WITH_BAD_HOST_VALUE = { 165 'name': CLASS_NAME, 166 'host': 'true' 167} 168# Constrants of cc test unittest 169FIND_CC_ONE = ROOT + 'foo/bt/hci/test/pf_test.cc\n' 170CC_MODULE_NAME = 'net_test_hci' 171CC_CLASS_NAME = 'PFTest' 172CC_MODULE_DIR = 'system/bt/hci' 173CC_CLASS_FILTER = test_info.TestFilter(CC_CLASS_NAME+".*", frozenset()) 174CC_CONFIG_FILE = os.path.join(CC_MODULE_DIR, constants.MODULE_CONFIG) 175CC_MODULE_CLASS_DATA = {constants.TI_REL_CONFIG: CC_CONFIG_FILE, 176 constants.TI_FILTER: frozenset([CC_CLASS_FILTER])} 177CC_MODULE_CLASS_INFO = test_info.TestInfo(CC_MODULE_NAME, 178 atf_tr.AtestTradefedTestRunner.NAME, 179 CLASS_BUILD_TARGETS, CC_MODULE_CLASS_DATA) 180CC_MODULE2_DIR = 'foo/bar/hello' 181CC_MODULE2_NAME = 'hello_world_test' 182CC_PATH = 'pf_test.cc' 183CC_FIND_ONE = ROOT + 'system/bt/hci/test/pf_test.cc:TEST_F(PFTest, test1) {\n' + \ 184 ROOT + 'system/bt/hci/test/pf_test.cc:TEST_F(PFTest, test2) {\n' 185CC_FIND_TWO = ROOT + 'other/dir/test.cpp:TEST(PFTest, test_f) {\n' + \ 186 ROOT + 'other/dir/test.cpp:TEST(PFTest, test_p) {\n' 187CC_CONFIG2_FILE = os.path.join(CC_MODULE2_DIR, constants.MODULE_CONFIG) 188CC_CLASS_FILTER = test_info.TestFilter(CC_CLASS_NAME+".*", frozenset()) 189CC_CLASS_DATA = {constants.TI_REL_CONFIG: CC_CONFIG_FILE, 190 constants.TI_FILTER: frozenset([CC_CLASS_FILTER])} 191CC_CLASS_INFO = test_info.TestInfo(CC_MODULE_NAME, 192 atf_tr.AtestTradefedTestRunner.NAME, 193 CLASS_BUILD_TARGETS, CC_CLASS_DATA) 194CC_METHOD_NAME = 'test1' 195CC_METHOD2_NAME = 'test2' 196CC_METHOD_FILTER = test_info.TestFilter(CC_CLASS_NAME+"."+CC_METHOD_NAME, 197 frozenset()) 198CC_METHOD2_FILTER = test_info.TestFilter(CC_CLASS_NAME+"."+CC_METHOD_NAME+ \ 199 ":"+CC_CLASS_NAME+"."+CC_METHOD2_NAME, 200 frozenset()) 201CC_METHOD_INFO = test_info.TestInfo( 202 CC_MODULE_NAME, 203 atf_tr.AtestTradefedTestRunner.NAME, 204 MODULE_BUILD_TARGETS, 205 data={constants.TI_REL_CONFIG: CC_CONFIG_FILE, 206 constants.TI_FILTER: frozenset([CC_METHOD_FILTER])}) 207CC_METHOD2_INFO = test_info.TestInfo( 208 CC_MODULE_NAME, 209 atf_tr.AtestTradefedTestRunner.NAME, 210 MODULE_BUILD_TARGETS, 211 data={constants.TI_REL_CONFIG: CC_CONFIG_FILE, 212 constants.TI_FILTER: frozenset([CC_METHOD2_FILTER])}) 213CC_PATH_DATA = { 214 constants.TI_REL_CONFIG: TEST_DATA_CONFIG, 215 constants.TI_FILTER: frozenset()} 216CC_PATH_INFO = test_info.TestInfo(CC_MODULE_NAME, 217 atf_tr.AtestTradefedTestRunner.NAME, 218 MODULE_BUILD_TARGETS, 219 CC_PATH_DATA) 220CC_PATH_DATA2 = {constants.TI_REL_CONFIG: CC_CONFIG_FILE, 221 constants.TI_FILTER: frozenset()} 222CC_PATH_INFO2 = test_info.TestInfo(CC_MODULE_NAME, 223 atf_tr.AtestTradefedTestRunner.NAME, 224 CLASS_BUILD_TARGETS, CC_PATH_DATA2) 225CTS_INT_DIR = 'test/suite_harness/tools/cts-tradefed/res/config' 226# Constrants of java, kt, cc, cpp test_find_class_file() unittest 227FIND_PATH_TESTCASE_JAVA = 'hello_world_test' 228FIND_PATH_FILENAME_CC = 'hello_world_test' 229FIND_PATH_TESTCASE_CC = 'HelloWorldTest' 230FIND_PATH_FOLDER = 'class_file_path_testing' 231FIND_PATH = os.path.join(TEST_DATA_DIR, FIND_PATH_FOLDER) 232 233DEFAULT_INSTALL_PATH = ['/path/to/install'] 234# Module names 235MOD1 = 'mod1' 236MOD2 = 'mod2' 237MOD3 = 'mod3' 238FUZZY_MOD1 = 'Mod1' 239FUZZY_MOD2 = 'nod2' 240FUZZY_MOD3 = 'mod3mod3' 241 242LOCATE_CACHE = '/tmp/mcloate.db' 243CLASS_INDEX = '/tmp/classes.idx' 244QCLASS_INDEX = '/tmp/fqcn.idx' 245CC_CLASS_INDEX = '/tmp/cc_classes.idx' 246PACKAGE_INDEX = '/tmp/packages.idx' 247MODULE_INDEX = '/tmp/modules.idx' 248