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