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'
59FLAKES_INFO = 'FLAKES_INFO'
60
61# Application exit codes.
62EXIT_CODE_SUCCESS = 0
63EXIT_CODE_ENV_NOT_SETUP = 1
64EXIT_CODE_BUILD_FAILURE = 2
65EXIT_CODE_ERROR = 3
66EXIT_CODE_TEST_NOT_FOUND = 4
67EXIT_CODE_TEST_FAILURE = 5
68EXIT_CODE_VERIFY_FAILURE = 6
69EXIT_CODE_OUTSIDE_ROOT = 7
70EXIT_CODE_AVD_CREATE_FAILURE = 8
71EXIT_CODE_AVD_INVALID_ARGS = 9
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
78MLOCATEDB_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_INSTALLED = 'installed'
87MODULE_CLASS_ROBOLECTRIC = 'ROBOLECTRIC'
88MODULE_CLASS_NATIVE_TESTS = 'NATIVE_TESTS'
89MODULE_CLASS_JAVA_LIBRARIES = 'JAVA_LIBRARIES'
90MODULE_TEST_CONFIG = 'test_config'
91
92# Env constants
93ANDROID_BUILD_TOP = 'ANDROID_BUILD_TOP'
94ANDROID_OUT = 'OUT'
95ANDROID_OUT_DIR = 'OUT_DIR'
96ANDROID_HOST_OUT = 'ANDROID_HOST_OUT'
97ANDROID_PRODUCT_OUT = 'ANDROID_PRODUCT_OUT'
98
99# Test Info data keys
100# Value of include-filter option.
101TI_FILTER = 'filter'
102TI_REL_CONFIG = 'rel_config'
103TI_MODULE_CLASS = 'module_class'
104# Value of module-arg option
105TI_MODULE_ARG = 'module-arg'
106
107# Google TF
108GTF_MODULE = 'google-tradefed'
109GTF_TARGET = 'google-tradefed-core'
110
111# TEST_MAPPING filename
112TEST_MAPPING = 'TEST_MAPPING'
113# Test group for tests in TEST_MAPPING
114TEST_GROUP_PRESUBMIT = 'presubmit'
115TEST_GROUP_POSTSUBMIT = 'postsubmit'
116TEST_GROUP_ALL = 'all'
117# Key in TEST_MAPPING file for a list of imported TEST_MAPPING file
118TEST_MAPPING_IMPORTS = 'imports'
119
120# TradeFed command line args
121TF_INCLUDE_FILTER_OPTION = 'include-filter'
122TF_EXCLUDE_FILTER_OPTION = 'exclude-filter'
123TF_INCLUDE_FILTER = '--include-filter'
124TF_EXCLUDE_FILTER = '--exclude-filter'
125TF_ATEST_INCLUDE_FILTER = '--atest-include-filter'
126TF_ATEST_INCLUDE_FILTER_VALUE_FMT = '{test_name}:{test_filter}'
127TF_MODULE_ARG = '--module-arg'
128TF_MODULE_ARG_VALUE_FMT = '{test_name}:{option_name}:{option_value}'
129TF_SUITE_FILTER_ARG_VALUE_FMT = '"{test_name} {option_value}"'
130TF_SKIP_LOADING_CONFIG_JAR = '--skip-loading-config-jar'
131
132# Suite Plans
133SUITE_PLANS = frozenset(['cts'])
134
135# Constants of Steps
136REBUILD_MODULE_INFO_FLAG = '--rebuild-module-info'
137BUILD_STEP = 'build'
138INSTALL_STEP = 'install'
139TEST_STEP = 'test'
140ALL_STEPS = [BUILD_STEP, INSTALL_STEP, TEST_STEP]
141
142# ANSI code shift for colorful print
143BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = range(8)
144
145# Answers equivalent to YES!
146AFFIRMATIVES = ['y', 'Y', 'yes', 'Yes', 'YES', '']
147LD_RANGE = 2
148
149# Types of Levenshetine Distance Cost
150COST_TYPO = (1, 1, 1)
151COST_SEARCH = (8, 1, 5)
152
153# Value of TestInfo install_locations.
154DEVICELESS_TEST = 'host'
155DEVICE_TEST = 'device'
156BOTH_TEST = 'both'
157
158# Metrics
159NO_METRICS_ARG = '--no-metrics'
160METRICS_URL = 'http://asuite-218222.appspot.com/atest/metrics'
161EXTERNAL = 'EXTERNAL_RUN'
162INTERNAL = 'INTERNAL_RUN'
163INTERNAL_EMAIL = '@google.com'
164INTERNAL_HOSTNAME = ['.google.com', 'c.googlers.com']
165CONTENT_LICENSES_URL = 'https://source.android.com/setup/start/licenses'
166CONTRIBUTOR_AGREEMENT_URL = {
167    'INTERNAL': 'https://cla.developers.google.com/',
168    'EXTERNAL': 'https://opensource.google.com/docs/cla/'
169}
170PRIVACY_POLICY_URL = 'https://policies.google.com/privacy'
171TERMS_SERVICE_URL = 'https://policies.google.com/terms'
172TOOL_NAME = 'atest'
173USER_FROM_TOOL = 'USER_FROM_TOOL'
174TF_PREPARATION = 'tf-preparation'
175
176# Detect type for local_detect_event.
177# Next expansion : DETECT_TYPE_XXX = 3
178DETECT_TYPE_BUG_DETECTED = 0
179DETECT_TYPE_ACLOUD_CREATE = 1
180DETECT_TYPE_FIND_BUILD = 2
181
182# Considering a trade-off between speed and size, we set UPPER_LIMIT to 100000
183# to make maximum file space 10M(100000(records)*100(byte/record)) at most.
184# Therefore, to update history file will spend 1 sec at most in each run.
185UPPER_LIMIT = 100000
186TRIM_TO_SIZE = 50000
187
188# VTS plans
189VTS_STAGING_PLAN = 'vts-staging-default'
190
191# TreeHugger TEST_MAPPING SUITE_PLANS
192TEST_MAPPING_SUITES = ['device-tests', 'general-tests']
193
194# VTS10 TF
195VTS_TF_MODULE = 'vts10-tradefed'
196
197# VTS TF
198VTS_CORE_TF_MODULE = 'vts-tradefed'
199
200# VTS suite set
201VTS_CORE_SUITE = 'vts'
202
203# ATest TF
204ATEST_TF_MODULE = 'atest-tradefed'
205
206# Build environment variable for each build on ATest
207# With RECORD_ALL_DEPS enabled, ${ANDROID_PRODUCT_OUT}/module-info.json will
208# generate modules' dependencies info when make.
209# With SOONG_COLLECT_JAVA_DEPS enabled, out/soong/module_bp_java_deps.json will
210# be generated when make.
211ATEST_BUILD_ENV = {'RECORD_ALL_DEPS':'true', 'SOONG_COLLECT_JAVA_DEPS':'true'}
212
213# Atest index path and relative dirs/caches.
214INDEX_DIR = os.path.join(os.getenv(ANDROID_HOST_OUT, ''), 'indexes')
215LOCATE_CACHE = os.path.join(INDEX_DIR, 'mlocate.db')
216INT_INDEX = os.path.join(INDEX_DIR, 'integration.idx')
217CLASS_INDEX = os.path.join(INDEX_DIR, 'classes.idx')
218CC_CLASS_INDEX = os.path.join(INDEX_DIR, 'cc_classes.idx')
219PACKAGE_INDEX = os.path.join(INDEX_DIR, 'packages.idx')
220QCLASS_INDEX = os.path.join(INDEX_DIR, 'fqcn.idx')
221MODULE_INDEX = os.path.join(INDEX_DIR, 'modules.idx')
222VERSION_FILE = os.path.join(os.path.dirname(__file__), 'VERSION')
223
224# Regeular Expressions
225CC_EXT_RE = re.compile(r'.*\.(cc|cpp)$')
226JAVA_EXT_RE = re.compile(r'.*\.(java|kt)$')
227# e.g. /path/to/ccfile.cc: TEST_F(test_name, method_name){
228CC_OUTPUT_RE = re.compile(r'(?P<file_path>/.*):\s*TEST(_F|_P)?[ ]*\('
229                          r'(?P<test_name>\w+)\s*,\s*(?P<method_name>\w+)\)'
230                          r'\s*\{')
231CC_GREP_RE = r'^[ ]*TEST(_P|_F)?[ ]*\([[:alnum:]].*,'
232# e.g. /path/to/Javafile.java:package com.android.settings.accessibility
233# grab the path, Javafile(class) and com.android.settings.accessibility(package)
234CLASS_OUTPUT_RE = re.compile(r'(?P<java_path>.*/(?P<class>[A-Z]\w+)\.\w+)[:].*')
235QCLASS_OUTPUT_RE = re.compile(r'(?P<java_path>.*/(?P<class>[A-Z]\w+)\.\w+)'
236                              r'[:]\s*package\s+(?P<package>[^(;|\s)]+)\s*')
237PACKAGE_OUTPUT_RE = re.compile(r'(?P<java_dir>/.*/).*[.](java|kt)[:]\s*package\s+'
238                               r'(?P<package>[^(;|\s)]+)\s*')
239
240ATEST_RESULT_ROOT = '/tmp/atest_result'
241ATEST_TEST_RECORD_PROTO = 'test_record.proto'
242LATEST_RESULT_FILE = os.path.join(ATEST_RESULT_ROOT, 'LATEST', 'test_result')
243ACLOUD_REPORT_FILE_RE = re.compile(r'.*--report[_-]file(=|\s+)(?P<report_file>[\w/.]+)')
244
245# Tests list which need vts_kernel_tests as test dependency
246REQUIRED_KERNEL_TEST_MODULES = [
247    'vts_ltp_test_arm',
248    'vts_ltp_test_arm_64',
249    'vts_linux_kselftest_arm_32',
250    'vts_linux_kselftest_arm_64',
251    'vts_linux_kselftest_x86_32',
252    'vts_linux_kselftest_x86_64',
253    'vts_ltp_test_arm_64_lowmem',
254    'vts_ltp_test_arm_64_hwasan',
255    'vts_ltp_test_arm_64_lowmem_hwasan',
256    'vts_ltp_test_arm_lowmem',
257    'vts_ltp_test_x86_64',
258    'vts_ltp_test_x86'
259]
260
261# Tradefed log file name term.
262TF_HOST_LOG = 'host_log_*'
263
264# Flake service par path
265FLAKE_SERVICE_PATH = '/foo'
266FLAKE_TMP_PATH = '/tmp'
267FLAKE_FILE = 'flakes_info.par'
268FLAKE_TARGET = 'aosp_cf_x86_phone-userdebug'
269FLAKE_BRANCH = 'aosp-master'
270FLAKE_TEST_NAME = 'suite/test-mapping-presubmit-retry_cloud-tf'
271FLAKE_PERCENT = 'flake_percent'
272FLAKE_POSTSUBMIT = 'postsubmit_flakes_per_week'
273
274# cert status command
275CERT_STATUS_CMD = ''
276