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