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