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_DATA = {constants.TI_REL_CONFIG: CONFIG_FILE, 58 constants.TI_FILTER: frozenset()} 59MODULE_INFO = test_info.TestInfo(MODULE_NAME, 60 atf_tr.AtestTradefedTestRunner.NAME, 61 MODULE_BUILD_TARGETS, 62 MODULE_DATA) 63CLASS_FILTER = test_info.TestFilter(FULL_CLASS_NAME, frozenset()) 64CLASS_DATA = {constants.TI_REL_CONFIG: CONFIG_FILE, 65 constants.TI_FILTER: frozenset([CLASS_FILTER])} 66PACKAGE_FILTER = test_info.TestFilter(PACKAGE, frozenset()) 67PACKAGE_DATA = {constants.TI_REL_CONFIG: CONFIG_FILE, 68 constants.TI_FILTER: frozenset([PACKAGE_FILTER])} 69TEST_DATA_CONFIG = os.path.relpath(os.path.join(TEST_DATA_DIR, 70 constants.MODULE_CONFIG), ROOT) 71PATH_DATA = { 72 constants.TI_REL_CONFIG: TEST_DATA_CONFIG, 73 constants.TI_FILTER: frozenset([PACKAGE_FILTER])} 74EMPTY_PATH_DATA = { 75 constants.TI_REL_CONFIG: TEST_DATA_CONFIG, 76 constants.TI_FILTER: frozenset()} 77 78CLASS_BUILD_TARGETS = {'class-specific-target'} 79CLASS_INFO = test_info.TestInfo(MODULE_NAME, 80 atf_tr.AtestTradefedTestRunner.NAME, 81 CLASS_BUILD_TARGETS, 82 CLASS_DATA) 83PACKAGE_INFO = test_info.TestInfo(MODULE_NAME, 84 atf_tr.AtestTradefedTestRunner.NAME, 85 CLASS_BUILD_TARGETS, 86 PACKAGE_DATA) 87PATH_INFO = test_info.TestInfo(MODULE_NAME, 88 atf_tr.AtestTradefedTestRunner.NAME, 89 MODULE_BUILD_TARGETS, 90 PATH_DATA) 91EMPTY_PATH_INFO = test_info.TestInfo(MODULE_NAME, 92 atf_tr.AtestTradefedTestRunner.NAME, 93 MODULE_BUILD_TARGETS, 94 EMPTY_PATH_DATA) 95MODULE_CLASS_COMBINED_BUILD_TARGETS = MODULE_BUILD_TARGETS | CLASS_BUILD_TARGETS 96INT_CONFIG = os.path.join(INT_DIR, INT_NAME + '.xml') 97GTF_INT_CONFIG = os.path.join(GTF_INT_DIR, GTF_INT_NAME + '.xml') 98METHOD_NAME = 'method1' 99METHOD_FILTER = test_info.TestFilter(FULL_CLASS_NAME, frozenset([METHOD_NAME])) 100METHOD_INFO = test_info.TestInfo( 101 MODULE_NAME, 102 atf_tr.AtestTradefedTestRunner.NAME, 103 MODULE_BUILD_TARGETS, 104 data={constants.TI_FILTER: frozenset([METHOD_FILTER]), 105 constants.TI_REL_CONFIG: CONFIG_FILE}) 106METHOD2_NAME = 'method2' 107FLAT_METHOD_FILTER = test_info.TestFilter( 108 FULL_CLASS_NAME, frozenset([METHOD_NAME, METHOD2_NAME])) 109INT_INFO = test_info.TestInfo(INT_NAME, 110 atf_tr.AtestTradefedTestRunner.NAME, 111 set(), 112 data={constants.TI_REL_CONFIG: INT_CONFIG, 113 constants.TI_FILTER: frozenset()}) 114GTF_INT_INFO = test_info.TestInfo( 115 GTF_INT_NAME, 116 atf_tr.AtestTradefedTestRunner.NAME, 117 set(), 118 data={constants.TI_FILTER: frozenset(), 119 constants.TI_REL_CONFIG: GTF_INT_CONFIG}) 120 121# Sample test configurations in TEST_MAPPING file. 122TEST_MAPPING_TEST = {'name': MODULE_NAME, 'host': True} 123TEST_MAPPING_TEST_WITH_OPTION = { 124 'name': CLASS_NAME, 125 'options': [ 126 { 127 'arg1': 'val1' 128 }, 129 { 130 'arg2': '' 131 } 132 ] 133} 134TEST_MAPPING_TEST_WITH_OPTION_STR = '%s (arg1: val1, arg2:)' % CLASS_NAME 135TEST_MAPPING_TEST_WITH_BAD_OPTION = { 136 'name': CLASS_NAME, 137 'options': [ 138 { 139 'arg1': 'val1', 140 'arg2': '' 141 } 142 ] 143} 144TEST_MAPPING_TEST_WITH_BAD_HOST_VALUE = { 145 'name': CLASS_NAME, 146 'host': 'true' 147} 148# Constrants of cc test unittest 149FIND_CC_ONE = ROOT + 'foo/bt/hci/test/pf_test.cc\n' 150CC_MODULE_NAME = 'net_test_hci' 151CC_CLASS_NAME = 'PFTest' 152CC_MODULE_DIR = 'system/bt/hci' 153CC_CLASS_FILTER = test_info.TestFilter(CC_CLASS_NAME+".*", frozenset()) 154CC_CONFIG_FILE = os.path.join(CC_MODULE_DIR, constants.MODULE_CONFIG) 155CC_MODULE_CLASS_DATA = {constants.TI_REL_CONFIG: CC_CONFIG_FILE, 156 constants.TI_FILTER: frozenset([CC_CLASS_FILTER])} 157CC_MODULE_CLASS_INFO = test_info.TestInfo(CC_MODULE_NAME, 158 atf_tr.AtestTradefedTestRunner.NAME, 159 CLASS_BUILD_TARGETS, CC_MODULE_CLASS_DATA) 160CC_MODULE2_DIR = 'foo/bar/hello' 161CC_MODULE2_NAME = 'hello_world_test' 162CC_PATH = 'pf_test.cc' 163CC_FIND_ONE = ROOT + 'system/bt/hci/test/pf_test.cc:TEST_F(PFTest, test1) {\n' +\ 164 ROOT + 'system/bt/hci/test/pf_test.cc:TEST_F(PFTest, test2) {\n' 165CC_FIND_TWO = ROOT + 'other/dir/test.cpp:TEST(PFTest, test_f) {\n' +\ 166 ROOT + 'other/dir/test.cpp:TEST(PFTest, test_p) {\n' 167CC_CONFIG2_FILE = os.path.join(CC_MODULE2_DIR, constants.MODULE_CONFIG) 168CC_CLASS_FILTER = test_info.TestFilter(CC_CLASS_NAME+".*", frozenset()) 169CC_CLASS_DATA = {constants.TI_REL_CONFIG: CC_CONFIG_FILE, 170 constants.TI_FILTER: frozenset([CC_CLASS_FILTER])} 171CC_CLASS_INFO = test_info.TestInfo(CC_MODULE_NAME, 172 atf_tr.AtestTradefedTestRunner.NAME, 173 CLASS_BUILD_TARGETS, CC_CLASS_DATA) 174CC_METHOD_NAME = 'test1' 175CC_METHOD2_NAME = 'test2' 176CC_METHOD_FILTER = test_info.TestFilter(CC_CLASS_NAME+"."+CC_METHOD_NAME, 177 frozenset()) 178CC_METHOD2_FILTER = test_info.TestFilter(CC_CLASS_NAME+"."+CC_METHOD_NAME+\ 179 ":"+CC_CLASS_NAME+"."+CC_METHOD2_NAME, 180 frozenset()) 181CC_METHOD_INFO = test_info.TestInfo( 182 CC_MODULE_NAME, 183 atf_tr.AtestTradefedTestRunner.NAME, 184 MODULE_BUILD_TARGETS, 185 data={constants.TI_REL_CONFIG: CC_CONFIG_FILE, 186 constants.TI_FILTER: frozenset([CC_METHOD_FILTER])}) 187CC_METHOD2_INFO = test_info.TestInfo( 188 CC_MODULE_NAME, 189 atf_tr.AtestTradefedTestRunner.NAME, 190 MODULE_BUILD_TARGETS, 191 data={constants.TI_REL_CONFIG: CC_CONFIG_FILE, 192 constants.TI_FILTER: frozenset([CC_METHOD2_FILTER])}) 193CC_PATH_DATA = { 194 constants.TI_REL_CONFIG: TEST_DATA_CONFIG, 195 constants.TI_FILTER: frozenset()} 196CC_PATH_INFO = test_info.TestInfo(CC_MODULE_NAME, 197 atf_tr.AtestTradefedTestRunner.NAME, 198 MODULE_BUILD_TARGETS, 199 CC_PATH_DATA) 200CC_PATH_DATA2 = {constants.TI_REL_CONFIG: CC_CONFIG_FILE, 201 constants.TI_FILTER: frozenset()} 202CC_PATH_INFO2 = test_info.TestInfo(CC_MODULE_NAME, 203 atf_tr.AtestTradefedTestRunner.NAME, 204 CLASS_BUILD_TARGETS, CC_PATH_DATA2) 205CTS_INT_DIR = 'test/suite_harness/tools/cts-tradefed/res/config' 206# Constrants of java, kt, cc, cpp test_find_class_file() unittest 207FIND_PATH_TESTCASE_JAVA = 'hello_world_test' 208FIND_PATH_FILENAME_CC = 'hello_world_test' 209FIND_PATH_TESTCASE_CC = 'HelloWorldTest' 210FIND_PATH_FOLDER = 'class_file_path_testing' 211FIND_PATH = os.path.join(TEST_DATA_DIR, FIND_PATH_FOLDER) 212 213DEFAULT_INSTALL_PATH = ['/path/to/install'] 214# Module names 215MOD1 = 'mod1' 216MOD2 = 'mod2' 217MOD3 = 'mod3' 218FUZZY_MOD1 = 'Mod1' 219FUZZY_MOD2 = 'nod2' 220FUZZY_MOD3 = 'mod3mod3' 221