• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
15import os
16import re
17import tempfile
18import subprocess
19
20_env = dict(os.environ)
21
22def _getEnvBoolean(var, default):
23  val = _env.get(var)
24  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
31_DUMP_MANY_VARS_LIST = ['HOST_2ND_ARCH_PREFIX',
32                        'TARGET_2ND_ARCH',
33                        'TARGET_ARCH',
34                        'HOST_PREFER_32_BIT',
35                        'HOST_OUT_EXECUTABLES']
36_DUMP_MANY_VARS = None  # To be set to a dictionary with above list being the keys,
37                        # and the build variable being the value.
38def _dump_many_vars(var_name):
39  """
40  Reach into the Android build system to dump many build vars simultaneously.
41  Since the make system is so slow, we want to avoid calling into build frequently.
42  """
43  global _DUMP_MANY_VARS
44  global _DUMP_MANY_VARS_LIST
45
46  # Look up var from cache.
47  if _DUMP_MANY_VARS:
48    return _DUMP_MANY_VARS[var_name]
49
50  all_vars=" ".join(_DUMP_MANY_VARS_LIST)
51
52  # The command is taken from build/envsetup.sh to fetch build variables.
53  command = ("CALLED_FROM_SETUP=true "  # Enable the 'dump-many-vars' make target.
54             "BUILD_SYSTEM=build/core " # Set up lookup path for make includes.
55             "make --no-print-directory -C \"%s\" -f build/core/config.mk "
56             "dump-many-vars DUMP_MANY_VARS=\"%s\"") % (ANDROID_BUILD_TOP, all_vars)
57
58  config = subprocess.Popen(command,
59                            stdout=subprocess.PIPE,
60                            universal_newlines=True,
61                            shell=True).communicate()[0] # read until EOF, select stdin
62  # Prints out something like:
63  # TARGET_ARCH='arm64'
64  # HOST_ARCH='x86_64'
65  _DUMP_MANY_VARS = {}
66  for line in config.split("\n"):
67    # Split out "$key='$value'" via regex.
68    match = re.search("([^=]+)='([^']*)", line)
69    if not match:
70      continue
71    key = match.group(1)
72    value = match.group(2)
73    _DUMP_MANY_VARS[key] = value
74
75  return _DUMP_MANY_VARS[var_name]
76
77def _get_build_var(var_name):
78  return _dump_many_vars(var_name)
79
80def get_env(key):
81  return _env.get(key)
82
83def _get_android_build_top():
84  path_to_top = _env.get('ANDROID_BUILD_TOP')
85  if not path_to_top:
86    # nothing set. try to guess it based on the relative path of this env.py file.
87    this_file_path = os.path.realpath(__file__)
88    path_to_top = os.path.join(os.path.dirname(this_file_path), '../../../')
89    path_to_top = os.path.realpath(path_to_top)
90
91  if not os.path.exists(os.path.join(path_to_top, 'build/envsetup.sh')):
92    raise AssertionError("env.py must be located inside an android source tree")
93
94  return path_to_top
95
96ANDROID_BUILD_TOP = _get_android_build_top()
97
98# Compiling with jack? Possible values in (True, False, 'default')
99ANDROID_COMPILE_WITH_JACK = _getEnvBoolean('ANDROID_COMPILE_WITH_JACK', 'default')
100
101# Directory used for temporary test files on the host.
102ART_HOST_TEST_DIR = tempfile.mkdtemp(prefix = 'test-art-')
103
104# Keep going after encountering a test failure?
105ART_TEST_KEEP_GOING = _getEnvBoolean('ART_TEST_KEEP_GOING', True)
106
107# Do you want all tests, even those that are time consuming?
108ART_TEST_FULL = _getEnvBoolean('ART_TEST_FULL', False)
109
110# Do you want interpreter tests run?
111ART_TEST_INTERPRETER = _getEnvBoolean('ART_TEST_INTERPRETER', ART_TEST_FULL)
112ART_TEST_INTERPRETER_ACCESS_CHECKS = _getEnvBoolean('ART_TEST_INTERPRETER_ACCESS_CHECKS',
113                                                   ART_TEST_FULL)
114
115# Do you want JIT tests run?
116ART_TEST_JIT = _getEnvBoolean('ART_TEST_JIT', ART_TEST_FULL)
117
118# Do you want optimizing compiler tests run?
119ART_TEST_OPTIMIZING = _getEnvBoolean('ART_TEST_OPTIMIZING', ART_TEST_FULL)
120
121# Do you want to test the optimizing compiler with graph coloring register allocation?
122ART_TEST_OPTIMIZING_GRAPH_COLOR = _getEnvBoolean('ART_TEST_OPTIMIZING_GRAPH_COLOR', ART_TEST_FULL)
123
124# Do you want to do run-tests with profiles?
125ART_TEST_SPEED_PROFILE = _getEnvBoolean('ART_TEST_SPEED_PROFILE', ART_TEST_FULL)
126
127# Do we want to test PIC-compiled tests ("apps")?
128ART_TEST_PIC_TEST = _getEnvBoolean('ART_TEST_PIC_TEST', ART_TEST_FULL)
129# Do you want tracing tests run?
130ART_TEST_TRACE = _getEnvBoolean('ART_TEST_TRACE', ART_TEST_FULL)
131
132# Do you want tracing tests (streaming mode) run?
133ART_TEST_TRACE_STREAM = _getEnvBoolean('ART_TEST_TRACE_STREAM', ART_TEST_FULL)
134
135# Do you want tests with GC verification enabled run?
136ART_TEST_GC_VERIFY = _getEnvBoolean('ART_TEST_GC_VERIFY', ART_TEST_FULL)
137
138# Do you want tests with the GC stress mode enabled run?
139ART_TEST_GC_STRESS = _getEnvBoolean('ART_TEST_GC_STRESS', ART_TEST_FULL)
140
141# Do you want tests with the JNI forcecopy mode enabled run?
142ART_TEST_JNI_FORCECOPY = _getEnvBoolean('ART_TEST_JNI_FORCECOPY', ART_TEST_FULL)
143
144# Do you want run-tests with relocation disabled run?
145ART_TEST_RUN_TEST_RELOCATE = _getEnvBoolean('ART_TEST_RUN_TEST_RELOCATE', ART_TEST_FULL)
146
147# Do you want run-tests with prebuilding?
148ART_TEST_RUN_TEST_PREBUILD = _getEnvBoolean('ART_TEST_RUN_TEST_PREBUILD', ART_TEST_FULL)
149
150# Do you want run-tests with no prebuilding enabled run?
151ART_TEST_RUN_TEST_NO_PREBUILD = _getEnvBoolean('ART_TEST_RUN_TEST_NO_PREBUILD', ART_TEST_FULL)
152
153# Do you want run-tests with a pregenerated core.art?
154ART_TEST_RUN_TEST_IMAGE = _getEnvBoolean('ART_TEST_RUN_TEST_IMAGE', ART_TEST_FULL)
155
156# Do you want run-tests without a pregenerated core.art?
157ART_TEST_RUN_TEST_NO_IMAGE = _getEnvBoolean('ART_TEST_RUN_TEST_NO_IMAGE', ART_TEST_FULL)
158
159# Do you want run-tests with relocation enabled but patchoat failing?
160ART_TEST_RUN_TEST_RELOCATE_NO_PATCHOAT = _getEnvBoolean('ART_TEST_RUN_TEST_RELOCATE_NO_PATCHOAT',
161                                                       ART_TEST_FULL)
162
163# Do you want run-tests without a dex2oat?
164ART_TEST_RUN_TEST_NO_DEX2OAT = _getEnvBoolean('ART_TEST_RUN_TEST_NO_DEX2OAT', ART_TEST_FULL)
165
166# Do you want run-tests with libartd.so?
167ART_TEST_RUN_TEST_DEBUG = _getEnvBoolean('ART_TEST_RUN_TEST_DEBUG', ART_TEST_FULL)
168
169# Do you want run-tests with libart.so?
170ART_TEST_RUN_TEST_NDEBUG = _getEnvBoolean('ART_TEST_RUN_TEST_NDEBUG', ART_TEST_FULL)
171
172# Do you want failed tests to have their artifacts cleaned up?
173ART_TEST_RUN_TEST_ALWAYS_CLEAN = _getEnvBoolean('ART_TEST_RUN_TEST_ALWAYS_CLEAN', True)
174
175# Do you want run-tests with the --debuggable flag
176ART_TEST_RUN_TEST_DEBUGGABLE = _getEnvBoolean('ART_TEST_RUN_TEST_DEBUGGABLE', ART_TEST_FULL)
177
178# Do you want to test multi-part boot-image functionality?
179ART_TEST_RUN_TEST_MULTI_IMAGE = _getEnvBoolean('ART_TEST_RUN_TEST_MULTI_IMAGE', ART_TEST_FULL)
180
181ART_TEST_DEBUG_GC = _getEnvBoolean('ART_TEST_DEBUG_GC', False)
182
183ART_TEST_BISECTION = _getEnvBoolean('ART_TEST_BISECTION', False)
184
185DEX2OAT_HOST_INSTRUCTION_SET_FEATURES = _env.get('DEX2OAT_HOST_INSTRUCTION_SET_FEATURES')
186
187# Do you want run-tests with the host/target's second arch?
188ART_TEST_RUN_TEST_2ND_ARCH = _getEnvBoolean('ART_TEST_RUN_TEST_2ND_ARCH', True)
189
190HOST_2ND_ARCH_PREFIX = _get_build_var('HOST_2ND_ARCH_PREFIX')
191HOST_2ND_ARCH_PREFIX_DEX2OAT_HOST_INSTRUCTION_SET_FEATURES = _env.get(
192  HOST_2ND_ARCH_PREFIX + 'DEX2OAT_HOST_INSTRUCTION_SET_FEATURES')
193
194ART_TEST_ANDROID_ROOT = _env.get('ART_TEST_ANDROID_ROOT')
195
196ART_TEST_WITH_STRACE = _getEnvBoolean('ART_TEST_DEBUG_GC', False)
197
198EXTRA_DISABLED_TESTS = set(_env.get("ART_TEST_RUN_TEST_SKIP", "").split())
199
200ART_TEST_RUN_TEST_BUILD = _getEnvBoolean('ART_TEST_RUN_TEST_BUILD', False)
201
202TARGET_2ND_ARCH = _get_build_var('TARGET_2ND_ARCH')
203TARGET_ARCH = _get_build_var('TARGET_ARCH')
204
205# Note: ART_2ND_PHONY_TEST_TARGET_SUFFIX is 2ND_ART_PHONY_TEST_TARGET_SUFFIX in .mk files
206# Note: ART_2ND_PHONY_TEST_HOST_SUFFIX is 2ND_ART_PHONY_HOST_TARGET_SUFFIX in .mk files
207# Python does not let us have variable names starting with a digit, so it has differ.
208
209ART_TEST_RUN_TEST_JVMTI_STRESS = _getEnvBoolean('ART_TEST_RUN_TEST_JVMTI_STRESS', ART_TEST_FULL)
210
211if TARGET_2ND_ARCH:
212  if "64" in TARGET_ARCH:
213    ART_PHONY_TEST_TARGET_SUFFIX = "64"
214    ART_2ND_PHONY_TEST_TARGET_SUFFIX = "32"
215  else:
216    ART_PHONY_TEST_TARGET_SUFFIX = "32"
217    ART_2ND_PHONY_TEST_TARGET_SUFFIX = ""
218else:
219  if "64" in TARGET_ARCH:
220    ART_PHONY_TEST_TARGET_SUFFIX = "64"
221    ART_2ND_PHONY_TEST_TARGET_SUFFIX = ""
222  else:
223    ART_PHONY_TEST_TARGET_SUFFIX = "32"
224    ART_2ND_PHONY_TEST_TARGET_SUFFIX = ""
225
226HOST_PREFER_32_BIT = _get_build_var('HOST_PREFER_32_BIT')
227if HOST_PREFER_32_BIT == "true":
228  ART_PHONY_TEST_HOST_SUFFIX = "32"
229  ART_2ND_PHONY_TEST_HOST_SUFFIX = ""
230else:
231  ART_PHONY_TEST_HOST_SUFFIX = "64"
232  ART_2ND_PHONY_TEST_HOST_SUFFIX = "32"
233
234HOST_OUT_EXECUTABLES = os.path.join(ANDROID_BUILD_TOP,
235                                    _get_build_var("HOST_OUT_EXECUTABLES"))
236
237# Set up default values for $JACK, $DX, $SMALI, etc to the $HOST_OUT_EXECUTABLES/$name path.
238for tool in ['jack', 'dx', 'smali', 'jasmin', 'dxmerger']:
239  binary = tool if tool != 'dxmerger' else 'dexmerger'
240  os.environ.setdefault(tool.upper(), HOST_OUT_EXECUTABLES + '/' + binary)
241