blob: d45d009ba46dae201e80e380edfcabb4c604b97f [file] [log] [blame]
Shubham Ajmera65adb8b2017-02-06 16:04:25 +00001# 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
15import os
Igor Murashkinfecb4ef2017-02-09 10:42:23 -080016import re
Shubham Ajmera65adb8b2017-02-06 16:04:25 +000017import tempfile
18import subprocess
19
Igor Murashkin6b61c802017-04-03 14:33:22 -070020_env = dict(os.environ)
Shubham Ajmera65adb8b2017-02-06 16:04:25 +000021
Igor Murashkin6b61c802017-04-03 14:33:22 -070022def _getEnvBoolean(var, default):
23 val = _env.get(var)
Shubham Ajmera65adb8b2017-02-06 16:04:25 +000024 if val:
25 if val == "True" or val == "true":
26 return True
27 if val == "False" or val == "false":
28 return False
29 return default
30
Igor Murashkinfecb4ef2017-02-09 10:42:23 -080031_DUMP_MANY_VARS_LIST = ['HOST_2ND_ARCH_PREFIX',
32 'TARGET_2ND_ARCH',
33 'TARGET_ARCH',
34 'HOST_PREFER_32_BIT',
Shubham Ajmerac33c0872017-07-20 18:41:52 -070035 'HOST_OUT_EXECUTABLES',
Colin Crosse0ef0a82017-07-27 21:29:18 +000036 'ANDROID_JAVA_TOOLCHAIN',
37 'ANDROID_COMPILE_WITH_JACK']
Igor Murashkinfecb4ef2017-02-09 10:42:23 -080038_DUMP_MANY_VARS = None # To be set to a dictionary with above list being the keys,
39 # and the build variable being the value.
Igor Murashkin6b61c802017-04-03 14:33:22 -070040def _dump_many_vars(var_name):
Igor Murashkinfecb4ef2017-02-09 10:42:23 -080041 """
42 Reach into the Android build system to dump many build vars simultaneously.
43 Since the make system is so slow, we want to avoid calling into build frequently.
44 """
45 global _DUMP_MANY_VARS
46 global _DUMP_MANY_VARS_LIST
47
48 # Look up var from cache.
49 if _DUMP_MANY_VARS:
50 return _DUMP_MANY_VARS[var_name]
51
52 all_vars=" ".join(_DUMP_MANY_VARS_LIST)
53
Shubham Ajmera65adb8b2017-02-06 16:04:25 +000054 # The command is taken from build/envsetup.sh to fetch build variables.
Igor Murashkinfecb4ef2017-02-09 10:42:23 -080055 command = ("CALLED_FROM_SETUP=true " # Enable the 'dump-many-vars' make target.
56 "BUILD_SYSTEM=build/core " # Set up lookup path for make includes.
Shubham Ajmera65adb8b2017-02-06 16:04:25 +000057 "make --no-print-directory -C \"%s\" -f build/core/config.mk "
Igor Murashkinfecb4ef2017-02-09 10:42:23 -080058 "dump-many-vars DUMP_MANY_VARS=\"%s\"") % (ANDROID_BUILD_TOP, all_vars)
59
Shubham Ajmerafe793492017-03-16 13:31:35 -070060 config = subprocess.Popen(command,
61 stdout=subprocess.PIPE,
62 universal_newlines=True,
Igor Murashkinfecb4ef2017-02-09 10:42:23 -080063 shell=True).communicate()[0] # read until EOF, select stdin
64 # Prints out something like:
65 # TARGET_ARCH='arm64'
66 # HOST_ARCH='x86_64'
67 _DUMP_MANY_VARS = {}
68 for line in config.split("\n"):
69 # Split out "$key='$value'" via regex.
70 match = re.search("([^=]+)='([^']*)", line)
71 if not match:
72 continue
73 key = match.group(1)
74 value = match.group(2)
75 _DUMP_MANY_VARS[key] = value
76
77 return _DUMP_MANY_VARS[var_name]
78
Igor Murashkin6b61c802017-04-03 14:33:22 -070079def _get_build_var(var_name):
80 return _dump_many_vars(var_name)
Shubham Ajmera65adb8b2017-02-06 16:04:25 +000081
Colin Crosse0ef0a82017-07-27 21:29:18 +000082def _get_build_var_boolean(var, default):
83 val = _get_build_var(var)
84 if val:
85 if val == "True" or val == "true":
86 return True
87 if val == "False" or val == "false":
88 return False
89 return default
90
Shubham Ajmera65adb8b2017-02-06 16:04:25 +000091def get_env(key):
Igor Murashkin6b61c802017-04-03 14:33:22 -070092 return _env.get(key)
Shubham Ajmera65adb8b2017-02-06 16:04:25 +000093
Igor Murashkin6b61c802017-04-03 14:33:22 -070094def _get_android_build_top():
95 path_to_top = _env.get('ANDROID_BUILD_TOP')
96 if not path_to_top:
97 # nothing set. try to guess it based on the relative path of this env.py file.
98 this_file_path = os.path.realpath(__file__)
99 path_to_top = os.path.join(os.path.dirname(this_file_path), '../../../')
100 path_to_top = os.path.realpath(path_to_top)
101
102 if not os.path.exists(os.path.join(path_to_top, 'build/envsetup.sh')):
103 raise AssertionError("env.py must be located inside an android source tree")
104
105 return path_to_top
106
107ANDROID_BUILD_TOP = _get_android_build_top()
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000108
Igor Murashkin8889a892017-04-24 16:09:15 -0700109# Compiling with jack? Possible values in (True, False, 'default')
Colin Crosse0ef0a82017-07-27 21:29:18 +0000110ANDROID_COMPILE_WITH_JACK = _get_build_var_boolean('ANDROID_COMPILE_WITH_JACK', 'default')
Igor Murashkin8889a892017-04-24 16:09:15 -0700111
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000112# Directory used for temporary test files on the host.
113ART_HOST_TEST_DIR = tempfile.mkdtemp(prefix = 'test-art-')
114
115# Keep going after encountering a test failure?
Igor Murashkin6b61c802017-04-03 14:33:22 -0700116ART_TEST_KEEP_GOING = _getEnvBoolean('ART_TEST_KEEP_GOING', True)
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000117
118# Do you want all tests, even those that are time consuming?
Igor Murashkin6b61c802017-04-03 14:33:22 -0700119ART_TEST_FULL = _getEnvBoolean('ART_TEST_FULL', False)
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000120
121# Do you want interpreter tests run?
Igor Murashkin6b61c802017-04-03 14:33:22 -0700122ART_TEST_INTERPRETER = _getEnvBoolean('ART_TEST_INTERPRETER', ART_TEST_FULL)
123ART_TEST_INTERPRETER_ACCESS_CHECKS = _getEnvBoolean('ART_TEST_INTERPRETER_ACCESS_CHECKS',
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000124 ART_TEST_FULL)
125
126# Do you want JIT tests run?
Igor Murashkin6b61c802017-04-03 14:33:22 -0700127ART_TEST_JIT = _getEnvBoolean('ART_TEST_JIT', ART_TEST_FULL)
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000128
129# Do you want optimizing compiler tests run?
Igor Murashkin6b61c802017-04-03 14:33:22 -0700130ART_TEST_OPTIMIZING = _getEnvBoolean('ART_TEST_OPTIMIZING', ART_TEST_FULL)
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000131
132# Do you want to test the optimizing compiler with graph coloring register allocation?
Igor Murashkin6b61c802017-04-03 14:33:22 -0700133ART_TEST_OPTIMIZING_GRAPH_COLOR = _getEnvBoolean('ART_TEST_OPTIMIZING_GRAPH_COLOR', ART_TEST_FULL)
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000134
Jeff Hao002b9312017-03-27 16:23:08 -0700135# Do you want to do run-tests with profiles?
Igor Murashkin6b61c802017-04-03 14:33:22 -0700136ART_TEST_SPEED_PROFILE = _getEnvBoolean('ART_TEST_SPEED_PROFILE', ART_TEST_FULL)
Jeff Hao002b9312017-03-27 16:23:08 -0700137
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000138# Do we want to test PIC-compiled tests ("apps")?
Igor Murashkin6b61c802017-04-03 14:33:22 -0700139ART_TEST_PIC_TEST = _getEnvBoolean('ART_TEST_PIC_TEST', ART_TEST_FULL)
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000140# Do you want tracing tests run?
Igor Murashkin6b61c802017-04-03 14:33:22 -0700141ART_TEST_TRACE = _getEnvBoolean('ART_TEST_TRACE', ART_TEST_FULL)
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000142
143# Do you want tracing tests (streaming mode) run?
Igor Murashkin6b61c802017-04-03 14:33:22 -0700144ART_TEST_TRACE_STREAM = _getEnvBoolean('ART_TEST_TRACE_STREAM', ART_TEST_FULL)
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000145
146# Do you want tests with GC verification enabled run?
Igor Murashkin6b61c802017-04-03 14:33:22 -0700147ART_TEST_GC_VERIFY = _getEnvBoolean('ART_TEST_GC_VERIFY', ART_TEST_FULL)
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000148
149# Do you want tests with the GC stress mode enabled run?
Igor Murashkin6b61c802017-04-03 14:33:22 -0700150ART_TEST_GC_STRESS = _getEnvBoolean('ART_TEST_GC_STRESS', ART_TEST_FULL)
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000151
152# Do you want tests with the JNI forcecopy mode enabled run?
Igor Murashkin6b61c802017-04-03 14:33:22 -0700153ART_TEST_JNI_FORCECOPY = _getEnvBoolean('ART_TEST_JNI_FORCECOPY', ART_TEST_FULL)
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000154
155# Do you want run-tests with relocation disabled run?
Igor Murashkin6b61c802017-04-03 14:33:22 -0700156ART_TEST_RUN_TEST_RELOCATE = _getEnvBoolean('ART_TEST_RUN_TEST_RELOCATE', ART_TEST_FULL)
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000157
158# Do you want run-tests with prebuilding?
Igor Murashkin6b61c802017-04-03 14:33:22 -0700159ART_TEST_RUN_TEST_PREBUILD = _getEnvBoolean('ART_TEST_RUN_TEST_PREBUILD', ART_TEST_FULL)
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000160
161# Do you want run-tests with no prebuilding enabled run?
Igor Murashkin6b61c802017-04-03 14:33:22 -0700162ART_TEST_RUN_TEST_NO_PREBUILD = _getEnvBoolean('ART_TEST_RUN_TEST_NO_PREBUILD', ART_TEST_FULL)
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000163
164# Do you want run-tests with a pregenerated core.art?
Igor Murashkin6b61c802017-04-03 14:33:22 -0700165ART_TEST_RUN_TEST_IMAGE = _getEnvBoolean('ART_TEST_RUN_TEST_IMAGE', ART_TEST_FULL)
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000166
167# Do you want run-tests without a pregenerated core.art?
Igor Murashkin6b61c802017-04-03 14:33:22 -0700168ART_TEST_RUN_TEST_NO_IMAGE = _getEnvBoolean('ART_TEST_RUN_TEST_NO_IMAGE', ART_TEST_FULL)
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000169
170# Do you want run-tests with relocation enabled but patchoat failing?
Igor Murashkin6b61c802017-04-03 14:33:22 -0700171ART_TEST_RUN_TEST_RELOCATE_NO_PATCHOAT = _getEnvBoolean('ART_TEST_RUN_TEST_RELOCATE_NO_PATCHOAT',
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000172 ART_TEST_FULL)
173
174# Do you want run-tests without a dex2oat?
Igor Murashkin6b61c802017-04-03 14:33:22 -0700175ART_TEST_RUN_TEST_NO_DEX2OAT = _getEnvBoolean('ART_TEST_RUN_TEST_NO_DEX2OAT', ART_TEST_FULL)
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000176
177# Do you want run-tests with libartd.so?
Igor Murashkin6b61c802017-04-03 14:33:22 -0700178ART_TEST_RUN_TEST_DEBUG = _getEnvBoolean('ART_TEST_RUN_TEST_DEBUG', ART_TEST_FULL)
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000179
180# Do you want run-tests with libart.so?
Igor Murashkin6b61c802017-04-03 14:33:22 -0700181ART_TEST_RUN_TEST_NDEBUG = _getEnvBoolean('ART_TEST_RUN_TEST_NDEBUG', ART_TEST_FULL)
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000182
183# Do you want failed tests to have their artifacts cleaned up?
Igor Murashkin6b61c802017-04-03 14:33:22 -0700184ART_TEST_RUN_TEST_ALWAYS_CLEAN = _getEnvBoolean('ART_TEST_RUN_TEST_ALWAYS_CLEAN', True)
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000185
186# Do you want run-tests with the --debuggable flag
Igor Murashkin6b61c802017-04-03 14:33:22 -0700187ART_TEST_RUN_TEST_DEBUGGABLE = _getEnvBoolean('ART_TEST_RUN_TEST_DEBUGGABLE', ART_TEST_FULL)
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000188
189# Do you want to test multi-part boot-image functionality?
Igor Murashkin6b61c802017-04-03 14:33:22 -0700190ART_TEST_RUN_TEST_MULTI_IMAGE = _getEnvBoolean('ART_TEST_RUN_TEST_MULTI_IMAGE', ART_TEST_FULL)
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000191
Igor Murashkin6b61c802017-04-03 14:33:22 -0700192ART_TEST_DEBUG_GC = _getEnvBoolean('ART_TEST_DEBUG_GC', False)
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000193
Igor Murashkin6b61c802017-04-03 14:33:22 -0700194ART_TEST_BISECTION = _getEnvBoolean('ART_TEST_BISECTION', False)
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000195
Igor Murashkin6b61c802017-04-03 14:33:22 -0700196DEX2OAT_HOST_INSTRUCTION_SET_FEATURES = _env.get('DEX2OAT_HOST_INSTRUCTION_SET_FEATURES')
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000197
198# Do you want run-tests with the host/target's second arch?
Igor Murashkin6b61c802017-04-03 14:33:22 -0700199ART_TEST_RUN_TEST_2ND_ARCH = _getEnvBoolean('ART_TEST_RUN_TEST_2ND_ARCH', True)
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000200
Igor Murashkin6b61c802017-04-03 14:33:22 -0700201HOST_2ND_ARCH_PREFIX = _get_build_var('HOST_2ND_ARCH_PREFIX')
202HOST_2ND_ARCH_PREFIX_DEX2OAT_HOST_INSTRUCTION_SET_FEATURES = _env.get(
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000203 HOST_2ND_ARCH_PREFIX + 'DEX2OAT_HOST_INSTRUCTION_SET_FEATURES')
204
Igor Murashkin6b61c802017-04-03 14:33:22 -0700205ART_TEST_ANDROID_ROOT = _env.get('ART_TEST_ANDROID_ROOT')
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000206
Igor Murashkin6b61c802017-04-03 14:33:22 -0700207ART_TEST_WITH_STRACE = _getEnvBoolean('ART_TEST_DEBUG_GC', False)
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000208
Igor Murashkin6b61c802017-04-03 14:33:22 -0700209EXTRA_DISABLED_TESTS = set(_env.get("ART_TEST_RUN_TEST_SKIP", "").split())
Alex Lightbc319b22017-02-17 14:21:33 -0800210
Igor Murashkin6b61c802017-04-03 14:33:22 -0700211ART_TEST_RUN_TEST_BUILD = _getEnvBoolean('ART_TEST_RUN_TEST_BUILD', False)
Alex Light9b6b13e2017-02-22 11:46:50 -0800212
Igor Murashkin6b61c802017-04-03 14:33:22 -0700213TARGET_2ND_ARCH = _get_build_var('TARGET_2ND_ARCH')
214TARGET_ARCH = _get_build_var('TARGET_ARCH')
215
216# Note: ART_2ND_PHONY_TEST_TARGET_SUFFIX is 2ND_ART_PHONY_TEST_TARGET_SUFFIX in .mk files
217# Note: ART_2ND_PHONY_TEST_HOST_SUFFIX is 2ND_ART_PHONY_HOST_TARGET_SUFFIX in .mk files
218# Python does not let us have variable names starting with a digit, so it has differ.
Alex Light8f2c6d42017-04-10 16:27:35 -0700219
220ART_TEST_RUN_TEST_JVMTI_STRESS = _getEnvBoolean('ART_TEST_RUN_TEST_JVMTI_STRESS', ART_TEST_FULL)
221
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000222if TARGET_2ND_ARCH:
223 if "64" in TARGET_ARCH:
224 ART_PHONY_TEST_TARGET_SUFFIX = "64"
Igor Murashkin6b61c802017-04-03 14:33:22 -0700225 ART_2ND_PHONY_TEST_TARGET_SUFFIX = "32"
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000226 else:
227 ART_PHONY_TEST_TARGET_SUFFIX = "32"
Igor Murashkin6b61c802017-04-03 14:33:22 -0700228 ART_2ND_PHONY_TEST_TARGET_SUFFIX = ""
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000229else:
230 if "64" in TARGET_ARCH:
231 ART_PHONY_TEST_TARGET_SUFFIX = "64"
Igor Murashkin6b61c802017-04-03 14:33:22 -0700232 ART_2ND_PHONY_TEST_TARGET_SUFFIX = ""
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000233 else:
234 ART_PHONY_TEST_TARGET_SUFFIX = "32"
Igor Murashkin6b61c802017-04-03 14:33:22 -0700235 ART_2ND_PHONY_TEST_TARGET_SUFFIX = ""
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000236
Igor Murashkin6b61c802017-04-03 14:33:22 -0700237HOST_PREFER_32_BIT = _get_build_var('HOST_PREFER_32_BIT')
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000238if HOST_PREFER_32_BIT == "true":
239 ART_PHONY_TEST_HOST_SUFFIX = "32"
Igor Murashkin6b61c802017-04-03 14:33:22 -0700240 ART_2ND_PHONY_TEST_HOST_SUFFIX = ""
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000241else:
242 ART_PHONY_TEST_HOST_SUFFIX = "64"
Igor Murashkin6b61c802017-04-03 14:33:22 -0700243 ART_2ND_PHONY_TEST_HOST_SUFFIX = "32"
Shubham Ajmera65adb8b2017-02-06 16:04:25 +0000244
Alex Light699c2552017-02-08 10:09:31 -0800245HOST_OUT_EXECUTABLES = os.path.join(ANDROID_BUILD_TOP,
Igor Murashkin6b61c802017-04-03 14:33:22 -0700246 _get_build_var("HOST_OUT_EXECUTABLES"))
Igor Murashkin7dc46cf2017-07-19 13:48:31 -0700247
248# Set up default values for $JACK, $DX, $SMALI, etc to the $HOST_OUT_EXECUTABLES/$name path.
249for tool in ['jack', 'dx', 'smali', 'jasmin', 'dxmerger']:
250 binary = tool if tool != 'dxmerger' else 'dexmerger'
251 os.environ.setdefault(tool.upper(), HOST_OUT_EXECUTABLES + '/' + binary)
Shubham Ajmerac33c0872017-07-20 18:41:52 -0700252
253ANDROID_JAVA_TOOLCHAIN = os.path.join(ANDROID_BUILD_TOP,
254 _get_build_var('ANDROID_JAVA_TOOLCHAIN'))
255
256# include platform prebuilt java, javac, etc in $PATH.
257os.environ['PATH'] = ANDROID_JAVA_TOOLCHAIN + ':' + os.environ['PATH']