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"""Various globals used by atest.""" 16 17 18from collections import namedtuple 19import os 20from pathlib import Path 21import re 22import tempfile 23 24# Result server constants for atest_utils. 25RESULT_SERVER = '' 26RESULT_SERVER_ARGS = [] 27RESULT_SERVER_TIMEOUT = 5 28# Result arguments if tests are configured in TEST_MAPPING. 29TEST_MAPPING_RESULT_SERVER_ARGS = [] 30 31# Google service key for gts tests. 32GTS_GOOGLE_SERVICE_ACCOUNT = '' 33 34# Arg constants. 35WAIT_FOR_DEBUGGER = 'WAIT_FOR_DEBUGGER' 36DISABLE_INSTALL = 'DISABLE_INSTALL' 37DISABLE_TEARDOWN = 'DISABLE_TEARDOWN' 38SERIAL = 'SERIAL' 39SHARDING = 'SHARDING' 40ALL_ABI = 'ALL_ABI' 41HOST = 'HOST' 42DEVICE_ONLY = 'DEVICE_ONLY' 43CUSTOM_ARGS = 'CUSTOM_ARGS' 44DRY_RUN = 'DRY_RUN' 45ANDROID_SERIAL = 'ANDROID_SERIAL' 46INSTANT = 'INSTANT' 47USER_TYPE = 'USER_TYPE' 48ITERATIONS = 'ITERATIONS' 49RERUN_UNTIL_FAILURE = 'RERUN_UNTIL_FAILURE' 50RETRY_ANY_FAILURE = 'RETRY_ANY_FAILURE' 51TF_DEBUG = 'TF_DEBUG' 52DEFAULT_DEBUG_PORT = '10888' 53COLLECT_TESTS_ONLY = 'COLLECT_TESTS_ONLY' 54TF_TEMPLATE = 'TF_TEMPLATE' 55BAZEL_MODE_FEATURES = 'BAZEL_MODE_FEATURES' 56REQUEST_UPLOAD_RESULT = 'REQUEST_UPLOAD_RESULT' 57DISABLE_UPLOAD_RESULT = 'DISABLE_UPLOAD_RESULT' 58MODULES_IN = 'MODULES-IN-' 59AGGREGATE_METRIC_FILTER_ARG = 'AGGREGATE_METRIC_FILTER' 60ANNOTATION_FILTER = 'ANNOTATION_FILTER' 61BAZEL_ARG = 'BAZEL_ARG' 62COVERAGE = 'COVERAGE' 63TEST_FILTER = 'TEST_FILTER' 64TEST_TIMEOUT = 'TEST_TIMEOUT' 65VERBOSE = 'VERBOSE' 66LD_LIBRARY_PATH = 'LD_LIBRARY_PATH' 67USE_TF_MIN_BASE_TEMPLATE = 'USE_TF_MIN_BASE_TEMPLATE' 68 69# Robolectric Types: 70ROBOTYPE_MODERN = 1 71ROBOTYPE_LEGACY = 2 72 73# Codes of specific events. These are exceptions that don't stop anything 74# but sending metrics. 75ACCESS_CACHE_FAILURE = 101 76ACCESS_HISTORY_FAILURE = 102 77IMPORT_FAILURE = 103 78PLOCATEDB_LOCKED = 104 79 80# Test finder constants. 81MODULE_CONFIG = 'AndroidTest.xml' 82MODULE_COMPATIBILITY_SUITES = 'compatibility_suites' 83MODULE_NAME = 'module_name' 84MODULE_PATH = 'path' 85MODULE_CLASS = 'class' 86MODULE_AUTO_TEST_CONFIG = 'auto_test_config' 87MODULE_INSTALLED = 'installed' 88MODULE_CLASS_ROBOLECTRIC = 'ROBOLECTRIC' 89MODULE_CLASS_NATIVE_TESTS = 'NATIVE_TESTS' 90MODULE_CLASS_JAVA_LIBRARIES = 'JAVA_LIBRARIES' 91MODULE_TEST_CONFIG = 'test_config' 92MODULE_MAINLINE_MODULES = 'test_mainline_modules' 93MODULE_DEPENDENCIES = 'dependencies' 94MODULE_SRCS = 'srcs' 95MODULE_IS_UNIT_TEST = 'is_unit_test' 96MODULE_SHARED_LIBS = 'shared_libs' 97MODULE_RUNTIME_DEPS = 'runtime_dependencies' 98MODULE_STATIC_DEPS = 'static_dependencies' 99MODULE_DATA_DEPS = 'data_dependencies' 100MODULE_SUPPORTED_VARIANTS = 'supported_variants' 101MODULE_LIBS = 'libs' 102MODULE_STATIC_LIBS = 'static_libs' 103MODULE_HOST_DEPS = 'host_dependencies' 104MODULE_TARGET_DEPS = 'target_dependencies' 105MODULE_TEST_OPTIONS_TAGS = 'test_options_tags' 106MODULE_INFO_ID = 'module_info_id' 107 108 109# Env constants 110ANDROID_BUILD_TOP = 'ANDROID_BUILD_TOP' 111ANDROID_OUT = 'OUT' 112ANDROID_OUT_DIR = 'OUT_DIR' 113ANDROID_OUT_DIR_COMMON_BASE = 'OUT_DIR_COMMON_BASE' 114ANDROID_HOST_OUT = 'ANDROID_HOST_OUT' 115ANDROID_PRODUCT_OUT = 'ANDROID_PRODUCT_OUT' 116ANDROID_TARGET_PRODUCT = 'TARGET_PRODUCT' 117TARGET_BUILD_VARIANT = 'TARGET_BUILD_VARIANT' 118ANDROID_TARGET_OUT_TESTCASES = 'ANDROID_TARGET_OUT_TESTCASES' 119 120# Test Info data keys 121# Value of include-filter option. 122TI_FILTER = 'filter' 123TI_REL_CONFIG = 'rel_config' 124TI_MODULE_CLASS = 'module_class' 125# Value of module-arg option 126TI_MODULE_ARG = 'module-arg' 127 128# Google TF 129GTF_MODULE = 'google-tradefed' 130GTF_TARGET = 'google-tradefed-core' 131# Defines the TF build targets which only exist in internal branches. 132# TODO(b/283364305) Have a flag and use the setup in vendor to define the flag. 133GTF_TARGETS = set() 134 135# TEST_MAPPING filename 136TEST_MAPPING = 'TEST_MAPPING' 137# Test group for tests in TEST_MAPPING 138TEST_GROUP_PRESUBMIT = 'presubmit' 139TEST_GROUP_PRESUBMIT_LARGE = 'presubmit-large' 140TEST_GROUP_POSTSUBMIT = 'postsubmit' 141TEST_GROUP_ALL = 'all' 142DEFAULT_TEST_GROUPS = [TEST_GROUP_PRESUBMIT, TEST_GROUP_PRESUBMIT_LARGE] 143# Key in TEST_MAPPING file for a list of imported TEST_MAPPING file 144TEST_MAPPING_IMPORTS = 'imports' 145 146# TradeFed command line args 147TF_INCLUDE_FILTER_OPTION = 'include-filter' 148TF_EXCLUDE_FILTER_OPTION = 'exclude-filter' 149TF_INCLUDE_FILTER = '--include-filter' 150TF_EXCLUDE_FILTER = '--exclude-filter' 151TF_ATEST_INCLUDE_FILTER = '--atest-include-filter' 152TF_ATEST_INCLUDE_FILTER_VALUE_FMT = '{test_name}:{test_filter}' 153TF_MODULE_ARG = '--module-arg' 154TF_MODULE_ARG_VALUE_FMT = '{test_name}:{option_name}:{option_value}' 155TF_SUITE_FILTER_ARG_VALUE_FMT = '"{test_name} {option_value}"' 156TF_SKIP_LOADING_CONFIG_JAR = '--skip-loading-config-jar' 157TF_MODULE_FILTER = '--module' 158TF_ENABLE_MAINLINE_PARAMETERIZED_MODULES = ( 159 '--enable-mainline-parameterized-modules' 160) 161TF_ENABLE_PARAMETERIZED_MODULES = '--enable-parameterized-modules' 162TF_MODULE_PARAMETER = '--module-parameter' 163 164# Mobly constants 165MOBLY_TEST_OPTIONS_TAG = 'mobly' 166 167# Suite Plans 168SUITE_PLANS = frozenset(['cts']) 169 170# Constants of Steps 171REBUILD_MODULE_INFO_FLAG = '--rebuild-module-info' 172BUILD_STEP = 'build' 173DEVICE_UPDATE_STEP = 'update_device' 174INSTALL_STEP = 'install' 175TEST_STEP = 'test' 176ALL_STEPS = [BUILD_STEP, INSTALL_STEP, TEST_STEP] 177 178# ANSI code shift for colorful print 179BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = range(8) 180 181# Types of Levenshetine Distance Cost 182COST_TYPO = (1, 1, 1) 183COST_SEARCH = (8, 1, 5) 184LD_RANGE = 2 185 186# Value of TestInfo install_locations. 187DEVICELESS_TEST = 'host' 188DEVICE_TEST = 'device' 189BOTH_TEST = 'both' 190 191# Metrics 192NO_METRICS_ARG = '--no-metrics' 193EXTERNAL = 'EXTERNAL_RUN' 194INTERNAL = 'INTERNAL_RUN' 195INTERNAL_EMAIL = '@google.com' 196INTERNAL_HOSTNAME = ['.google.com', 'c.googlers.com'] 197TOOL_NAME = 'atest' 198SUB_TOOL_NAME = '' 199USER_FROM_TOOL = 'USER_FROM_TOOL' 200USER_FROM_SUB_TOOL = 'USER_FROM_SUB_TOOL' 201TF_PREPARATION = 'tf-preparation' 202 203# Detect type for local_detect_event. 204# XTS suite types encode from 100 to 199 205DETECT_TYPE_XTS_SUITE = {'cts': 101, 'vts': 104} 206 207# Considering a trade-off between speed and size, we set UPPER_LIMIT to 100000 208# to make maximum file space 10M(100000(records)*100(byte/record)) at most. 209# Therefore, to update history file will spend 1 sec at most in each run. 210UPPER_LIMIT = 100000 211TRIM_TO_SIZE = 50000 212 213# VTS plans 214VTS_STAGING_PLAN = 'vts-staging-default' 215 216# TreeHugger TEST_MAPPING SUITE_PLANS 217TEST_MAPPING_SUITES = ['device-tests', 'general-tests'] 218 219# VTS10 TF 220VTS_TF_MODULE = 'vts10-tradefed' 221 222# VTS TF 223VTS_CORE_TF_MODULE = 'vts-tradefed' 224 225# VTS suite set 226VTS_CORE_SUITE = 'vts' 227 228# MTS suite set 229MTS_SUITE = 'mts' 230 231# CTS tradefed jar 232CTS_JAR = 'cts-tradefed' 233 234# ATest TF 235ATEST_TF_MODULE = 'atest-tradefed' 236 237# Atest index path and relative dirs/caches. 238INDEX_DIR = os.path.join(os.getenv(ANDROID_HOST_OUT, ''), 'indices') 239LOCATE_CACHE = os.path.join(INDEX_DIR, 'plocate.db') 240BUILDFILES_STP = os.path.join(INDEX_DIR, 'buildfiles.stp') 241INT_INDEX = os.path.join(INDEX_DIR, 'integration.idx') 242CLASS_INDEX = os.path.join(INDEX_DIR, 'classes.idx') 243CC_CLASS_INDEX = os.path.join(INDEX_DIR, 'cc_classes.idx') 244PACKAGE_INDEX = os.path.join(INDEX_DIR, 'packages.idx') 245QCLASS_INDEX = os.path.join(INDEX_DIR, 'fqcn.idx') 246 247# Regeular Expressions 248CC_EXT_RE = re.compile(r'.*\.(cc|cpp)$') 249JAVA_EXT_RE = re.compile(r'.*\.(java|kt)$') 250# e.g. /path/to/ccfile.cc: TYPED_TEST_P(test_name, method_name){ 251CC_OUTPUT_RE = re.compile( 252 r'(?P<file_path>/.*):\s*(TYPED_TEST(_P)*|TEST(_F|_P)*)\s*\(' 253 r'(?P<test_name>\w+)\s*,\s*(?P<method_name>\w+)\)\s*\{' 254) 255# Used by locate command. 256CC_GREP_RE = r'^\s*(TYPED_TEST(_P)*|TEST(_F|_P)*)\s*\(\w+,' 257# e.g. /path/to/Javafile.java:package com.android.settings.accessibility 258# grab the path, Javafile(class) and com.android.settings.accessibility(package) 259CLASS_OUTPUT_RE = re.compile(r'(?P<java_path>.*/(?P<class>[A-Z]\w+)\.\w+)[:].*') 260QCLASS_OUTPUT_RE = re.compile( 261 r'(?P<java_path>.*/(?P<class>[A-Z]\w+)\.\w+)' 262 r'[:]\s*package\s+(?P<package>[^(;|\s)]+)\s*' 263) 264PACKAGE_OUTPUT_RE = re.compile( 265 r'(?P<java_dir>/.*/).*[.](java|kt)[:]\s*package\s+' 266 r'(?P<package>[^(;|\s)]+)\s*' 267) 268 269ATEST_RESULT_ROOT = Path( 270 tempfile.gettempdir(), 271 'atest_result_%s' % Path('~').expanduser().name.replace(' ', '_'), 272) 273ATEST_TEST_RECORD_PROTO = 'test_record.proto' 274LATEST_RESULT_FILE = os.path.join(ATEST_RESULT_ROOT, 'LATEST', 'test_result') 275 276# Tests list which need vts_ltp_tests as test dependency 277REQUIRED_LTP_TEST_MODULES = [ 278 'vts_ltp_test_arm', 279 'vts_ltp_test_arm_64', 280 'vts_ltp_test_arm_64_lowmem', 281 'vts_ltp_test_arm_64_hwasan', 282 'vts_ltp_test_arm_64_lowmem_hwasan', 283 'vts_ltp_test_arm_lowmem', 284 'vts_ltp_test_x86_64', 285 'vts_ltp_test_x86', 286] 287# Tests list which need vts_kselftest_tests as test dependency 288REQUIRED_KSELFTEST_TEST_MODULES = [ 289 'vts_linux_kselftest_arm_32', 290 'vts_linux_kselftest_arm_64', 291 'vts_linux_kselftest_x86_32', 292 'vts_linux_kselftest_x86_64', 293] 294 295# XTS suite set dependency. 296SUITE_DEPS = {} 297 298# Tradefed log file name term. 299TF_HOST_LOG = 'host_log_*' 300 301ASUITE_REPO_PROJECT_NAME = 'platform/tools/asuite' 302 303# logstorage api scope. 304SCOPE_BUILD_API_SCOPE = '' 305STORAGE_API_VERSION = '' 306STORAGE_API_VERSION_LEGACY = '' 307STORAGE_SERVICE_NAME = '' 308CLIENT_ID = '' 309CLIENT_SECRET = '' 310CREDENTIAL_FILE_NAME = '' 311TOKEN_FILE_PATH = '' 312INVOCATION_ID = 'INVOCATION_ID' 313WORKUNIT_ID = 'WORKUNIT_ID' 314LOCAL_BUILD_ID = 'LOCAL_BUILD_ID' 315BUILD_TARGET = 'BUILD_TARGET' 316RESULT_LINK = '' 317TF_GLOBAL_CONFIG = '' 318DISCOVERY_SERVICE = '' 319DISCOVERY_SERVICE_LEGACY = '' 320STORAGE2_TEST_URI = '' 321 322# SSO constants. 323TOKEN_EXCHANGE_COMMAND = '' 324TOKEN_EXCHANGE_REQUEST = '' 325SCOPE = '' 326 327# Example arguments used in ~/.atest/config 328ATEST_EXAMPLE_ARGS = ( 329 '## Specify only one option per line; any test name/path will be ignored' 330 ' automatically.\n## Option that follows a "#" will be' 331 ' ignored.\nhello_world_test # Test name will be skipped WITHOUT' 332 ' warning.\n# -- --module-arg Foo:variable:value # Only support atest' 333 ' arguments so "--" will be ignored.\n ' 334 ' # and will stop running tests.\n# --iterations=3\n#' 335 ' --retry-any-failure=5\n# --rerun-until-failure=5\n# --start-avd #' 336 ' also run "acloud create" concurrently.\n# --all-abi # Set to run' 337 ' tests for all abis.\n# --verbose # turn on verbose mode for' 338 ' debugging.\n' 339) 340 341# AndroidJUnitTest related argument. 342ANDROID_JUNIT_CLASS = 'com.android.tradefed.testtype.AndroidJUnitTest' 343INCLUDE_ANNOTATION = 'include-annotation' 344EXCLUDE_ANNOTATION = 'exclude-annotation' 345SUPPORTED_FILTERS = [INCLUDE_ANNOTATION, EXCLUDE_ANNOTATION] 346 347# Tradefed config-descriptor metadata. 348CONFIG_DESCRIPTOR = 'config-descriptor:metadata' 349PARAMETER_KEY = 'parameter' 350MAINLINE_PARAM_KEY = 'mainline-param' 351 352# Tradefed related constant. 353TF_TEST_ARG = '--test-arg' 354TF_AND_JUNIT_CLASS = 'com.android.tradefed.testtype.AndroidJUnitTest' 355TF_EXCLUDE_ANNOTATE = 'exclude-annotation' 356INSTANT_MODE_ANNOTATE = 'android.platform.test.annotations.AppModeInstant' 357TF_PARA_INSTANT_APP = 'instant_app' 358TF_PARA_SECOND_USR = 'secondary_user' 359TF_PARA_MULTIABI = 'multi_abi' 360DEFAULT_EXCLUDE_PARAS = { 361 TF_PARA_INSTANT_APP, 362 TF_PARA_SECOND_USR, 363 TF_PARA_MULTIABI, 364} 365DEFAULT_EXCLUDE_NOT_PARAS = { 366 'not_' + TF_PARA_INSTANT_APP, 367 'not_' + TF_PARA_SECOND_USR, 368 'not_' + TF_PARA_MULTIABI, 369} 370RUNNER_COMMAND_PATH = os.path.join( 371 os.environ.get(ANDROID_BUILD_TOP, os.getcwd()), 372 'tools/asuite/atest/test_data/runner_commands.json', 373) 374 375# Tradefed log saver template for ATest 376ATEST_TF_LOG_SAVER = 'template/log/atest_log_saver' 377DEVICE_SETUP_PREPARER = 'template/preparers/device-preparer' 378LOG_ROOT_OPTION_NAME = 'atest-log-file-path' 379LOG_SAVER_EXT_OPTION = '' 380 381# Tradefed log saver template for uploading logs to cloud storage. 382GOOGLE_LOG_SAVER = '' 383GOOGLE_LOG_SAVER_LOG_ROOT_OPTION_NAME = '' 384GOOGLE_LOG_SAVER_EXT_OPTION = '' 385 386# Log messages here. 387REQUIRE_DEVICES_MSG = ( 388 'Please ensure there is at least one connected device via:\n' 389 ' $ adb devices' 390) 391 392# Default shard num. 393SHARD_NUM = 2 394