1# Copyright 2017, 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""" 16Various globals used by atest. 17""" 18 19# pylint: disable=line-too-long 20 21import os 22import re 23 24MODE = 'DEFAULT' 25 26# Result server constants for atest_utils. 27RESULT_SERVER = '' 28RESULT_SERVER_ARGS = [] 29RESULT_SERVER_TIMEOUT = 5 30# Result arguments if tests are configured in TEST_MAPPING. 31TEST_MAPPING_RESULT_SERVER_ARGS = [] 32 33# Google service key for gts tests. 34GTS_GOOGLE_SERVICE_ACCOUNT = '' 35 36# Arg constants. 37WAIT_FOR_DEBUGGER = 'WAIT_FOR_DEBUGGER' 38DISABLE_INSTALL = 'DISABLE_INSTALL' 39DISABLE_TEARDOWN = 'DISABLE_TEARDOWN' 40PRE_PATCH_ITERATIONS = 'PRE_PATCH_ITERATIONS' 41POST_PATCH_ITERATIONS = 'POST_PATCH_ITERATIONS' 42PRE_PATCH_FOLDER = 'PRE_PATCH_FOLDER' 43POST_PATCH_FOLDER = 'POST_PATCH_FOLDER' 44SERIAL = 'SERIAL' 45SHARDING = 'SHARDING' 46ALL_ABI = 'ALL_ABI' 47HOST = 'HOST' 48CUSTOM_ARGS = 'CUSTOM_ARGS' 49DRY_RUN = 'DRY_RUN' 50ANDROID_SERIAL = 'ANDROID_SERIAL' 51INSTANT = 'INSTANT' 52USER_TYPE = 'USER_TYPE' 53ITERATIONS = 'ITERATIONS' 54RERUN_UNTIL_FAILURE = 'RERUN_UNTIL_FAILURE' 55RETRY_ANY_FAILURE = 'RETRY_ANY_FAILURE' 56TF_DEBUG = 'TF_DEBUG' 57COLLECT_TESTS_ONLY = 'COLLECT_TESTS_ONLY' 58TF_TEMPLATE = 'TF_TEMPLATE' 59 60# Application exit codes. 61EXIT_CODE_SUCCESS = 0 62EXIT_CODE_ENV_NOT_SETUP = 1 63EXIT_CODE_BUILD_FAILURE = 2 64EXIT_CODE_ERROR = 3 65EXIT_CODE_TEST_NOT_FOUND = 4 66EXIT_CODE_TEST_FAILURE = 5 67EXIT_CODE_VERIFY_FAILURE = 6 68EXIT_CODE_OUTSIDE_ROOT = 7 69 70# Codes of specific events. These are exceptions that don't stop anything 71# but sending metrics. 72ACCESS_CACHE_FAILURE = 101 73ACCESS_HISTORY_FAILURE = 102 74IMPORT_FAILURE = 103 75MLOCATEDB_LOCKED = 104 76 77# Test finder constants. 78MODULE_CONFIG = 'AndroidTest.xml' 79MODULE_COMPATIBILITY_SUITES = 'compatibility_suites' 80MODULE_NAME = 'module_name' 81MODULE_PATH = 'path' 82MODULE_CLASS = 'class' 83MODULE_INSTALLED = 'installed' 84MODULE_CLASS_ROBOLECTRIC = 'ROBOLECTRIC' 85MODULE_CLASS_NATIVE_TESTS = 'NATIVE_TESTS' 86MODULE_CLASS_JAVA_LIBRARIES = 'JAVA_LIBRARIES' 87MODULE_TEST_CONFIG = 'test_config' 88 89# Env constants 90ANDROID_BUILD_TOP = 'ANDROID_BUILD_TOP' 91ANDROID_OUT = 'OUT' 92ANDROID_OUT_DIR = 'OUT_DIR' 93ANDROID_HOST_OUT = 'ANDROID_HOST_OUT' 94ANDROID_PRODUCT_OUT = 'ANDROID_PRODUCT_OUT' 95 96# Test Info data keys 97# Value of include-filter option. 98TI_FILTER = 'filter' 99TI_REL_CONFIG = 'rel_config' 100TI_MODULE_CLASS = 'module_class' 101# Value of module-arg option 102TI_MODULE_ARG = 'module-arg' 103 104# Google TF 105GTF_MODULE = 'google-tradefed' 106GTF_TARGET = 'google-tradefed-core' 107 108# TEST_MAPPING filename 109TEST_MAPPING = 'TEST_MAPPING' 110# Test group for tests in TEST_MAPPING 111TEST_GROUP_PRESUBMIT = 'presubmit' 112TEST_GROUP_POSTSUBMIT = 'postsubmit' 113TEST_GROUP_ALL = 'all' 114# Key in TEST_MAPPING file for a list of imported TEST_MAPPING file 115TEST_MAPPING_IMPORTS = 'imports' 116 117# TradeFed command line args 118TF_INCLUDE_FILTER_OPTION = 'include-filter' 119TF_EXCLUDE_FILTER_OPTION = 'exclude-filter' 120TF_INCLUDE_FILTER = '--include-filter' 121TF_EXCLUDE_FILTER = '--exclude-filter' 122TF_ATEST_INCLUDE_FILTER = '--atest-include-filter' 123TF_ATEST_INCLUDE_FILTER_VALUE_FMT = '{test_name}:{test_filter}' 124TF_MODULE_ARG = '--module-arg' 125TF_MODULE_ARG_VALUE_FMT = '{test_name}:{option_name}:{option_value}' 126TF_SUITE_FILTER_ARG_VALUE_FMT = '"{test_name} {option_value}"' 127TF_SKIP_LOADING_CONFIG_JAR = '--skip-loading-config-jar' 128 129# Suite Plans 130SUITE_PLANS = frozenset(['cts']) 131 132# Constants of Steps 133REBUILD_MODULE_INFO_FLAG = '--rebuild-module-info' 134BUILD_STEP = 'build' 135INSTALL_STEP = 'install' 136TEST_STEP = 'test' 137ALL_STEPS = [BUILD_STEP, INSTALL_STEP, TEST_STEP] 138 139# ANSI code shift for colorful print 140BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = range(8) 141 142# Answers equivalent to YES! 143AFFIRMATIVES = ['y', 'Y', 'yes', 'Yes', 'YES', ''] 144LD_RANGE = 2 145 146# Types of Levenshetine Distance Cost 147COST_TYPO = (1, 1, 1) 148COST_SEARCH = (8, 1, 5) 149 150# Value of TestInfo install_locations. 151DEVICELESS_TEST = 'host' 152DEVICE_TEST = 'device' 153BOTH_TEST = 'both' 154 155# Metrics 156NO_METRICS_ARG = '--no-metrics' 157METRICS_URL = 'http://asuite-218222.appspot.com/atest/metrics' 158EXTERNAL = 'EXTERNAL_RUN' 159INTERNAL = 'INTERNAL_RUN' 160INTERNAL_EMAIL = '@google.com' 161INTERNAL_HOSTNAME = ['.google.com', 'c.googlers.com'] 162CONTENT_LICENSES_URL = 'https://source.android.com/setup/start/licenses' 163CONTRIBUTOR_AGREEMENT_URL = { 164 'INTERNAL': 'https://cla.developers.google.com/', 165 'EXTERNAL': 'https://opensource.google.com/docs/cla/' 166} 167PRIVACY_POLICY_URL = 'https://policies.google.com/privacy' 168TERMS_SERVICE_URL = 'https://policies.google.com/terms' 169TOOL_NAME = 'atest' 170USER_FROM_TOOL = 'USER_FROM_TOOL' 171TF_PREPARATION = 'tf-preparation' 172 173# Detect type for local_detect_event. 174# Next expansion : DETECT_TYPE_XXX = 1 175DETECT_TYPE_BUG_DETECTED = 0 176# Considering a trade-off between speed and size, we set UPPER_LIMIT to 100000 177# to make maximum file space 10M(100000(records)*100(byte/record)) at most. 178# Therefore, to update history file will spend 1 sec at most in each run. 179UPPER_LIMIT = 100000 180TRIM_TO_SIZE = 50000 181 182# VTS plans 183VTS_STAGING_PLAN = 'vts-staging-default' 184 185# TreeHugger TEST_MAPPING SUITE_PLANS 186TEST_MAPPING_SUITES = ['device-tests', 'general-tests'] 187 188# VTS10 TF 189VTS_TF_MODULE = 'vts10-tradefed' 190 191# VTS TF 192VTS_CORE_TF_MODULE = 'vts-tradefed' 193 194# VTS suite set 195VTS_CORE_SUITE = 'vts' 196 197# ATest TF 198ATEST_TF_MODULE = 'atest-tradefed' 199 200# Build environment variable for each build on ATest 201# With RECORD_ALL_DEPS enabled, ${ANDROID_PRODUCT_OUT}/module-info.json will 202# generate modules' dependencies info when make. 203# With SOONG_COLLECT_JAVA_DEPS enabled, out/soong/module_bp_java_deps.json will 204# be generated when make. 205ATEST_BUILD_ENV = {'RECORD_ALL_DEPS':'true', 'SOONG_COLLECT_JAVA_DEPS':'true'} 206 207# Atest index path and relative dirs/caches. 208INDEX_DIR = os.path.join(os.getenv(ANDROID_HOST_OUT, ''), 'indexes') 209LOCATE_CACHE = os.path.join(INDEX_DIR, 'mlocate.db') 210INT_INDEX = os.path.join(INDEX_DIR, 'integration.idx') 211CLASS_INDEX = os.path.join(INDEX_DIR, 'classes.idx') 212CC_CLASS_INDEX = os.path.join(INDEX_DIR, 'cc_classes.idx') 213PACKAGE_INDEX = os.path.join(INDEX_DIR, 'packages.idx') 214QCLASS_INDEX = os.path.join(INDEX_DIR, 'fqcn.idx') 215MODULE_INDEX = os.path.join(INDEX_DIR, 'modules.idx') 216VERSION_FILE = os.path.join(os.path.dirname(__file__), 'VERSION') 217 218# Regeular Expressions 219CC_EXT_RE = re.compile(r'.*\.(cc|cpp)$') 220JAVA_EXT_RE = re.compile(r'.*\.(java|kt)$') 221# e.g. /path/to/ccfile.cc: TEST_F(test_name, method_name){ 222CC_OUTPUT_RE = re.compile(r'(?P<file_path>/.*):\s*TEST(_F|_P)?[ ]*\(' 223 r'(?P<test_name>\w+)\s*,\s*(?P<method_name>\w+)\)' 224 r'\s*\{') 225CC_GREP_RE = r'^[ ]*TEST(_P|_F)?[ ]*\([[:alnum:]].*,' 226# e.g. /path/to/Javafile.java:package com.android.settings.accessibility 227# grab the path, Javafile(class) and com.android.settings.accessibility(package) 228CLASS_OUTPUT_RE = re.compile(r'(?P<java_path>.*/(?P<class>[A-Z]\w+)\.\w+)[:].*') 229QCLASS_OUTPUT_RE = re.compile(r'(?P<java_path>.*/(?P<class>[A-Z]\w+)\.\w+)' 230 r'[:]\s*package\s+(?P<package>[^(;|\s)]+)\s*') 231PACKAGE_OUTPUT_RE = re.compile(r'(?P<java_dir>/.*/).*[.](java|kt)[:]\s*package\s+' 232 r'(?P<package>[^(;|\s)]+)\s*') 233 234ATEST_RESULT_ROOT = '/tmp/atest_result' 235LATEST_RESULT_FILE = os.path.join(ATEST_RESULT_ROOT, 'LATEST', 'test_result') 236 237# Tests list which need vts_kernel_tests as test dependency 238REQUIRED_KERNEL_TEST_MODULES = [ 239 'vts_ltp_test_arm', 240 'vts_ltp_test_arm_64', 241 'vts_linux_kselftest_arm_32', 242 'vts_linux_kselftest_arm_64', 243 'vts_linux_kselftest_x86_32', 244 'vts_linux_kselftest_x86_64', 245 'vts_ltp_test_arm_64_lowmem', 246 'vts_ltp_test_arm_64_hwasan', 247 'vts_ltp_test_arm_64_lowmem_hwasan', 248 'vts_ltp_test_arm_lowmem', 249 'vts_ltp_test_x86_64', 250 'vts_ltp_test_x86' 251] 252