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' 57DEFAULT_DEBUG_PORT = '10888' 58COLLECT_TESTS_ONLY = 'COLLECT_TESTS_ONLY' 59TF_TEMPLATE = 'TF_TEMPLATE' 60FLAKES_INFO = 'FLAKES_INFO' 61TF_EARLY_DEVICE_RELEASE = 'TF_EARLY_DEVICE_RELEASE' 62BAZEL_MODE_FEATURES = 'BAZEL_MODE_FEATURES' 63REQUEST_UPLOAD_RESULT = 'REQUEST_UPLOAD_RESULT' 64DISABLE_UPLOAD_RESULT = 'DISABLE_UPLOAD_RESULT' 65MODULES_IN = 'MODULES-IN-' 66NO_ENABLE_ROOT = 'NO_ENABLE_ROOT' 67VERIFY_ENV_VARIABLE = 'VERIFY_ENV_VARIABLE' 68SKIP_VARS = [VERIFY_ENV_VARIABLE] 69AGGREGATE_METRIC_FILTER_ARG = 'AGGREGATE_METRIC_FILTER' 70ENABLE_DEVICE_PREPARER = 'ENABLE_DEVICE_PREPARER' 71ANNOTATION_FILTER = 'ANNOTATION_FILTER' 72BAZEL_ARG = 'BAZEL_ARG' 73TEST_FILTER = 'TEST_FILTER' 74TEST_TIMEOUT = 'TEST_TIMEOUT' 75 76# Robolectric Types: 77ROBOTYPE_MODERN = 1 78ROBOTYPE_LEGACY = 2 79 80# Codes of specific events. These are exceptions that don't stop anything 81# but sending metrics. 82ACCESS_CACHE_FAILURE = 101 83ACCESS_HISTORY_FAILURE = 102 84IMPORT_FAILURE = 103 85PLOCATEDB_LOCKED = 104 86 87# Test finder constants. 88MODULE_CONFIG = 'AndroidTest.xml' 89MODULE_COMPATIBILITY_SUITES = 'compatibility_suites' 90MODULE_NAME = 'module_name' 91MODULE_PATH = 'path' 92MODULE_CLASS = 'class' 93MODULE_INSTALLED = 'installed' 94MODULE_CLASS_ROBOLECTRIC = 'ROBOLECTRIC' 95MODULE_CLASS_NATIVE_TESTS = 'NATIVE_TESTS' 96MODULE_CLASS_JAVA_LIBRARIES = 'JAVA_LIBRARIES' 97MODULE_TEST_CONFIG = 'test_config' 98MODULE_MAINLINE_MODULES = 'test_mainline_modules' 99MODULE_DEPENDENCIES = 'dependencies' 100MODULE_SRCS = 'srcs' 101MODULE_IS_UNIT_TEST = 'is_unit_test' 102MODULE_SHARED_LIBS = 'shared_libs' 103MODULE_RUNTIME_DEPS = 'runtime_dependencies' 104MODULE_DATA_DEPS = 'data_dependencies' 105MODULE_SUPPORTED_VARIANTS = 'supported_variants' 106 107 108# Env constants 109ANDROID_BUILD_TOP = 'ANDROID_BUILD_TOP' 110ANDROID_OUT = 'OUT' 111ANDROID_OUT_DIR = 'OUT_DIR' 112ANDROID_OUT_DIR_COMMON_BASE = 'OUT_DIR_COMMON_BASE' 113ANDROID_HOST_OUT = 'ANDROID_HOST_OUT' 114ANDROID_PRODUCT_OUT = 'ANDROID_PRODUCT_OUT' 115ANDROID_TARGET_PRODUCT = 'TARGET_PRODUCT' 116TARGET_BUILD_VARIANT = 'TARGET_BUILD_VARIANT' 117ANDROID_TARGET_OUT_TESTCASES = 'ANDROID_TARGET_OUT_TESTCASES' 118 119# Test Info data keys 120# Value of include-filter option. 121TI_FILTER = 'filter' 122TI_REL_CONFIG = 'rel_config' 123TI_MODULE_CLASS = 'module_class' 124# Value of module-arg option 125TI_MODULE_ARG = 'module-arg' 126 127# Google TF 128GTF_MODULE = 'google-tradefed' 129GTF_TARGET = 'google-tradefed-core' 130 131# TEST_MAPPING filename 132TEST_MAPPING = 'TEST_MAPPING' 133# Test group for tests in TEST_MAPPING 134TEST_GROUP_PRESUBMIT = 'presubmit' 135TEST_GROUP_PRESUBMIT_LARGE = 'presubmit-large' 136TEST_GROUP_POSTSUBMIT = 'postsubmit' 137TEST_GROUP_ALL = 'all' 138DEFAULT_TEST_GROUPS = [TEST_GROUP_PRESUBMIT, 139 TEST_GROUP_PRESUBMIT_LARGE] 140# Key in TEST_MAPPING file for a list of imported TEST_MAPPING file 141TEST_MAPPING_IMPORTS = 'imports' 142 143# TradeFed command line args 144TF_INCLUDE_FILTER_OPTION = 'include-filter' 145TF_EXCLUDE_FILTER_OPTION = 'exclude-filter' 146TF_INCLUDE_FILTER = '--include-filter' 147TF_EXCLUDE_FILTER = '--exclude-filter' 148TF_ATEST_INCLUDE_FILTER = '--atest-include-filter' 149TF_ATEST_INCLUDE_FILTER_VALUE_FMT = '{test_name}:{test_filter}' 150TF_MODULE_ARG = '--module-arg' 151TF_MODULE_ARG_VALUE_FMT = '{test_name}:{option_name}:{option_value}' 152TF_SUITE_FILTER_ARG_VALUE_FMT = '"{test_name} {option_value}"' 153TF_SKIP_LOADING_CONFIG_JAR = '--skip-loading-config-jar' 154TF_MODULE_FILTER = '--module' 155TF_ENABLE_MAINLINE_PARAMETERIZED_MODULES = '--enable-mainline-parameterized-modules' 156TF_ENABLE_PARAMETERIZED_MODULES = '--enable-parameterized-modules' 157TF_MODULE_PARAMETER = '--module-parameter' 158 159# Suite Plans 160SUITE_PLANS = frozenset(['cts']) 161 162# Constants of Steps 163REBUILD_MODULE_INFO_FLAG = '--rebuild-module-info' 164BUILD_STEP = 'build' 165INSTALL_STEP = 'install' 166TEST_STEP = 'test' 167ALL_STEPS = [BUILD_STEP, INSTALL_STEP, TEST_STEP] 168 169# ANSI code shift for colorful print 170BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = range(8) 171 172# Types of Levenshetine Distance Cost 173COST_TYPO = (1, 1, 1) 174COST_SEARCH = (8, 1, 5) 175LD_RANGE = 2 176 177# Value of TestInfo install_locations. 178DEVICELESS_TEST = 'host' 179DEVICE_TEST = 'device' 180BOTH_TEST = 'both' 181 182# Metrics 183NO_METRICS_ARG = '--no-metrics' 184METRICS_URL = 'http://asuite-218222.appspot.com/atest/metrics' 185EXTERNAL = 'EXTERNAL_RUN' 186INTERNAL = 'INTERNAL_RUN' 187INTERNAL_EMAIL = '@google.com' 188INTERNAL_HOSTNAME = ['.google.com', 'c.googlers.com'] 189CONTENT_LICENSES_URL = 'https://source.android.com/setup/start/licenses' 190CONTRIBUTOR_AGREEMENT_URL = { 191 'INTERNAL': 'https://cla.developers.google.com/', 192 'EXTERNAL': 'https://opensource.google.com/docs/cla/' 193} 194PRIVACY_POLICY_URL = 'https://policies.google.com/privacy' 195TERMS_SERVICE_URL = 'https://policies.google.com/terms' 196TOOL_NAME = 'atest' 197SUB_TOOL_NAME = '' 198USER_FROM_TOOL = 'USER_FROM_TOOL' 199USER_FROM_SUB_TOOL = 'USER_FROM_SUB_TOOL' 200TF_PREPARATION = 'tf-preparation' 201 202# Detect type for local_detect_event. 203# XTS suite types encode from 100 to 199 204DETECT_TYPE_XTS_SUITE = {'cts': 101, 205 '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, ''), 'indexes') 239LOCATE_CACHE = os.path.join(INDEX_DIR, 'plocate.db') 240LOCATE_CACHE_MD5 = os.path.join(INDEX_DIR, 'plocate.md5') 241BUILDFILES_MD5 = os.path.join(INDEX_DIR, 'buildfiles.md5') 242INT_INDEX = os.path.join(INDEX_DIR, 'integration.idx') 243CLASS_INDEX = os.path.join(INDEX_DIR, 'classes.idx') 244CC_CLASS_INDEX = os.path.join(INDEX_DIR, 'cc_classes.idx') 245PACKAGE_INDEX = os.path.join(INDEX_DIR, 'packages.idx') 246QCLASS_INDEX = os.path.join(INDEX_DIR, 'fqcn.idx') 247MODULE_INDEX = 'modules.idx' 248MODULE_INFO_MD5 = 'module-info.md5' 249VERSION_FILE = os.path.join(os.path.dirname(__file__), 'VERSION') 250 251# Regeular Expressions 252CC_EXT_RE = re.compile(r'.*\.(cc|cpp)$') 253JAVA_EXT_RE = re.compile(r'.*\.(java|kt)$') 254# e.g. /path/to/ccfile.cc: TYPED_TEST_P(test_name, method_name){ 255CC_OUTPUT_RE = re.compile( 256 r'(?P<file_path>/.*):\s*(TYPED_TEST(_P)*|TEST(_F|_P)*)\s*\(' 257 r'(?P<test_name>\w+)\s*,\s*(?P<method_name>\w+)\)\s*\{') 258# Used by locate command. 259CC_GREP_RE = r'^\s*(TYPED_TEST(_P)*|TEST(_F|_P)*)\s*\(\w+,' 260# Used by find command. 261CC_GREP_KWRE = r'^\s*(TYPED_TEST(_P)*|TEST(_F|_P)*)\s*\({2},' 262# e.g. /path/to/Javafile.java:package com.android.settings.accessibility 263# grab the path, Javafile(class) and com.android.settings.accessibility(package) 264CLASS_OUTPUT_RE = re.compile(r'(?P<java_path>.*/(?P<class>[A-Z]\w+)\.\w+)[:].*') 265QCLASS_OUTPUT_RE = re.compile(r'(?P<java_path>.*/(?P<class>[A-Z]\w+)\.\w+)' 266 r'[:]\s*package\s+(?P<package>[^(;|\s)]+)\s*') 267PACKAGE_OUTPUT_RE = re.compile(r'(?P<java_dir>/.*/).*[.](java|kt)[:]\s*package\s+' 268 r'(?P<package>[^(;|\s)]+)\s*') 269 270ATEST_RESULT_ROOT = '/tmp/atest_result' 271ATEST_TEST_RECORD_PROTO = 'test_record.proto' 272LATEST_RESULT_FILE = os.path.join(ATEST_RESULT_ROOT, 'LATEST', 'test_result') 273ACLOUD_REPORT_FILE_RE = re.compile(r'.*--report[_-]file(=|\s+)(?P<report_file>[\w/.]+)') 274TEST_WITH_MAINLINE_MODULES_RE = re.compile(r'(?P<test>.*)\[(?P<mainline_modules>.*' 275 r'[.](apk|apks|apex))\]$') 276 277# Tests list which need vts_kernel_tests as test dependency 278REQUIRED_KERNEL_TEST_MODULES = [ 279 'vts_ltp_test_arm', 280 'vts_ltp_test_arm_64', 281 'vts_linux_kselftest_arm_32', 282 'vts_linux_kselftest_arm_64', 283 'vts_linux_kselftest_x86_32', 284 'vts_linux_kselftest_x86_64', 285 'vts_ltp_test_arm_64_lowmem', 286 'vts_ltp_test_arm_64_hwasan', 287 'vts_ltp_test_arm_64_lowmem_hwasan', 288 'vts_ltp_test_arm_lowmem', 289 'vts_ltp_test_x86_64', 290 'vts_ltp_test_x86' 291] 292 293# XTS suite set dependency. 294SUITE_DEPS = {} 295 296# Tradefed log file name term. 297TF_HOST_LOG = 'host_log_*' 298 299# Flake service par path 300FLAKE_SERVICE_PATH = '/foo' 301FLAKE_TMP_PATH = '/tmp' 302FLAKE_FILE = 'flakes_info.par' 303FLAKE_TARGET = 'aosp_cf_x86_phone-userdebug' 304FLAKE_BRANCH = 'aosp-master' 305FLAKE_TEST_NAME = 'suite/test-mapping-presubmit-retry_cloud-tf' 306FLAKE_PERCENT = 'flake_percent' 307FLAKE_POSTSUBMIT = 'postsubmit_flakes_per_week' 308 309# cert status command 310CERT_STATUS_CMD = '' 311 312ASUITE_REPO_PROJECT_NAME = 'platform/tools/asuite' 313 314# logstorage api scope. 315SCOPE_BUILD_API_SCOPE = '' 316STORAGE_API_VERSION = '' 317STORAGE_SERVICE_NAME = '' 318DO_NOT_UPLOAD = 'DO_NOT_UPLOAD' 319CLIENT_ID = '' 320CLIENT_SECRET = '' 321CREDENTIAL_FILE_NAME = '' 322TOKEN_FILE_PATH = '' 323INVOCATION_ID = 'INVOCATION_ID' 324WORKUNIT_ID = 'WORKUNIT_ID' 325LOCAL_BUILD_ID = 'LOCAL_BUILD_ID' 326BUILD_TARGET = 'BUILD_TARGET' 327RESULT_LINK = '' 328TF_GLOBAL_CONFIG = '' 329UPLOAD_TEST_RESULT_MSG = 'Upload test result?' 330DISCOVERY_SERVICE = '' 331STORAGE2_TEST_URI = '' 332 333# SSO constants. 334TOKEN_EXCHANGE_COMMAND = '' 335TOKEN_EXCHANGE_REQUEST = '' 336SCOPE = '' 337 338# Example arguments used in ~/.atest/config 339ATEST_EXAMPLE_ARGS = ('## Specify only one option per line; any test name/path will be ignored automatically.\n' 340 '## Option that follows a "#" will be ignored.\n' 341 'hello_world_test # Test name will be skipped WITHOUT warning.\n' 342 '# -- --module-arg Foo:variable:value # Only support atest arguments so "--" will be ignored.\n' 343 ' # and will stop running tests.\n' 344 '# --iterations=3\n' 345 '# --retry-any-failure=5\n' 346 '# --rerun-until-failure=5\n' 347 '# --start-avd # also run "acloud create" concurrently.\n' 348 '# --all-abi # Set to run tests for all abis.\n' 349 '# --verbose # turn on verbose mode for debugging.\n') 350 351# AndroidJUnitTest related argument. 352ANDROID_JUNIT_CLASS = 'com.android.tradefed.testtype.AndroidJUnitTest' 353INCLUDE_ANNOTATION = 'include-annotation' 354EXCLUDE_ANNOTATION = 'exclude-annotation' 355SUPPORTED_FILTERS = [INCLUDE_ANNOTATION, EXCLUDE_ANNOTATION] 356 357# Tradefed config-descriptor metadata. 358CONFIG_DESCRIPTOR = 'config-descriptor:metadata' 359PARAMETER_KEY = 'parameter' 360MAINLINE_PARAM_KEY = 'mainline-param' 361 362# Tradefed related constant. 363TF_TEST_ARG = '--test-arg' 364TF_AND_JUNIT_CLASS = 'com.android.tradefed.testtype.AndroidJUnitTest' 365TF_EXCLUDE_ANNOTATE = 'exclude-annotation' 366INSTANT_MODE_ANNOTATE = 'android.platform.test.annotations.AppModeInstant' 367TF_PARA_INSTANT_APP = 'instant_app' 368TF_PARA_SECOND_USR = 'secondary_user' 369TF_PARA_MULTIABI = 'multi_abi' 370DEFAULT_EXCLUDE_PARAS = {TF_PARA_INSTANT_APP, 371 TF_PARA_SECOND_USR, 372 TF_PARA_MULTIABI 373 } 374DEFAULT_EXCLUDE_NOT_PARAS = {'not_' + TF_PARA_INSTANT_APP, 375 'not_' + TF_PARA_SECOND_USR, 376 'not_' + TF_PARA_MULTIABI} 377 378# ATest integration test related constants. 379INTEGRATION_TESTS = [os.path.join( 380 os.environ.get(ANDROID_BUILD_TOP, os.getcwd()), 381 'tools/asuite/atest/test_plans/INTEGRATION_TESTS')] 382VERIFY_DATA_PATH = os.path.join( 383 os.environ.get(ANDROID_BUILD_TOP, os.getcwd()), 384 'tools/asuite/atest/test_data/test_commands.json') 385VERIFY_ENV_PATH = os.path.join( 386 os.environ.get(ANDROID_BUILD_TOP, os.getcwd()), 387 'tools/asuite/atest/test_data/test_environ.json') 388 389# Gtest Types 390GTEST_REGULAR = 'regular native test' 391GTEST_TYPED = 'typed test' 392GTEST_TYPED_PARAM = 'typed-parameterized test' 393GTEST_PARAM = 'value-parameterized test' 394 395# Tradefed log saver template for ATest 396ATEST_TF_LOG_SAVER = 'template/log/atest_log_saver' 397DEVICE_SETUP_PREPARER = 'template/preparers/device-preparer' 398LOG_ROOT_OPTION_NAME = 'atest-log-file-path' 399LOG_SAVER_EXT_OPTION = '' 400 401# Log messages here. 402REQUIRE_DEVICES_MSG = ( 403 'Please ensure there is at least one connected device via:\n' 404 ' $ adb devices') 405