Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 1 | # |
David Srbecky | bfa76b3 | 2022-06-20 21:30:56 +0100 | [diff] [blame] | 2 | # Copyright (C) 2022 The Android Open Source Project |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 15 | |
David Srbecky | bfa76b3 | 2022-06-20 21:30:56 +0100 | [diff] [blame] | 16 | import sys, os, shutil, shlex, re, subprocess, glob |
David Srbecky | e4e701b | 2022-10-24 11:00:31 +0000 | [diff] [blame] | 17 | from argparse import ArgumentParser, BooleanOptionalAction, Namespace |
David Srbecky | bfa76b3 | 2022-06-20 21:30:56 +0100 | [diff] [blame] | 18 | from os import path |
David Srbecky | 93749ed | 2022-11-09 15:24:45 +0000 | [diff] [blame] | 19 | from os.path import isfile, isdir, basename |
David Srbecky | bfa76b3 | 2022-06-20 21:30:56 +0100 | [diff] [blame] | 20 | from subprocess import DEVNULL, PIPE, STDOUT |
David Srbecky | d7674c2 | 2022-10-03 18:22:13 +0100 | [diff] [blame] | 21 | from tempfile import NamedTemporaryFile |
David Srbecky | 49506de | 2022-11-25 12:00:06 +0000 | [diff] [blame] | 22 | from testrunner import env |
| 23 | from typing import List |
David Srbecky | bfa76b3 | 2022-06-20 21:30:56 +0100 | [diff] [blame] | 24 | |
David Srbecky | f356dcd | 2022-11-21 12:14:50 +0000 | [diff] [blame] | 25 | COLOR = (os.environ.get("LUCI_CONTEXT") == None) # Disable colors on LUCI. |
| 26 | COLOR_BLUE = '\033[94m' if COLOR else '' |
| 27 | COLOR_GREEN = '\033[92m' if COLOR else '' |
| 28 | COLOR_NORMAL = '\033[0m' if COLOR else '' |
| 29 | COLOR_RED = '\033[91m' if COLOR else '' |
David Srbecky | bfa76b3 | 2022-06-20 21:30:56 +0100 | [diff] [blame] | 30 | |
David Srbecky | e4e701b | 2022-10-24 11:00:31 +0000 | [diff] [blame] | 31 | def parse_args(argv): |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 32 | argp, opt_bool = ArgumentParser(), BooleanOptionalAction |
| 33 | argp.add_argument("--64", dest="is64", action="store_true") |
| 34 | argp.add_argument("--O", action="store_true") |
| 35 | argp.add_argument("--Xcompiler-option", default=[], action="append") |
| 36 | argp.add_argument("--add-libdir-argument", action="store_true") |
| 37 | argp.add_argument("--android-art-root", default="/apex/com.android.art") |
| 38 | argp.add_argument("--android-i18n-root", default="/apex/com.android.i18n") |
David Srbecky | fe3d9c9 | 2022-11-10 18:57:15 +0000 | [diff] [blame] | 39 | argp.add_argument("--android-log-tags", default="*:i") |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 40 | argp.add_argument("--android-root", default="/system") |
| 41 | argp.add_argument("--android-runtime-option", default=[], action="append") |
| 42 | argp.add_argument("--android-tzdata-root", default="/apex/com.android.tzdata") |
| 43 | argp.add_argument("--app-image", default=True, action=opt_bool) |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 44 | argp.add_argument("--baseline", action="store_true") |
| 45 | argp.add_argument("--bionic", action="store_true") |
| 46 | argp.add_argument("--boot", default="") |
| 47 | argp.add_argument("--chroot", default="") |
| 48 | argp.add_argument("--compact-dex-level") |
| 49 | argp.add_argument("--compiler-only-option", default=[], action="append") |
| 50 | argp.add_argument("--create-runner", action="store_true") |
David Srbecky | fe3d9c9 | 2022-11-10 18:57:15 +0000 | [diff] [blame] | 51 | argp.add_argument("--diff-min-log-tag", default="E") |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 52 | argp.add_argument("--debug", action="store_true") |
| 53 | argp.add_argument("--debug-agent") |
| 54 | argp.add_argument("--debug-wrap-agent", action="store_true") |
| 55 | argp.add_argument("--dex2oat-dm", action="store_true") |
| 56 | argp.add_argument( |
| 57 | "--dex2oat-rt-timeout", type=int, |
| 58 | default=360) # The *hard* timeout. 6 min. |
| 59 | argp.add_argument( |
| 60 | "--dex2oat-timeout", type=int, default=300) # The "soft" timeout. 5 min. |
| 61 | argp.add_argument("--dry-run", action="store_true") |
| 62 | argp.add_argument("--experimental", default=[], action="append") |
| 63 | argp.add_argument("--external-log-tags", action="store_true") |
| 64 | argp.add_argument("--gc-stress", action="store_true") |
| 65 | argp.add_argument("--gdb", action="store_true") |
| 66 | argp.add_argument("--gdb-arg", default=[], action="append") |
| 67 | argp.add_argument("--gdb-dex2oat", action="store_true") |
| 68 | argp.add_argument("--gdb-dex2oat-args", default=[], action="append") |
| 69 | argp.add_argument("--gdbserver", action="store_true") |
| 70 | argp.add_argument("--gdbserver-bin") |
| 71 | argp.add_argument("--gdbserver-port", default=":5039") |
| 72 | argp.add_argument("--host", action="store_true") |
| 73 | argp.add_argument("--image", default=True, action=opt_bool) |
| 74 | argp.add_argument("--instruction-set-features", default="") |
| 75 | argp.add_argument("--interpreter", action="store_true") |
| 76 | argp.add_argument("--invoke-with", default=[], action="append") |
| 77 | argp.add_argument("--jit", action="store_true") |
| 78 | argp.add_argument("--jvm", action="store_true") |
| 79 | argp.add_argument("--jvmti", action="store_true") |
| 80 | argp.add_argument("--jvmti-field-stress", action="store_true") |
| 81 | argp.add_argument("--jvmti-redefine-stress", action="store_true") |
| 82 | argp.add_argument("--jvmti-step-stress", action="store_true") |
| 83 | argp.add_argument("--jvmti-trace-stress", action="store_true") |
| 84 | argp.add_argument("--lib", default="") |
| 85 | argp.add_argument("--optimize", default=True, action=opt_bool) |
| 86 | argp.add_argument("--prebuild", default=True, action=opt_bool) |
| 87 | argp.add_argument("--profile", action="store_true") |
| 88 | argp.add_argument("--random-profile", action="store_true") |
| 89 | argp.add_argument("--relocate", default=False, action=opt_bool) |
| 90 | argp.add_argument("--runtime-dm", action="store_true") |
| 91 | argp.add_argument("--runtime-extracted-zipapex", default="") |
| 92 | argp.add_argument("--runtime-option", default=[], action="append") |
| 93 | argp.add_argument("--runtime-zipapex", default="") |
| 94 | argp.add_argument("--secondary", action="store_true") |
| 95 | argp.add_argument("--secondary-app-image", default=True, action=opt_bool) |
| 96 | argp.add_argument("--secondary-class-loader-context", default="") |
| 97 | argp.add_argument("--secondary-compilation", default=True, action=opt_bool) |
| 98 | argp.add_argument("--simpleperf", action="store_true") |
| 99 | argp.add_argument("--sync", action="store_true") |
| 100 | argp.add_argument("--testlib", default=[], action="append") |
| 101 | argp.add_argument("--timeout", default=0, type=int) |
| 102 | argp.add_argument("--vdex", action="store_true") |
| 103 | argp.add_argument("--vdex-arg", default=[], action="append") |
David Srbecky | e4e701b | 2022-10-24 11:00:31 +0000 | [diff] [blame] | 104 | argp.add_argument("--vdex-filter", default="") |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 105 | argp.add_argument("--verify", default=True, action=opt_bool) |
| 106 | argp.add_argument("--verify-soft-fail", action="store_true") |
| 107 | argp.add_argument("--with-agent", default=[], action="append") |
| 108 | argp.add_argument("--zygote", action="store_true") |
David Srbecky | e4e701b | 2022-10-24 11:00:31 +0000 | [diff] [blame] | 109 | argp.add_argument("--test_args", default=[], action="append") |
| 110 | argp.add_argument("--stdout_file", default="") |
| 111 | argp.add_argument("--stderr_file", default="") |
| 112 | argp.add_argument("--main", default="Main") |
| 113 | argp.add_argument("--expected_exit_code", default=0) |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 114 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 115 | # Python parser requires the format --key=--value, since without the equals symbol |
| 116 | # it looks like the required value has been omitted and there is just another flag. |
| 117 | # For example, '--args --foo --host --64' will become '--arg=--foo --host --64' |
| 118 | # because otherwise the --args is missing its value and --foo is unknown argument. |
| 119 | for i, arg in reversed(list(enumerate(argv))): |
| 120 | if arg in [ |
| 121 | "--args", "--runtime-option", "--android-runtime-option", |
| 122 | "-Xcompiler-option", "--compiler-only-option" |
| 123 | ]: |
| 124 | argv[i] += "=" + argv.pop(i + 1) |
David Srbecky | e4e701b | 2022-10-24 11:00:31 +0000 | [diff] [blame] | 125 | |
| 126 | # Accept single-dash arguments as if they were double-dash arguments. |
| 127 | # For exmpample, '-Xcompiler-option' becomes '--Xcompiler-option' |
| 128 | # became single-dash can be used only with single-letter arguments. |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 129 | for i, arg in list(enumerate(argv)): |
| 130 | if arg.startswith("-") and not arg.startswith("--"): |
| 131 | argv[i] = "-" + arg |
| 132 | if arg == "--": |
| 133 | break |
David Srbecky | 85786e7 | 2022-09-21 23:54:01 +0100 | [diff] [blame] | 134 | |
David Srbecky | e4e701b | 2022-10-24 11:00:31 +0000 | [diff] [blame] | 135 | return argp.parse_args(argv) |
| 136 | |
David Srbecky | 49506de | 2022-11-25 12:00:06 +0000 | [diff] [blame] | 137 | def get_target_arch(is64: bool) -> str: |
| 138 | # We may build for two arches. Get the one with the expected bitness. |
| 139 | arches = [a for a in [env.TARGET_ARCH, env.TARGET_2ND_ARCH] if a] |
| 140 | assert len(arches) > 0, "TARGET_ARCH/TARGET_2ND_ARCH not set" |
| 141 | if is64: |
| 142 | arches = [a for a in arches if a.endswith("64")] |
| 143 | assert len(arches) == 1, f"Can not find (unique) 64-bit arch in {arches}" |
| 144 | else: |
| 145 | arches = [a for a in arches if not a.endswith("64")] |
| 146 | assert len(arches) == 1, f"Can not find (unique) 32-bit arch in {arches}" |
| 147 | return arches[0] |
David Srbecky | e4e701b | 2022-10-24 11:00:31 +0000 | [diff] [blame] | 148 | |
David Srbecky | e0cbf8e | 2022-11-03 10:42:21 +0000 | [diff] [blame] | 149 | # Note: This must start with the CORE_IMG_JARS in Android.common_path.mk |
| 150 | # because that's what we use for compiling the boot.art image. |
| 151 | # It may contain additional modules from TEST_CORE_JARS. |
| 152 | bpath_modules = ("core-oj core-libart okhttp bouncycastle apache-xml core-icu4j" |
| 153 | " conscrypt") |
| 154 | |
| 155 | |
| 156 | # Helper function to construct paths for apex modules (for both -Xbootclasspath and |
| 157 | # -Xbootclasspath-location). |
| 158 | def get_apex_bootclasspath_impl(bpath_prefix: str): |
| 159 | bpath_separator = "" |
| 160 | bpath = "" |
| 161 | bpath_jar = "" |
| 162 | for bpath_module in bpath_modules.split(" "): |
| 163 | apex_module = "com.android.art" |
| 164 | if bpath_module == "conscrypt": |
| 165 | apex_module = "com.android.conscrypt" |
| 166 | if bpath_module == "core-icu4j": |
| 167 | apex_module = "com.android.i18n" |
| 168 | bpath_jar = f"/apex/{apex_module}/javalib/{bpath_module}.jar" |
| 169 | bpath += f"{bpath_separator}{bpath_prefix}{bpath_jar}" |
| 170 | bpath_separator = ":" |
| 171 | return bpath |
| 172 | |
| 173 | |
| 174 | # Gets a -Xbootclasspath paths with the apex modules. |
| 175 | def get_apex_bootclasspath(host: bool): |
| 176 | bpath_prefix = "" |
| 177 | |
| 178 | if host: |
| 179 | bpath_prefix = os.environ["ANDROID_HOST_OUT"] |
| 180 | |
| 181 | return get_apex_bootclasspath_impl(bpath_prefix) |
| 182 | |
| 183 | |
| 184 | # Gets a -Xbootclasspath-location paths with the apex modules. |
| 185 | def get_apex_bootclasspath_locations(host: bool): |
| 186 | bpath_location_prefix = "" |
| 187 | |
| 188 | if host: |
| 189 | ANDROID_BUILD_TOP=os.environ["ANDROID_BUILD_TOP"] |
| 190 | ANDROID_HOST_OUT=os.environ["ANDROID_HOST_OUT"] |
| 191 | if ANDROID_HOST_OUT[0:len(ANDROID_BUILD_TOP)+1] == f"{ANDROID_BUILD_TOP}/": |
| 192 | bpath_location_prefix=ANDROID_HOST_OUT[len(ANDROID_BUILD_TOP)+1:] |
| 193 | else: |
| 194 | print(f"ANDROID_BUILD_TOP/ is not a prefix of ANDROID_HOST_OUT"\ |
| 195 | "\nANDROID_BUILD_TOP={ANDROID_BUILD_TOP}"\ |
| 196 | "\nANDROID_HOST_OUT={ANDROID_HOST_OUT}") |
| 197 | sys.exit(1) |
| 198 | |
| 199 | return get_apex_bootclasspath_impl(bpath_location_prefix) |
| 200 | |
| 201 | |
David Srbecky | e4e701b | 2022-10-24 11:00:31 +0000 | [diff] [blame] | 202 | def default_run(ctx, args, **kwargs): |
| 203 | # Clone the args so we can modify them without affecting args in the caller. |
| 204 | args = Namespace(**vars(args)) |
| 205 | |
| 206 | # Overwrite args based on the named parameters. |
| 207 | # E.g. the caller can do `default_run(args, jvmti=True)` to modify args.jvmti. |
| 208 | for name, new_value in kwargs.items(): |
| 209 | old_value = getattr(args, name) |
| 210 | assert isinstance(new_value, old_value.__class__), name + " should have type " + str(old_value.__class__) |
| 211 | if isinstance(old_value, list): |
| 212 | setattr(args, name, old_value + new_value) # Lists get merged. |
| 213 | else: |
| 214 | setattr(args, name, new_value) |
| 215 | |
| 216 | # Script debugging: Record executed commands into the given directory. |
| 217 | # This is useful to ensure that changes to the script don't change behaviour. |
| 218 | # (the commands are appended so the directory needs to be cleared before run) |
| 219 | ART_TEST_CMD_DIR = os.environ.get("ART_TEST_CMD_DIR") |
| 220 | |
| 221 | # Script debugging: Record executed commands, but don't actually run the main test. |
| 222 | # This makes it possible the extract the test commands without waiting for days. |
| 223 | # This will make tests fail since there is no stdout. Use with large -j value. |
| 224 | ART_TEST_DRY_RUN = os.environ.get("ART_TEST_DRY_RUN") |
| 225 | |
| 226 | def run(cmdline: str, |
| 227 | env={}, |
David Srbecky | e4e701b | 2022-10-24 11:00:31 +0000 | [diff] [blame] | 228 | check=True, |
David Srbecky | db12173 | 2022-10-31 18:40:26 +0000 | [diff] [blame] | 229 | parse_exit_code_from_stdout=False, |
David Srbecky | e4e701b | 2022-10-24 11:00:31 +0000 | [diff] [blame] | 230 | expected_exit_code=0, |
| 231 | save_cmd=True) -> subprocess.CompletedProcess: |
| 232 | env.setdefault("PATH", PATH) # Ensure that PATH is always set. |
| 233 | env = {k: v for k, v in env.items() if v != None} # Filter "None" entries. |
| 234 | if ART_TEST_CMD_DIR and save_cmd and cmdline != "true": |
| 235 | tmp = os.environ["DEX_LOCATION"] |
| 236 | with open( |
| 237 | os.path.join(ART_TEST_CMD_DIR, os.environ["FULL_TEST_NAME"]), |
| 238 | "a") as f: |
| 239 | # Replace DEX_LOCATION (which is randomly generated temporary directory), |
| 240 | # with a deterministic placeholder so that we can do a diff from run to run. |
| 241 | f.write("\n".join( |
| 242 | k + ":" + v.replace(tmp, "<tmp>") for k, v in env.items()) + "\n\n") |
| 243 | f.write(re.sub(" +", "\n", cmdline).replace(tmp, "<tmp>") + "\n\n") |
| 244 | if ART_TEST_DRY_RUN and ("dalvikvm" in cmdline or |
| 245 | "adb shell chroot" in cmdline): |
| 246 | cmdline = "true" # We still need to run some command, so run the no-op "true" binary instead. |
David Srbecky | fe3d9c9 | 2022-11-10 18:57:15 +0000 | [diff] [blame] | 247 | |
| 248 | if cmdline != "true": |
| 249 | print(f"{COLOR_BLUE}$ {cmdline}{COLOR_NORMAL}") |
David Srbecky | e4e701b | 2022-10-24 11:00:31 +0000 | [diff] [blame] | 250 | proc = subprocess.run([cmdline], |
| 251 | shell=True, |
David Srbecky | 93749ed | 2022-11-09 15:24:45 +0000 | [diff] [blame] | 252 | executable="/bin/bash", |
David Srbecky | e4e701b | 2022-10-24 11:00:31 +0000 | [diff] [blame] | 253 | env=env, |
| 254 | encoding="utf8", |
| 255 | capture_output=True) |
David Srbecky | fe3d9c9 | 2022-11-10 18:57:15 +0000 | [diff] [blame] | 256 | if proc.stdout: |
| 257 | print(proc.stdout.strip(), flush=True) |
| 258 | if proc.stderr: |
| 259 | print(proc.stderr.strip(), flush=True) |
David Srbecky | e4e701b | 2022-10-24 11:00:31 +0000 | [diff] [blame] | 260 | |
David Srbecky | db12173 | 2022-10-31 18:40:26 +0000 | [diff] [blame] | 261 | # ADB forwards exit code from the executed command, but if ADB process itself crashes, |
| 262 | # it will also return non-zero exit code, and we can not distinguish those two cases. |
| 263 | # As a work-around, we wrap the executed command so that it always returns 0 exit code |
| 264 | # and we also make it print the actual exit code as the last line of its stdout. |
| 265 | if parse_exit_code_from_stdout: |
David Srbecky | fe3d9c9 | 2022-11-10 18:57:15 +0000 | [diff] [blame] | 266 | assert proc.returncode == 0, f"ADB failed (exit code {proc.returncode})" |
David Srbecky | db12173 | 2022-10-31 18:40:26 +0000 | [diff] [blame] | 267 | found = re.search("exit_code=([0-9]+)$", proc.stdout) |
| 268 | assert found, "Expected exit code as the last line of stdout" |
| 269 | proc.stdout = proc.stdout[:found.start(0)] # Remove the exit code from stdout. |
| 270 | proc.returncode = int(found.group(1)) # Use it as if it was the process exit code. |
| 271 | |
David Srbecky | e4e701b | 2022-10-24 11:00:31 +0000 | [diff] [blame] | 272 | # Check the exit code. |
David Srbecky | e4e701b | 2022-10-24 11:00:31 +0000 | [diff] [blame] | 273 | if (check and proc.returncode != expected_exit_code): |
| 274 | suffix = "" |
| 275 | if proc.returncode == 124: |
| 276 | suffix = " (TIME OUT)" |
| 277 | elif expected_exit_code != 0: |
| 278 | suffix = " (expected {})".format(expected_exit_code) |
David Srbecky | fe3d9c9 | 2022-11-10 18:57:15 +0000 | [diff] [blame] | 279 | print(f"{COLOR_RED}{TEST_NAME} FAILED: Command returned exit code " |
| 280 | f"{proc.returncode}{suffix}{COLOR_NORMAL}", file=sys.stderr) |
David Srbecky | 93749ed | 2022-11-09 15:24:45 +0000 | [diff] [blame] | 281 | sys.exit(1) |
David Srbecky | e4e701b | 2022-10-24 11:00:31 +0000 | [diff] [blame] | 282 | |
| 283 | return proc |
| 284 | |
David Srbecky | 93749ed | 2022-11-09 15:24:45 +0000 | [diff] [blame] | 285 | # Store copy of stdout&stderr of command in files so that we can diff them later. |
| 286 | # This may run under 'adb shell' so we are limited only to 'sh' shell feature set. |
| 287 | def tee(cmd: str): |
| 288 | # 'tee' works on stdout only, so we need to temporarily swap stdout and stderr. |
| 289 | cmd = f"({cmd} | tee -a {DEX_LOCATION}/{basename(args.stdout_file)}) 3>&1 1>&2 2>&3" |
| 290 | cmd = f"({cmd} | tee -a {DEX_LOCATION}/{basename(args.stderr_file)}) 3>&1 1>&2 2>&3" |
| 291 | return f"set -o pipefail; {cmd}" # Use exit code of first failure in piped command. |
| 292 | |
David Srbecky | e4e701b | 2022-10-24 11:00:31 +0000 | [diff] [blame] | 293 | class Adb(): |
| 294 | |
| 295 | def __init__(self): |
| 296 | self.env = { |
| 297 | "ADB_VENDOR_KEYS": os.environ.get("ADB_VENDOR_KEYS"), |
| 298 | "ANDROID_SERIAL": os.environ.get("ANDROID_SERIAL"), |
| 299 | "PATH": os.environ.get("PATH"), |
| 300 | } |
| 301 | |
| 302 | def root(self) -> None: |
| 303 | run("adb root", self.env) |
| 304 | |
| 305 | def wait_for_device(self) -> None: |
| 306 | run("adb wait-for-device", self.env) |
| 307 | |
| 308 | def shell(self, cmdline: str, **kwargs) -> subprocess.CompletedProcess: |
David Srbecky | db12173 | 2022-10-31 18:40:26 +0000 | [diff] [blame] | 309 | return run(f"adb shell '{cmdline}; echo exit_code=$?'", self.env, |
| 310 | parse_exit_code_from_stdout=True, **kwargs) |
David Srbecky | e4e701b | 2022-10-24 11:00:31 +0000 | [diff] [blame] | 311 | |
| 312 | def push(self, src: str, dst: str, **kwargs) -> None: |
| 313 | run(f"adb push {src} {dst}", self.env, **kwargs) |
| 314 | |
David Srbecky | 93749ed | 2022-11-09 15:24:45 +0000 | [diff] [blame] | 315 | def pull(self, src: str, dst: str, **kwargs) -> None: |
| 316 | run(f"adb pull {src} {dst}", self.env, **kwargs) |
| 317 | |
David Srbecky | e4e701b | 2022-10-24 11:00:31 +0000 | [diff] [blame] | 318 | adb = Adb() |
| 319 | |
| 320 | local_path = os.path.dirname(__file__) |
| 321 | |
| 322 | # Check that stdout is connected to a terminal and that we have at least 1 color. |
| 323 | # This ensures that if the stdout is not connected to a terminal and instead |
| 324 | # the stdout will be used for a log, it will not append the color characters. |
| 325 | bold_red = "" |
| 326 | if sys.stdout.isatty(): |
| 327 | if int(subprocess.run(["tput", "colors"], capture_output=True).stdout) >= 1: |
| 328 | bold_red = subprocess.run(["tput", "bold"], |
| 329 | text=True, |
| 330 | capture_output=True).stdout.strip() |
| 331 | bold_red += subprocess.run(["tput", "setaf", "1"], |
| 332 | text=True, |
| 333 | capture_output=True).stdout.strip() |
| 334 | |
| 335 | ANDROID_BUILD_TOP = os.environ.get("ANDROID_BUILD_TOP") |
| 336 | ANDROID_DATA = os.environ.get("ANDROID_DATA") |
| 337 | ANDROID_HOST_OUT = os.environ["ANDROID_HOST_OUT"] |
| 338 | ANDROID_LOG_TAGS = os.environ.get("ANDROID_LOG_TAGS", "") |
| 339 | ART_TIME_OUT_MULTIPLIER = int(os.environ.get("ART_TIME_OUT_MULTIPLIER", 1)) |
| 340 | DEX2OAT = os.environ.get("DEX2OAT", "") |
| 341 | DEX_LOCATION = os.environ["DEX_LOCATION"] |
| 342 | JAVA = os.environ.get("JAVA") |
| 343 | OUT_DIR = os.environ.get("OUT_DIR") |
| 344 | PATH = os.environ.get("PATH", "") |
| 345 | SANITIZE_HOST = os.environ.get("SANITIZE_HOST", "") |
| 346 | TEST_NAME = os.environ["TEST_NAME"] |
| 347 | USE_EXRACTED_ZIPAPEX = os.environ.get("USE_EXRACTED_ZIPAPEX", "") |
| 348 | |
| 349 | assert ANDROID_BUILD_TOP, "Did you forget to run `lunch`?" |
| 350 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 351 | ANDROID_ROOT = args.android_root |
| 352 | ANDROID_ART_ROOT = args.android_art_root |
| 353 | ANDROID_I18N_ROOT = args.android_i18n_root |
| 354 | ANDROID_TZDATA_ROOT = args.android_tzdata_root |
| 355 | ARCHITECTURES_32 = "(arm|x86|none)" |
| 356 | ARCHITECTURES_64 = "(arm64|x86_64|none)" |
| 357 | ARCHITECTURES_PATTERN = ARCHITECTURES_32 |
| 358 | GET_DEVICE_ISA_BITNESS_FLAG = "--32" |
| 359 | BOOT_IMAGE = args.boot |
| 360 | CHROOT = args.chroot |
| 361 | COMPILE_FLAGS = "" |
| 362 | DALVIKVM = "dalvikvm32" |
| 363 | DEBUGGER = "n" |
| 364 | WITH_AGENT = args.with_agent |
| 365 | DEBUGGER_AGENT = args.debug_agent |
| 366 | WRAP_DEBUGGER_AGENT = args.debug_wrap_agent |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 367 | DEX2OAT_NDEBUG_BINARY = "dex2oat32" |
| 368 | DEX2OAT_DEBUG_BINARY = "dex2oatd32" |
| 369 | EXPERIMENTAL = args.experimental |
| 370 | FALSE_BIN = "false" |
| 371 | FLAGS = "" |
| 372 | ANDROID_FLAGS = "" |
| 373 | GDB = "" |
| 374 | GDB_ARGS = "" |
| 375 | GDB_DEX2OAT = "" |
| 376 | GDB_DEX2OAT_ARGS = "" |
| 377 | GDBSERVER_DEVICE = "gdbserver" |
| 378 | GDBSERVER_HOST = "gdbserver" |
| 379 | HAVE_IMAGE = args.image |
| 380 | HOST = args.host |
| 381 | BIONIC = args.bionic |
| 382 | CREATE_ANDROID_ROOT = False |
| 383 | USE_ZIPAPEX = (args.runtime_zipapex != "") |
| 384 | ZIPAPEX_LOC = args.runtime_zipapex |
| 385 | USE_EXTRACTED_ZIPAPEX = (args.runtime_extracted_zipapex != "") |
| 386 | EXTRACTED_ZIPAPEX_LOC = args.runtime_extracted_zipapex |
| 387 | INTERPRETER = args.interpreter |
| 388 | JIT = args.jit |
| 389 | INVOKE_WITH = " ".join(args.invoke_with) |
| 390 | USE_JVMTI = args.jvmti |
| 391 | IS_JVMTI_TEST = False |
| 392 | ADD_LIBDIR_ARGUMENTS = args.add_libdir_argument |
| 393 | SUFFIX64 = "" |
| 394 | ISA = "x86" |
| 395 | LIBRARY_DIRECTORY = "lib" |
| 396 | TEST_DIRECTORY = "nativetest" |
David Srbecky | e4e701b | 2022-10-24 11:00:31 +0000 | [diff] [blame] | 397 | MAIN = args.main |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 398 | OPTIMIZE = args.optimize |
| 399 | PREBUILD = args.prebuild |
| 400 | RELOCATE = args.relocate |
| 401 | SECONDARY_DEX = "" |
| 402 | TIME_OUT = "n" # "n" (disabled), "timeout" (use timeout), "gdb" (use gdb) |
| 403 | TIMEOUT_DUMPER = "signal_dumper" |
| 404 | # Values in seconds. |
| 405 | TIME_OUT_EXTRA = 0 |
| 406 | TIME_OUT_VALUE = args.timeout |
| 407 | USE_GDB = args.gdb |
| 408 | USE_GDBSERVER = args.gdbserver |
| 409 | GDBSERVER_PORT = args.gdbserver_port |
| 410 | USE_GDB_DEX2OAT = args.gdb_dex2oat |
| 411 | USE_JVM = args.jvm |
| 412 | VERIFY = "y" if args.verify else "n" # y=yes,n=no,s=softfail |
| 413 | ZYGOTE = "" |
| 414 | DEX_VERIFY = "" |
| 415 | INSTRUCTION_SET_FEATURES = args.instruction_set_features |
| 416 | ARGS = "" |
| 417 | VDEX_ARGS = "" |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 418 | DRY_RUN = args.dry_run |
| 419 | TEST_VDEX = args.vdex |
| 420 | TEST_DEX2OAT_DM = args.dex2oat_dm |
| 421 | TEST_RUNTIME_DM = args.runtime_dm |
| 422 | TEST_IS_NDEBUG = args.O |
| 423 | APP_IMAGE = args.app_image |
| 424 | SECONDARY_APP_IMAGE = args.secondary_app_image |
| 425 | SECONDARY_CLASS_LOADER_CONTEXT = args.secondary_class_loader_context |
| 426 | SECONDARY_COMPILATION = args.secondary_compilation |
| 427 | JVMTI_STRESS = False |
| 428 | JVMTI_REDEFINE_STRESS = args.jvmti_redefine_stress |
| 429 | JVMTI_STEP_STRESS = args.jvmti_step_stress |
| 430 | JVMTI_FIELD_STRESS = args.jvmti_field_stress |
| 431 | JVMTI_TRACE_STRESS = args.jvmti_trace_stress |
| 432 | PROFILE = args.profile |
| 433 | RANDOM_PROFILE = args.random_profile |
| 434 | DEX2OAT_TIMEOUT = args.dex2oat_timeout |
| 435 | DEX2OAT_RT_TIMEOUT = args.dex2oat_rt_timeout |
| 436 | CREATE_RUNNER = args.create_runner |
| 437 | INT_OPTS = "" |
| 438 | SIMPLEPERF = args.simpleperf |
| 439 | DEBUGGER_OPTS = "" |
| 440 | JVM_VERIFY_ARG = "" |
| 441 | LIB = args.lib |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 442 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 443 | # if True, run 'sync' before dalvikvm to make sure all files from |
| 444 | # build step (e.g. dex2oat) were finished writing. |
| 445 | SYNC_BEFORE_RUN = args.sync |
Igor Murashkin | 271a0f8 | 2017-02-14 21:14:17 +0000 | [diff] [blame] | 446 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 447 | # When running a debug build, we want to run with all checks. |
| 448 | ANDROID_FLAGS += " -XX:SlowDebug=true" |
| 449 | # The same for dex2oatd, both prebuild and runtime-driven. |
| 450 | ANDROID_FLAGS += (" -Xcompiler-option --runtime-arg -Xcompiler-option " |
| 451 | "-XX:SlowDebug=true") |
| 452 | COMPILER_FLAGS = " --runtime-arg -XX:SlowDebug=true" |
Andreas Gampe | 1c5b42f | 2017-06-15 18:20:45 -0700 | [diff] [blame] | 453 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 454 | # Let the compiler and runtime know that we are running tests. |
| 455 | COMPILE_FLAGS += " --compile-art-test" |
| 456 | ANDROID_FLAGS += " -Xcompiler-option --compile-art-test" |
David Srbecky | 4fa07a5 | 2020-03-31 20:52:09 +0100 | [diff] [blame] | 457 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 458 | if USE_JVMTI: |
| 459 | IS_JVMTI_TEST = True |
David Srbecky | 85786e7 | 2022-09-21 23:54:01 +0100 | [diff] [blame] | 460 | # Secondary images block some tested behavior. |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 461 | SECONDARY_APP_IMAGE = False |
| 462 | if args.gc_stress: |
David Srbecky | 85786e7 | 2022-09-21 23:54:01 +0100 | [diff] [blame] | 463 | # Give an extra 20 mins if we are gc-stress. |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 464 | TIME_OUT_EXTRA += 1200 |
| 465 | for arg in args.testlib: |
| 466 | ARGS += f" {arg}" |
David Srbecky | e4e701b | 2022-10-24 11:00:31 +0000 | [diff] [blame] | 467 | for arg in args.test_args: |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 468 | ARGS += f" {arg}" |
| 469 | for arg in args.compiler_only_option: |
| 470 | COMPILE_FLAGS += f" {arg}" |
| 471 | for arg in args.Xcompiler_option: |
| 472 | FLAGS += f" -Xcompiler-option {arg}" |
| 473 | COMPILE_FLAGS += f" {arg}" |
| 474 | if args.secondary: |
| 475 | SECONDARY_DEX = f":{DEX_LOCATION}/{TEST_NAME}-ex.jar" |
David Srbecky | 85786e7 | 2022-09-21 23:54:01 +0100 | [diff] [blame] | 476 | # Enable cfg-append to make sure we get the dump for both dex files. |
| 477 | # (otherwise the runtime compilation of the secondary dex will overwrite |
| 478 | # the dump of the first one). |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 479 | FLAGS += " -Xcompiler-option --dump-cfg-append" |
| 480 | COMPILE_FLAGS += " --dump-cfg-append" |
| 481 | for arg in args.android_runtime_option: |
| 482 | ANDROID_FLAGS += f" {arg}" |
| 483 | for arg in args.runtime_option: |
| 484 | FLAGS += f" {arg}" |
David Srbecky | 85786e7 | 2022-09-21 23:54:01 +0100 | [diff] [blame] | 485 | if arg == "-Xmethod-trace": |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 486 | # Method tracing can slow some tests down a lot. |
| 487 | TIME_OUT_EXTRA += 1200 |
| 488 | if args.compact_dex_level: |
| 489 | arg = args.compact_dex_level |
| 490 | COMPILE_FLAGS += f" --compact-dex-level={arg}" |
| 491 | if JVMTI_REDEFINE_STRESS: |
David Srbecky | 85786e7 | 2022-09-21 23:54:01 +0100 | [diff] [blame] | 492 | # APP_IMAGE doesn't really work with jvmti redefine stress |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 493 | SECONDARY_APP_IMAGE = False |
| 494 | JVMTI_STRESS = True |
| 495 | if JVMTI_REDEFINE_STRESS or JVMTI_STEP_STRESS or JVMTI_FIELD_STRESS or JVMTI_TRACE_STRESS: |
| 496 | USE_JVMTI = True |
| 497 | JVMTI_STRESS = True |
| 498 | if HOST: |
| 499 | ANDROID_ROOT = ANDROID_HOST_OUT |
| 500 | ANDROID_ART_ROOT = f"{ANDROID_HOST_OUT}/com.android.art" |
| 501 | ANDROID_I18N_ROOT = f"{ANDROID_HOST_OUT}/com.android.i18n" |
| 502 | ANDROID_TZDATA_ROOT = f"{ANDROID_HOST_OUT}/com.android.tzdata" |
David Srbecky | 85786e7 | 2022-09-21 23:54:01 +0100 | [diff] [blame] | 503 | # On host, we default to using the symlink, as the PREFER_32BIT |
| 504 | # configuration is the only configuration building a 32bit version of |
| 505 | # dex2oat. |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 506 | DEX2OAT_DEBUG_BINARY = "dex2oatd" |
| 507 | DEX2OAT_NDEBUG_BINARY = "dex2oat" |
| 508 | if BIONIC: |
David Srbecky | 85786e7 | 2022-09-21 23:54:01 +0100 | [diff] [blame] | 509 | # We need to create an ANDROID_ROOT because currently we cannot create |
| 510 | # the frameworks/libcore with linux_bionic so we need to use the normal |
| 511 | # host ones which are in a different location. |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 512 | CREATE_ANDROID_ROOT = True |
| 513 | if USE_ZIPAPEX: |
David Srbecky | 85786e7 | 2022-09-21 23:54:01 +0100 | [diff] [blame] | 514 | # TODO (b/119942078): Currently apex does not support |
| 515 | # symlink_preferred_arch so we will not have a dex2oatd to execute and |
| 516 | # need to manually provide |
| 517 | # dex2oatd64. |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 518 | DEX2OAT_DEBUG_BINARY = "dex2oatd64" |
| 519 | if WITH_AGENT: |
| 520 | USE_JVMTI = True |
| 521 | if DEBUGGER_AGENT: |
| 522 | DEBUGGER = "agent" |
| 523 | USE_JVMTI = True |
| 524 | TIME_OUT = "n" |
| 525 | if args.debug: |
| 526 | USE_JVMTI = True |
| 527 | DEBUGGER = "y" |
| 528 | TIME_OUT = "n" |
| 529 | if args.gdbserver_bin: |
David Srbecky | 85786e7 | 2022-09-21 23:54:01 +0100 | [diff] [blame] | 530 | arg = args.gdbserver_bin |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 531 | GDBSERVER_HOST = arg |
| 532 | GDBSERVER_DEVICE = arg |
| 533 | if args.gdbserver or args.gdb or USE_GDB_DEX2OAT: |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 534 | TIME_OUT = "n" |
| 535 | for arg in args.gdb_arg: |
| 536 | GDB_ARGS += f" {arg}" |
| 537 | if args.gdb_dex2oat_args: |
David Srbecky | 85786e7 | 2022-09-21 23:54:01 +0100 | [diff] [blame] | 538 | for arg in arg.split(";"): |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 539 | GDB_DEX2OAT_ARGS += f"{arg} " |
| 540 | if args.zygote: |
| 541 | ZYGOTE = "-Xzygote" |
David Srbecky | fe3d9c9 | 2022-11-10 18:57:15 +0000 | [diff] [blame] | 542 | print("Spawning from zygote") |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 543 | if args.baseline: |
| 544 | FLAGS += " -Xcompiler-option --baseline" |
| 545 | COMPILE_FLAGS += " --baseline" |
| 546 | if args.verify_soft_fail: |
| 547 | VERIFY = "s" |
| 548 | if args.is64: |
| 549 | SUFFIX64 = "64" |
| 550 | ISA = "x86_64" |
| 551 | GDBSERVER_DEVICE = "gdbserver64" |
| 552 | DALVIKVM = "dalvikvm64" |
| 553 | LIBRARY_DIRECTORY = "lib64" |
| 554 | TEST_DIRECTORY = "nativetest64" |
| 555 | ARCHITECTURES_PATTERN = ARCHITECTURES_64 |
| 556 | GET_DEVICE_ISA_BITNESS_FLAG = "--64" |
| 557 | DEX2OAT_NDEBUG_BINARY = "dex2oat64" |
| 558 | DEX2OAT_DEBUG_BINARY = "dex2oatd64" |
| 559 | if args.vdex_filter: |
| 560 | option = args.vdex_filter |
| 561 | VDEX_ARGS += f" --compiler-filter={option}" |
| 562 | if args.vdex_arg: |
David Srbecky | 85786e7 | 2022-09-21 23:54:01 +0100 | [diff] [blame] | 563 | arg = args.vdex_arg |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 564 | VDEX_ARGS += f" {arg}" |
David Srbecky | 4c93c25 | 2022-09-08 13:17:44 +0100 | [diff] [blame] | 565 | |
Roland Levillain | b59f5fb | 2020-02-19 16:22:48 +0000 | [diff] [blame] | 566 | # HACK: Force the use of `signal_dumper` on host. |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 567 | if HOST: |
| 568 | TIME_OUT = "timeout" |
Roland Levillain | 505e56b | 2019-11-20 08:49:24 +0000 | [diff] [blame] | 569 | |
Andreas Gampe | 6ad30a2 | 2019-09-12 15:12:36 -0700 | [diff] [blame] | 570 | # If you change this, update the timeout in testrunner.py as well. |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 571 | if not TIME_OUT_VALUE: |
| 572 | # 10 minutes is the default. |
| 573 | TIME_OUT_VALUE = 600 |
Andreas Gampe | 6ad30a2 | 2019-09-12 15:12:36 -0700 | [diff] [blame] | 574 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 575 | # For sanitized builds use a larger base. |
| 576 | # TODO: Consider sanitized target builds? |
| 577 | if SANITIZE_HOST != "": |
| 578 | TIME_OUT_VALUE = 1500 # 25 minutes. |
Andreas Gampe | 6ad30a2 | 2019-09-12 15:12:36 -0700 | [diff] [blame] | 579 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 580 | TIME_OUT_VALUE += TIME_OUT_EXTRA |
Andreas Gampe | 6ad30a2 | 2019-09-12 15:12:36 -0700 | [diff] [blame] | 581 | |
Andreas Gampe | 29bfb0c | 2019-09-12 15:17:43 -0700 | [diff] [blame] | 582 | # Escape hatch for slow hosts or devices. Accept an environment variable as a timeout factor. |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 583 | if ART_TIME_OUT_MULTIPLIER: |
| 584 | TIME_OUT_VALUE *= ART_TIME_OUT_MULTIPLIER |
Andreas Gampe | 29bfb0c | 2019-09-12 15:17:43 -0700 | [diff] [blame] | 585 | |
Roland Levillain | 76cfe61 | 2017-10-30 13:14:28 +0000 | [diff] [blame] | 586 | # The DEX_LOCATION with the chroot prefix, if any. |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 587 | CHROOT_DEX_LOCATION = f"{CHROOT}{DEX_LOCATION}" |
Roland Levillain | 76cfe61 | 2017-10-30 13:14:28 +0000 | [diff] [blame] | 588 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 589 | # If running on device, determine the ISA of the device. |
| 590 | if not HOST and not USE_JVM: |
| 591 | ISA = run( |
| 592 | f"{ANDROID_BUILD_TOP}/art/test/utils/get-device-isa {GET_DEVICE_ISA_BITNESS_FLAG}", |
| 593 | adb.env, |
| 594 | save_cmd=False).stdout.strip() |
David Srbecky | 49506de | 2022-11-25 12:00:06 +0000 | [diff] [blame] | 595 | target_arch = get_target_arch(args.is64) # Should return the same ISA. |
| 596 | assert ISA == target_arch, f"{ISA} vs {target_arch}" |
Roland Levillain | 72f6774 | 2019-03-06 15:48:08 +0000 | [diff] [blame] | 597 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 598 | if not USE_JVM: |
| 599 | FLAGS += f" {ANDROID_FLAGS}" |
Alex Light | baac7e4 | 2018-06-08 15:30:11 +0000 | [diff] [blame] | 600 | # we don't want to be trying to get adbconnections since the plugin might |
| 601 | # not have been built. |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 602 | FLAGS += " -XjdwpProvider:none" |
David Srbecky | bfa76b3 | 2022-06-20 21:30:56 +0100 | [diff] [blame] | 603 | for feature in EXPERIMENTAL: |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 604 | FLAGS += f" -Xexperimental:{feature} -Xcompiler-option --runtime-arg -Xcompiler-option -Xexperimental:{feature}" |
| 605 | COMPILE_FLAGS = f"{COMPILE_FLAGS} --runtime-arg -Xexperimental:{feature}" |
Alex Light | 8a0e033 | 2015-10-26 10:11:58 -0700 | [diff] [blame] | 606 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 607 | if CREATE_ANDROID_ROOT: |
| 608 | ANDROID_ROOT = f"{DEX_LOCATION}/android-root" |
Alex Light | 680cbf2 | 2018-10-31 11:00:19 -0700 | [diff] [blame] | 609 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 610 | if ZYGOTE == "": |
David Srbecky | c6d2a79 | 2022-08-18 14:15:43 +0100 | [diff] [blame] | 611 | if OPTIMIZE: |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 612 | if VERIFY == "y": |
| 613 | DEX_OPTIMIZE = "-Xdexopt:verified" |
| 614 | else: |
| 615 | DEX_OPTIMIZE = "-Xdexopt:all" |
David Srbecky | fe3d9c9 | 2022-11-10 18:57:15 +0000 | [diff] [blame] | 616 | print("Performing optimizations") |
David Srbecky | bfa76b3 | 2022-06-20 21:30:56 +0100 | [diff] [blame] | 617 | else: |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 618 | DEX_OPTIMIZE = "-Xdexopt:none" |
David Srbecky | fe3d9c9 | 2022-11-10 18:57:15 +0000 | [diff] [blame] | 619 | print("Skipping optimizations") |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 620 | |
David Srbecky | bfa76b3 | 2022-06-20 21:30:56 +0100 | [diff] [blame] | 621 | if VERIFY == "y": |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 622 | JVM_VERIFY_ARG = "-Xverify:all" |
David Srbecky | fe3d9c9 | 2022-11-10 18:57:15 +0000 | [diff] [blame] | 623 | print("Performing verification") |
David Srbecky | bfa76b3 | 2022-06-20 21:30:56 +0100 | [diff] [blame] | 624 | elif VERIFY == "s": |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 625 | JVM_VERIFY_ARG = "Xverify:all" |
| 626 | DEX_VERIFY = "-Xverify:softfail" |
David Srbecky | fe3d9c9 | 2022-11-10 18:57:15 +0000 | [diff] [blame] | 627 | print("Forcing verification to be soft fail") |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 628 | else: # VERIFY == "n" |
| 629 | DEX_VERIFY = "-Xverify:none" |
| 630 | JVM_VERIFY_ARG = "-Xverify:none" |
David Srbecky | fe3d9c9 | 2022-11-10 18:57:15 +0000 | [diff] [blame] | 631 | print("Skipping verification") |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 632 | |
David Srbecky | fe3d9c9 | 2022-11-10 18:57:15 +0000 | [diff] [blame] | 633 | print("------------------------------") |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 634 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 635 | if DEBUGGER == "y": |
| 636 | # Use this instead for ddms and connect by running 'ddms': |
| 637 | # DEBUGGER_OPTS="-XjdwpOptions=server=y,suspend=y -XjdwpProvider:adbconnection" |
| 638 | # TODO: add a separate --ddms option? |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 639 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 640 | PORT = 12345 |
David Srbecky | fe3d9c9 | 2022-11-10 18:57:15 +0000 | [diff] [blame] | 641 | print("Waiting for jdb to connect:") |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 642 | if not HOST: |
David Srbecky | fe3d9c9 | 2022-11-10 18:57:15 +0000 | [diff] [blame] | 643 | print(f" adb forward tcp:{PORT} tcp:{PORT}") |
| 644 | print(f" jdb -attach localhost:{PORT}") |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 645 | if not USE_JVM: |
| 646 | # Use the default libjdwp agent. Use --debug-agent to use a custom one. |
| 647 | DEBUGGER_OPTS = f"-agentpath:libjdwp.so=transport=dt_socket,address={PORT},server=y,suspend=y -XjdwpProvider:internal" |
| 648 | else: |
| 649 | DEBUGGER_OPTS = f"-agentlib:jdwp=transport=dt_socket,address={PORT},server=y,suspend=y" |
| 650 | elif DEBUGGER == "agent": |
| 651 | PORT = 12345 |
| 652 | # TODO Support ddms connection and support target. |
David Srbecky | e4e701b | 2022-10-24 11:00:31 +0000 | [diff] [blame] | 653 | assert HOST, "--debug-agent not supported yet for target!" |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 654 | AGENTPATH = DEBUGGER_AGENT |
| 655 | if WRAP_DEBUGGER_AGENT: |
| 656 | WRAPPROPS = f"{ANDROID_ROOT}/{LIBRARY_DIRECTORY}/libwrapagentpropertiesd.so" |
| 657 | if TEST_IS_NDEBUG: |
| 658 | WRAPPROPS = f"{ANDROID_ROOT}/{LIBRARY_DIRECTORY}/libwrapagentproperties.so" |
| 659 | AGENTPATH = f"{WRAPPROPS}={ANDROID_BUILD_TOP}/art/tools/libjdwp-compat.props,{AGENTPATH}" |
David Srbecky | fe3d9c9 | 2022-11-10 18:57:15 +0000 | [diff] [blame] | 660 | print(f"Connect to localhost:{PORT}") |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 661 | DEBUGGER_OPTS = f"-agentpath:{AGENTPATH}=transport=dt_socket,address={PORT},server=y,suspend=y" |
Alex Light | c281ba5 | 2017-10-11 11:35:55 -0700 | [diff] [blame] | 662 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 663 | for agent in WITH_AGENT: |
| 664 | FLAGS += f" -agentpath:{agent}" |
Alex Light | 0e151e7 | 2017-10-25 10:50:35 -0700 | [diff] [blame] | 665 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 666 | if USE_JVMTI: |
| 667 | if not USE_JVM: |
| 668 | plugin = "libopenjdkjvmtid.so" |
| 669 | if TEST_IS_NDEBUG: |
| 670 | plugin = "libopenjdkjvmti.so" |
| 671 | # We used to add flags here that made the runtime debuggable but that is not |
| 672 | # needed anymore since the plugin can do it for us now. |
| 673 | FLAGS += f" -Xplugin:{plugin}" |
Mythri Alle | f0d8b44 | 2021-11-03 17:28:24 +0000 | [diff] [blame] | 674 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 675 | # For jvmti tests, set the threshold of compilation to 1, so we jit early to |
| 676 | # provide better test coverage for jvmti + jit. This means we won't run |
| 677 | # the default --jit configuration but it is not too important test scenario for |
| 678 | # jvmti tests. This is art specific flag, so don't use it with jvm. |
| 679 | FLAGS += " -Xjitthreshold:1" |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 680 | |
Alex Light | 280e6c3 | 2020-03-03 13:52:07 -0800 | [diff] [blame] | 681 | # Add the libdir to the argv passed to the main function. |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 682 | if ADD_LIBDIR_ARGUMENTS: |
| 683 | if HOST: |
| 684 | ARGS += f" {ANDROID_HOST_OUT}/{TEST_DIRECTORY}/" |
| 685 | else: |
| 686 | ARGS += f" /data/{TEST_DIRECTORY}/art/{ISA}/" |
David Srbecky | c6d2a79 | 2022-08-18 14:15:43 +0100 | [diff] [blame] | 687 | if IS_JVMTI_TEST: |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 688 | agent = "libtiagentd.so" |
| 689 | lib = "tiagentd" |
| 690 | if TEST_IS_NDEBUG: |
| 691 | agent = "libtiagent.so" |
| 692 | lib = "tiagent" |
Nicolas Geoffray | 288a4a2 | 2014-10-07 11:02:40 +0100 | [diff] [blame] | 693 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 694 | ARGS += f" {lib}" |
| 695 | if USE_JVM: |
| 696 | FLAGS += f" -agentpath:{ANDROID_HOST_OUT}/nativetest64/{agent}={TEST_NAME},jvm" |
| 697 | else: |
| 698 | FLAGS += f" -agentpath:{agent}={TEST_NAME},art" |
Artem Serov | 55e509f | 2022-01-26 11:59:22 +0000 | [diff] [blame] | 699 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 700 | if JVMTI_STRESS: |
| 701 | agent = "libtistressd.so" |
| 702 | if TEST_IS_NDEBUG: |
| 703 | agent = "libtistress.so" |
| 704 | |
| 705 | # Just give it a default start so we can always add ',' to it. |
| 706 | agent_args = "jvmti-stress" |
| 707 | if JVMTI_REDEFINE_STRESS: |
| 708 | # We really cannot do this on RI so don't both passing it in that case. |
| 709 | if not USE_JVM: |
| 710 | agent_args = f"{agent_args},redefine" |
| 711 | if JVMTI_FIELD_STRESS: |
| 712 | agent_args = f"{agent_args},field" |
| 713 | if JVMTI_STEP_STRESS: |
| 714 | agent_args = f"{agent_args},step" |
| 715 | if JVMTI_TRACE_STRESS: |
| 716 | agent_args = f"{agent_args},trace" |
| 717 | # In the future add onto this; |
| 718 | if USE_JVM: |
| 719 | FLAGS += f" -agentpath:{ANDROID_HOST_OUT}/nativetest64/{agent}={agent_args}" |
| 720 | else: |
| 721 | FLAGS += f" -agentpath:{agent}={agent_args}" |
| 722 | |
| 723 | if USE_JVM: |
| 724 | env = { |
| 725 | "ANDROID_I18N_ROOT": ANDROID_I18N_ROOT, |
| 726 | "DEX_LOCATION": DEX_LOCATION, |
| 727 | "JAVA_HOME": os.environ["JAVA_HOME"], |
| 728 | "LANG": |
| 729 | "en_US.UTF-8", # Needed to enable unicode and make the output is deterministic. |
| 730 | "LD_LIBRARY_PATH": f"{ANDROID_HOST_OUT}/lib64", |
| 731 | } |
| 732 | # Some jvmti tests are flaky without -Xint on the RI. |
| 733 | if IS_JVMTI_TEST: |
| 734 | FLAGS += " -Xint" |
| 735 | # Xmx is necessary since we don't pass down the ART flags to JVM. |
| 736 | # We pass the classes2 path whether it's used (src-multidex) or not. |
David Srbecky | e4e701b | 2022-10-24 11:00:31 +0000 | [diff] [blame] | 737 | cmdline = f"{JAVA} {DEBUGGER_OPTS} {JVM_VERIFY_ARG} -Xmx256m -classpath classes:classes2 {FLAGS} {MAIN} {ARGS}" |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 738 | if CREATE_RUNNER: |
| 739 | with open("runit.sh", "w") as f: |
| 740 | f.write("#!/bin/bash") |
| 741 | print(f"export LD_LIBRARY_PATH=\"{LD_LIBRARY_PATH}\"") |
| 742 | f.write(cmdline) |
| 743 | os.chmod("runit.sh", 0o777) |
| 744 | pwd = os.getcwd() |
| 745 | print(f"Runnable test script written to {pwd}/runit.sh") |
David Srbecky | e4e701b | 2022-10-24 11:00:31 +0000 | [diff] [blame] | 746 | return |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 747 | else: |
David Srbecky | 93749ed | 2022-11-09 15:24:45 +0000 | [diff] [blame] | 748 | run(tee(cmdline), |
David Srbecky | 35a48ce | 2022-11-09 12:19:29 +0000 | [diff] [blame] | 749 | env, |
David Srbecky | 35a48ce | 2022-11-09 12:19:29 +0000 | [diff] [blame] | 750 | expected_exit_code=args.expected_exit_code) |
David Srbecky | e4e701b | 2022-10-24 11:00:31 +0000 | [diff] [blame] | 751 | return |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 752 | |
| 753 | b_path = get_apex_bootclasspath(HOST) |
| 754 | b_path_locations = get_apex_bootclasspath_locations(HOST) |
| 755 | |
| 756 | BCPEX = "" |
| 757 | if isfile(f"{TEST_NAME}-bcpex.jar"): |
| 758 | BCPEX = f":{DEX_LOCATION}/{TEST_NAME}-bcpex.jar" |
Vladimir Marko | 239c941 | 2022-01-05 16:09:09 +0000 | [diff] [blame] | 759 | |
David Srbecky | fe3d9c9 | 2022-11-10 18:57:15 +0000 | [diff] [blame] | 760 | # Pass down the bootclasspath |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 761 | FLAGS += f" -Xbootclasspath:{b_path}{BCPEX}" |
| 762 | FLAGS += f" -Xbootclasspath-locations:{b_path_locations}{BCPEX}" |
| 763 | COMPILE_FLAGS += f" --runtime-arg -Xbootclasspath:{b_path}" |
| 764 | COMPILE_FLAGS += f" --runtime-arg -Xbootclasspath-locations:{b_path_locations}" |
Nicolas Geoffray | 288a4a2 | 2014-10-07 11:02:40 +0100 | [diff] [blame] | 765 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 766 | if not HAVE_IMAGE: |
Andreas Gampe | 1078d15 | 2017-11-07 18:00:54 -0800 | [diff] [blame] | 767 | # Disable image dex2oat - this will forbid the runtime to patch or compile an image. |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 768 | FLAGS += " -Xnoimage-dex2oat" |
Andreas Gampe | 1078d15 | 2017-11-07 18:00:54 -0800 | [diff] [blame] | 769 | |
| 770 | # We'll abuse a second flag here to test different behavior. If --relocate, use the |
| 771 | # existing image - relocation will fail as patching is disallowed. If --no-relocate, |
| 772 | # pass a non-existent image - compilation will fail as dex2oat is disallowed. |
David Srbecky | c6d2a79 | 2022-08-18 14:15:43 +0100 | [diff] [blame] | 773 | if not RELOCATE: |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 774 | BOOT_IMAGE = "/system/non-existent/boot.art" |
Nicolas Geoffray | 48eb839 | 2022-02-24 16:20:18 +0000 | [diff] [blame] | 775 | # App images cannot be generated without a boot image. |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 776 | APP_IMAGE = False |
| 777 | DALVIKVM_BOOT_OPT = f"-Ximage:{BOOT_IMAGE}" |
Nicolas Geoffray | 288a4a2 | 2014-10-07 11:02:40 +0100 | [diff] [blame] | 778 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 779 | if USE_GDB_DEX2OAT: |
David Srbecky | e4e701b | 2022-10-24 11:00:31 +0000 | [diff] [blame] | 780 | assert HOST, "The --gdb-dex2oat option is not yet implemented for target." |
Dmitrii Ishcheikin | e60131a | 2022-10-07 11:45:44 +0000 | [diff] [blame] | 781 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 782 | if USE_GDB: |
David Srbecky | e4e701b | 2022-10-24 11:00:31 +0000 | [diff] [blame] | 783 | assert not USE_GDBSERVER, "Cannot pass both --gdb and --gdbserver at the same time!" |
| 784 | if not HOST: |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 785 | # We might not have any hostname resolution if we are using a chroot. |
| 786 | GDB = f"{GDBSERVER_DEVICE} --no-startup-with-shell 127.0.0.1{GDBSERVER_PORT}" |
| 787 | else: |
| 788 | if run("uname").stdout.strip() == "Darwin": |
| 789 | GDB = "lldb" |
| 790 | GDB_ARGS += f" -- {DALVIKVM}" |
| 791 | DALVIKVM = "" |
| 792 | else: |
| 793 | GDB = "gdb" |
| 794 | GDB_ARGS += f" --args {DALVIKVM}" |
| 795 | # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line. |
| 796 | # gdbargs=f"--annotate=3 {gdbargs}" |
| 797 | elif USE_GDBSERVER: |
| 798 | if not HOST: |
| 799 | # We might not have any hostname resolution if we are using a chroot. |
| 800 | GDB = f"{GDBSERVER_DEVICE} --no-startup-with-shell 127.0.0.1{GDBSERVER_PORT}" |
| 801 | else: |
| 802 | GDB = f"{GDBSERVER_HOST} {GDBSERVER_PORT}" |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 803 | |
David Srbecky | e4e701b | 2022-10-24 11:00:31 +0000 | [diff] [blame] | 804 | assert shutil.which(GDBSERVER_HOST), f"{GDBSERVER_HOST} is not available" |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 805 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 806 | if INTERPRETER: |
| 807 | INT_OPTS += " -Xint" |
Nicolas Geoffray | c76fbf0 | 2021-04-06 08:59:17 +0100 | [diff] [blame] | 808 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 809 | if JIT: |
| 810 | INT_OPTS += " -Xusejit:true" |
| 811 | else: |
| 812 | INT_OPTS += " -Xusejit:false" |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 813 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 814 | if INTERPRETER or JIT: |
| 815 | if VERIFY == "y": |
| 816 | INT_OPTS += " -Xcompiler-option --compiler-filter=verify" |
| 817 | COMPILE_FLAGS += " --compiler-filter=verify" |
| 818 | elif VERIFY == "s": |
| 819 | INT_OPTS += " -Xcompiler-option --compiler-filter=extract" |
| 820 | COMPILE_FLAGS += " --compiler-filter=extract" |
| 821 | DEX_VERIFY = f"{DEX_VERIFY} -Xverify:softfail" |
| 822 | else: # VERIFY == "n" |
| 823 | INT_OPTS += " -Xcompiler-option --compiler-filter=assume-verified" |
| 824 | COMPILE_FLAGS += " --compiler-filter=assume-verified" |
| 825 | DEX_VERIFY = f"{DEX_VERIFY} -Xverify:none" |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 826 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 827 | JNI_OPTS = "-Xjnigreflimit:512 -Xcheck:jni" |
| 828 | |
| 829 | COMPILE_FLAGS += " --runtime-arg -Xnorelocate" |
| 830 | if RELOCATE: |
| 831 | FLAGS += " -Xrelocate" |
| 832 | else: |
| 833 | FLAGS += " -Xnorelocate" |
| 834 | |
| 835 | if BIONIC: |
| 836 | # This is the location that soong drops linux_bionic builds. Despite being |
| 837 | # called linux_bionic-x86 the build is actually amd64 (x86_64) only. |
David Srbecky | e4e701b | 2022-10-24 11:00:31 +0000 | [diff] [blame] | 838 | assert path.exists(f"{OUT_DIR}/soong/host/linux_bionic-x86"), ( |
| 839 | "linux_bionic-x86 target doesn't seem to have been built!") |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 840 | # Set TIMEOUT_DUMPER manually so it works even with apex's |
| 841 | TIMEOUT_DUMPER = f"{OUT_DIR}/soong/host/linux_bionic-x86/bin/signal_dumper" |
Alex Light | 680cbf2 | 2018-10-31 11:00:19 -0700 | [diff] [blame] | 842 | |
David Srbecky | fe3d9c9 | 2022-11-10 18:57:15 +0000 | [diff] [blame] | 843 | # Prevent test from silently falling back to interpreter in no-prebuild mode. This happens |
| 844 | # when DEX_LOCATION path is too long, because vdex/odex filename is constructed by taking |
| 845 | # full path to dex, stripping leading '/', appending '@classes.vdex' and changing every |
| 846 | # remaining '/' into '@'. |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 847 | if HOST: |
| 848 | max_filename_size = int( |
| 849 | run(f"getconf NAME_MAX {DEX_LOCATION}", save_cmd=False).stdout) |
| 850 | else: |
| 851 | # There is no getconf on device, fallback to standard value. |
| 852 | # See NAME_MAX in kernel <linux/limits.h> |
| 853 | max_filename_size = 255 |
David Srbecky | fe3d9c9 | 2022-11-10 18:57:15 +0000 | [diff] [blame] | 854 | # Compute VDEX_NAME. |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 855 | DEX_LOCATION_STRIPPED = DEX_LOCATION.lstrip("/") |
| 856 | VDEX_NAME = f"{DEX_LOCATION_STRIPPED}@{TEST_NAME}.jar@classes.vdex".replace( |
| 857 | "/", "@") |
David Srbecky | e4e701b | 2022-10-24 11:00:31 +0000 | [diff] [blame] | 858 | assert len(VDEX_NAME) <= max_filename_size, "Dex location path too long" |
Wojciech Staszkiewicz | e663653 | 2016-09-23 10:59:55 -0700 | [diff] [blame] | 859 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 860 | if HOST: |
| 861 | # On host, run binaries (`dex2oat(d)`, `dalvikvm`, `profman`) from the `bin` |
| 862 | # directory under the "Android Root" (usually `out/host/linux-x86`). |
| 863 | # |
| 864 | # TODO(b/130295968): Adjust this if/when ART host artifacts are installed |
| 865 | # under the ART root (usually `out/host/linux-x86/com.android.art`). |
| 866 | ANDROID_ART_BIN_DIR = f"{ANDROID_ROOT}/bin" |
| 867 | else: |
| 868 | # On target, run binaries (`dex2oat(d)`, `dalvikvm`, `profman`) from the ART |
| 869 | # APEX's `bin` directory. This means the linker will observe the ART APEX |
| 870 | # linker configuration file (`/apex/com.android.art/etc/ld.config.txt`) for |
| 871 | # these binaries. |
| 872 | ANDROID_ART_BIN_DIR = f"{ANDROID_ART_ROOT}/bin" |
Alex Light | 20802ca | 2018-12-05 15:36:03 -0800 | [diff] [blame] | 873 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 874 | profman_cmdline = "true" |
| 875 | dex2oat_cmdline = "true" |
| 876 | vdex_cmdline = "true" |
| 877 | dm_cmdline = "true" |
| 878 | mkdir_locations = f"{DEX_LOCATION}/dalvik-cache/{ISA}" |
| 879 | strip_cmdline = "true" |
| 880 | sync_cmdline = "true" |
| 881 | linkroot_cmdline = "true" |
| 882 | linkroot_overlay_cmdline = "true" |
| 883 | setupapex_cmdline = "true" |
| 884 | installapex_cmdline = "true" |
| 885 | installapex_test_cmdline = "true" |
Alex Light | 680cbf2 | 2018-10-31 11:00:19 -0700 | [diff] [blame] | 886 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 887 | def linkdirs(host_out: str, root: str): |
| 888 | dirs = list(filter(os.path.isdir, glob.glob(os.path.join(host_out, "*")))) |
| 889 | # Also create a link for the boot image. |
| 890 | dirs.append(f"{ANDROID_HOST_OUT}/apex/art_boot_images") |
| 891 | return " && ".join(f"ln -sf {dir} {root}" for dir in dirs) |
Alex Light | 680cbf2 | 2018-10-31 11:00:19 -0700 | [diff] [blame] | 892 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 893 | if CREATE_ANDROID_ROOT: |
| 894 | mkdir_locations += f" {ANDROID_ROOT}" |
| 895 | linkroot_cmdline = linkdirs(ANDROID_HOST_OUT, ANDROID_ROOT) |
| 896 | if BIONIC: |
| 897 | # TODO Make this overlay more generic. |
| 898 | linkroot_overlay_cmdline = linkdirs( |
| 899 | f"{OUT_DIR}/soong/host/linux_bionic-x86", ANDROID_ROOT) |
| 900 | # Replace the boot image to a location expected by the runtime. |
| 901 | DALVIKVM_BOOT_OPT = f"-Ximage:{ANDROID_ROOT}/art_boot_images/javalib/boot.art" |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 902 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 903 | if USE_ZIPAPEX: |
| 904 | # TODO Currently this only works for linux_bionic zipapexes because those are |
| 905 | # stripped and so small enough that the ulimit doesn't kill us. |
| 906 | mkdir_locations += f" {DEX_LOCATION}/zipapex" |
| 907 | setupapex_cmdline = f"unzip -o -u {ZIPAPEX_LOC} apex_payload.zip -d {DEX_LOCATION}" |
| 908 | installapex_cmdline = f"unzip -o -u {DEX_LOCATION}/apex_payload.zip -d {DEX_LOCATION}/zipapex" |
| 909 | ANDROID_ART_BIN_DIR = f"{DEX_LOCATION}/zipapex/bin" |
| 910 | elif USE_EXTRACTED_ZIPAPEX: |
| 911 | # Just symlink the zipapex binaries |
| 912 | ANDROID_ART_BIN_DIR = f"{DEX_LOCATION}/zipapex/bin" |
| 913 | # Force since some tests manually run this file twice. |
| 914 | # If the {RUN} is executed multiple times we don't need to recreate the link |
| 915 | installapex_test_cmdline = f"test -L {DEX_LOCATION}/zipapex" |
| 916 | installapex_cmdline = f"ln -s -f --verbose {EXTRACTED_ZIPAPEX_LOC} {DEX_LOCATION}/zipapex" |
Alex Light | 20802ca | 2018-12-05 15:36:03 -0800 | [diff] [blame] | 917 | |
David Srbecky | fe3d9c9 | 2022-11-10 18:57:15 +0000 | [diff] [blame] | 918 | # PROFILE takes precedence over RANDOM_PROFILE, since PROFILE tests require a |
| 919 | # specific profile to run properly. |
David Srbecky | c6d2a79 | 2022-08-18 14:15:43 +0100 | [diff] [blame] | 920 | if PROFILE or RANDOM_PROFILE: |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 921 | profman_cmdline = f"{ANDROID_ART_BIN_DIR}/profman \ |
| 922 | --apk={DEX_LOCATION}/{TEST_NAME}.jar \ |
| 923 | --dex-location={DEX_LOCATION}/{TEST_NAME}.jar" |
| 924 | |
| 925 | if isfile(f"{TEST_NAME}-ex.jar") and SECONDARY_COMPILATION: |
| 926 | profman_cmdline = f"{profman_cmdline} \ |
| 927 | --apk={DEX_LOCATION}/{TEST_NAME}-ex.jar \ |
| 928 | --dex-location={DEX_LOCATION}/{TEST_NAME}-ex.jar" |
| 929 | |
| 930 | COMPILE_FLAGS = f"{COMPILE_FLAGS} --profile-file={DEX_LOCATION}/{TEST_NAME}.prof" |
| 931 | FLAGS = f"{FLAGS} -Xcompiler-option --profile-file={DEX_LOCATION}/{TEST_NAME}.prof" |
| 932 | if PROFILE: |
| 933 | profman_cmdline = f"{profman_cmdline} --create-profile-from={DEX_LOCATION}/profile \ |
| 934 | --reference-profile-file={DEX_LOCATION}/{TEST_NAME}.prof" |
| 935 | |
David Srbecky | bfa76b3 | 2022-06-20 21:30:56 +0100 | [diff] [blame] | 936 | else: |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 937 | profman_cmdline = f"{profman_cmdline} --generate-test-profile={DEX_LOCATION}/{TEST_NAME}.prof \ |
| 938 | --generate-test-profile-seed=0" |
| 939 | |
| 940 | def get_prebuilt_lldb_path(): |
| 941 | CLANG_BASE = "prebuilts/clang/host" |
| 942 | CLANG_VERSION = run( |
| 943 | f"{ANDROID_BUILD_TOP}/build/soong/scripts/get_clang_version.py" |
| 944 | ).stdout.strip() |
| 945 | uname = run("uname -s").stdout.strip() |
| 946 | if uname == "Darwin": |
| 947 | PREBUILT_NAME = "darwin-x86" |
| 948 | elif uname == "Linux": |
| 949 | PREBUILT_NAME = "linux-x86" |
| 950 | else: |
| 951 | print( |
| 952 | "Unknown host $(uname -s). Unsupported for debugging dex2oat with LLDB.", |
| 953 | file=sys.stderr) |
| 954 | return |
| 955 | CLANG_PREBUILT_HOST_PATH = f"{ANDROID_BUILD_TOP}/{CLANG_BASE}/{PREBUILT_NAME}/{CLANG_VERSION}" |
| 956 | # If the clang prebuilt directory exists and the reported clang version |
| 957 | # string does not, then it is likely that the clang version reported by the |
| 958 | # get_clang_version.py script does not match the expected directory name. |
David Srbecky | e4e701b | 2022-10-24 11:00:31 +0000 | [diff] [blame] | 959 | if isdir(f"{ANDROID_BUILD_TOP}/{CLANG_BASE}/{PREBUILT_NAME}"): |
| 960 | assert isdir(CLANG_PREBUILT_HOST_PATH), ( |
| 961 | "The prebuilt clang directory exists, but the specific " |
| 962 | "clang\nversion reported by get_clang_version.py does not exist in " |
| 963 | "that path.\nPlease make sure that the reported clang version " |
| 964 | "resides in the\nprebuilt clang directory!") |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 965 | |
| 966 | # The lldb-server binary is a dependency of lldb. |
| 967 | os.environ[ |
| 968 | "LLDB_DEBUGSERVER_PATH"] = f"{CLANG_PREBUILT_HOST_PATH}/runtimes_ndk_cxx/x86_64/lldb-server" |
| 969 | |
| 970 | # Set the current terminfo directory to TERMINFO so that LLDB can read the |
| 971 | # termcap database. |
| 972 | terminfo = re.search("/.*/terminfo/", run("infocmp", save_cmd=False).stdout) |
| 973 | if terminfo: |
| 974 | os.environ["TERMINFO"] = terminfo[0] |
| 975 | |
| 976 | return f"{CLANG_PREBUILT_HOST_PATH}/bin/lldb.sh" |
| 977 | |
| 978 | def write_dex2oat_cmdlines(name: str): |
David Srbecky | e4e701b | 2022-10-24 11:00:31 +0000 | [diff] [blame] | 979 | nonlocal dex2oat_cmdline, dm_cmdline, vdex_cmdline |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 980 | |
| 981 | class_loader_context = "" |
| 982 | enable_app_image = False |
| 983 | if APP_IMAGE: |
| 984 | enable_app_image = True |
| 985 | |
| 986 | # If the name ends in -ex then this is a secondary dex file |
| 987 | if name.endswith("-ex"): |
| 988 | # Lazily realize the default value in case DEX_LOCATION/TEST_NAME change |
David Srbecky | e4e701b | 2022-10-24 11:00:31 +0000 | [diff] [blame] | 989 | nonlocal SECONDARY_CLASS_LOADER_CONTEXT |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 990 | if SECONDARY_CLASS_LOADER_CONTEXT == "": |
| 991 | if SECONDARY_DEX == "": |
| 992 | # Tests without `--secondary` load the "-ex" jar in a separate PathClassLoader |
| 993 | # that is a child of the main PathClassLoader. If the class loader is constructed |
| 994 | # in any other way, the test needs to specify the secondary CLC explicitly. |
| 995 | SECONDARY_CLASS_LOADER_CONTEXT = f"PCL[];PCL[{DEX_LOCATION}/{TEST_NAME}.jar]" |
| 996 | else: |
| 997 | # Tests with `--secondary` load the `-ex` jar a part of the main PathClassLoader. |
| 998 | SECONDARY_CLASS_LOADER_CONTEXT = f"PCL[{DEX_LOCATION}/{TEST_NAME}.jar]" |
| 999 | class_loader_context = f"'--class-loader-context={SECONDARY_CLASS_LOADER_CONTEXT}'" |
| 1000 | enable_app_image = enable_app_image and SECONDARY_APP_IMAGE |
| 1001 | |
| 1002 | app_image = "" |
| 1003 | if enable_app_image: |
| 1004 | app_image = f"--app-image-file={DEX_LOCATION}/oat/{ISA}/{name}.art --resolve-startup-const-strings=true" |
| 1005 | |
David Srbecky | e4e701b | 2022-10-24 11:00:31 +0000 | [diff] [blame] | 1006 | nonlocal GDB_DEX2OAT, GDB_DEX2OAT_ARGS |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1007 | if USE_GDB_DEX2OAT: |
| 1008 | prebuilt_lldb_path = get_prebuilt_lldb_path() |
| 1009 | GDB_DEX2OAT = f"{prebuilt_lldb_path} -f" |
| 1010 | GDB_DEX2OAT_ARGS += " -- " |
| 1011 | |
| 1012 | dex2oat_binary = DEX2OAT_DEBUG_BINARY |
| 1013 | if TEST_IS_NDEBUG: |
| 1014 | dex2oat_binary = DEX2OAT_NDEBUG_BINARY |
| 1015 | dex2oat_cmdline = f"{INVOKE_WITH} {GDB_DEX2OAT} \ |
| 1016 | {ANDROID_ART_BIN_DIR}/{dex2oat_binary} \ |
| 1017 | {GDB_DEX2OAT_ARGS} \ |
| 1018 | {COMPILE_FLAGS} \ |
| 1019 | --boot-image={BOOT_IMAGE} \ |
| 1020 | --dex-file={DEX_LOCATION}/{name}.jar \ |
| 1021 | --oat-file={DEX_LOCATION}/oat/{ISA}/{name}.odex \ |
| 1022 | {app_image} \ |
| 1023 | --generate-mini-debug-info \ |
| 1024 | --instruction-set={ISA} \ |
| 1025 | {class_loader_context}" |
| 1026 | |
| 1027 | if INSTRUCTION_SET_FEATURES != "": |
| 1028 | dex2oat_cmdline += f" --instruction-set-features={INSTRUCTION_SET_FEATURES}" |
| 1029 | |
| 1030 | # Add in a timeout. This is important for testing the compilation/verification time of |
| 1031 | # pathological cases. We do not append a timeout when debugging dex2oat because we |
| 1032 | # do not want it to exit while debugging. |
| 1033 | # Note: as we don't know how decent targets are (e.g., emulator), only do this on the host for |
| 1034 | # now. We should try to improve this. |
| 1035 | # The current value is rather arbitrary. run-tests should compile quickly. |
| 1036 | # Watchdog timeout is in milliseconds so add 3 '0's to the dex2oat timeout. |
| 1037 | if HOST and not USE_GDB_DEX2OAT: |
| 1038 | # Use SIGRTMIN+2 to try to dump threads. |
| 1039 | # Use -k 1m to SIGKILL it a minute later if it hasn't ended. |
| 1040 | dex2oat_cmdline = f"timeout -k {DEX2OAT_TIMEOUT}s -s SIGRTMIN+2 {DEX2OAT_RT_TIMEOUT}s {dex2oat_cmdline} --watchdog-timeout={DEX2OAT_TIMEOUT}000" |
| 1041 | if PROFILE or RANDOM_PROFILE: |
| 1042 | vdex_cmdline = f"{dex2oat_cmdline} {VDEX_ARGS} --input-vdex={DEX_LOCATION}/oat/{ISA}/{name}.vdex --output-vdex={DEX_LOCATION}/oat/{ISA}/{name}.vdex" |
| 1043 | elif TEST_VDEX: |
| 1044 | if VDEX_ARGS == "": |
| 1045 | # If no arguments need to be passed, just delete the odex file so that the runtime only picks up the vdex file. |
| 1046 | vdex_cmdline = f"rm {DEX_LOCATION}/oat/{ISA}/{name}.odex" |
| 1047 | else: |
| 1048 | vdex_cmdline = f"{dex2oat_cmdline} {VDEX_ARGS} --compact-dex-level=none --input-vdex={DEX_LOCATION}/oat/{ISA}/{name}.vdex" |
| 1049 | elif TEST_DEX2OAT_DM: |
| 1050 | vdex_cmdline = f"{dex2oat_cmdline} {VDEX_ARGS} --dump-timings --dm-file={DEX_LOCATION}/oat/{ISA}/{name}.dm" |
| 1051 | dex2oat_cmdline = f"{dex2oat_cmdline} --copy-dex-files=false --output-vdex={DEX_LOCATION}/oat/{ISA}/primary.vdex" |
| 1052 | dm_cmdline = f"zip -qj {DEX_LOCATION}/oat/{ISA}/{name}.dm {DEX_LOCATION}/oat/{ISA}/primary.vdex" |
| 1053 | elif TEST_RUNTIME_DM: |
| 1054 | dex2oat_cmdline = f"{dex2oat_cmdline} --copy-dex-files=false --output-vdex={DEX_LOCATION}/oat/{ISA}/primary.vdex" |
| 1055 | dm_cmdline = f"zip -qj {DEX_LOCATION}/{name}.dm {DEX_LOCATION}/oat/{ISA}/primary.vdex" |
Andreas Gampe | 038a198 | 2020-03-11 23:06:42 +0000 | [diff] [blame] | 1056 | |
| 1057 | # Enable mini-debug-info for JIT (if JIT is used). |
Andreas Gampe | 038a198 | 2020-03-11 23:06:42 +0000 | [diff] [blame] | 1058 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1059 | FLAGS += " -Xcompiler-option --generate-mini-debug-info" |
Andreas Gampe | 038a198 | 2020-03-11 23:06:42 +0000 | [diff] [blame] | 1060 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1061 | if PREBUILD: |
| 1062 | mkdir_locations += f" {DEX_LOCATION}/oat/{ISA}" |
Andreas Gampe | 038a198 | 2020-03-11 23:06:42 +0000 | [diff] [blame] | 1063 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1064 | # "Primary". |
| 1065 | write_dex2oat_cmdlines(TEST_NAME) |
| 1066 | dex2oat_cmdline = re.sub(" +", " ", dex2oat_cmdline) |
| 1067 | dm_cmdline = re.sub(" +", " ", dm_cmdline) |
| 1068 | vdex_cmdline = re.sub(" +", " ", vdex_cmdline) |
Andreas Gampe | 038a198 | 2020-03-11 23:06:42 +0000 | [diff] [blame] | 1069 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1070 | # Enable mini-debug-info for JIT (if JIT is used). |
| 1071 | FLAGS += " -Xcompiler-option --generate-mini-debug-info" |
Andreas Gampe | 038a198 | 2020-03-11 23:06:42 +0000 | [diff] [blame] | 1072 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1073 | if isfile(f"{TEST_NAME}-ex.jar") and SECONDARY_COMPILATION: |
| 1074 | # "Secondary" for test coverage. |
Andreas Gampe | 038a198 | 2020-03-11 23:06:42 +0000 | [diff] [blame] | 1075 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1076 | # Store primary values. |
| 1077 | base_dex2oat_cmdline = dex2oat_cmdline |
| 1078 | base_dm_cmdline = dm_cmdline |
| 1079 | base_vdex_cmdline = vdex_cmdline |
Andreas Gampe | 038a198 | 2020-03-11 23:06:42 +0000 | [diff] [blame] | 1080 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1081 | write_dex2oat_cmdlines(f"{TEST_NAME}-ex") |
| 1082 | dex2oat_cmdline = re.sub(" +", " ", dex2oat_cmdline) |
| 1083 | dm_cmdline = re.sub(" +", " ", dm_cmdline) |
| 1084 | vdex_cmdline = re.sub(" +", " ", vdex_cmdline) |
Andreas Gampe | 4d2ef33 | 2015-08-05 09:24:45 -0700 | [diff] [blame] | 1085 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1086 | # Concatenate. |
| 1087 | dex2oat_cmdline = f"{base_dex2oat_cmdline} && {dex2oat_cmdline}" |
| 1088 | dm_cmdline = base_dm_cmdline # Only use primary dm. |
| 1089 | vdex_cmdline = f"{base_vdex_cmdline} && {vdex_cmdline}" |
Igor Murashkin | 271a0f8 | 2017-02-14 21:14:17 +0000 | [diff] [blame] | 1090 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1091 | if SYNC_BEFORE_RUN: |
| 1092 | sync_cmdline = "sync" |
| 1093 | |
| 1094 | DALVIKVM_ISA_FEATURES_ARGS = "" |
| 1095 | if INSTRUCTION_SET_FEATURES != "": |
| 1096 | DALVIKVM_ISA_FEATURES_ARGS = f"-Xcompiler-option --instruction-set-features={INSTRUCTION_SET_FEATURES}" |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 1097 | |
Nicolas Geoffray | c525604 | 2015-12-26 19:41:37 +0000 | [diff] [blame] | 1098 | # java.io.tmpdir can only be set at launch time. |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1099 | TMP_DIR_OPTION = "" |
| 1100 | if not HOST: |
| 1101 | TMP_DIR_OPTION = "-Djava.io.tmpdir=/data/local/tmp" |
Nicolas Geoffray | c525604 | 2015-12-26 19:41:37 +0000 | [diff] [blame] | 1102 | |
Alex Light | b801210 | 2019-11-13 01:41:04 +0000 | [diff] [blame] | 1103 | # The build servers have an ancient version of bash so we cannot use @Q. |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1104 | QUOTED_DALVIKVM_BOOT_OPT = shlex.quote(DALVIKVM_BOOT_OPT) |
Alex Light | b801210 | 2019-11-13 01:41:04 +0000 | [diff] [blame] | 1105 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1106 | DALVIKVM_CLASSPATH = f"{DEX_LOCATION}/{TEST_NAME}.jar" |
| 1107 | if isfile(f"{TEST_NAME}-aotex.jar"): |
| 1108 | DALVIKVM_CLASSPATH = f"{DALVIKVM_CLASSPATH}:{DEX_LOCATION}/{TEST_NAME}-aotex.jar" |
| 1109 | DALVIKVM_CLASSPATH = f"{DALVIKVM_CLASSPATH}{SECONDARY_DEX}" |
Vladimir Marko | 239c941 | 2022-01-05 16:09:09 +0000 | [diff] [blame] | 1110 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1111 | # We set DumpNativeStackOnSigQuit to false to avoid stressing libunwind. |
| 1112 | # b/27185632 |
| 1113 | # b/24664297 |
Ulya Trafimovich | 7f7f644 | 2021-11-05 15:26:13 +0000 | [diff] [blame] | 1114 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1115 | dalvikvm_cmdline = f"{INVOKE_WITH} {GDB} {ANDROID_ART_BIN_DIR}/{DALVIKVM} \ |
David Srbecky | 93749ed | 2022-11-09 15:24:45 +0000 | [diff] [blame] | 1116 | {GDB_ARGS} \ |
| 1117 | {FLAGS} \ |
| 1118 | {DEX_VERIFY} \ |
| 1119 | -XXlib:{LIB} \ |
| 1120 | {DEX2OAT} \ |
| 1121 | {DALVIKVM_ISA_FEATURES_ARGS} \ |
| 1122 | {ZYGOTE} \ |
| 1123 | {JNI_OPTS} \ |
| 1124 | {INT_OPTS} \ |
| 1125 | {DEBUGGER_OPTS} \ |
| 1126 | {QUOTED_DALVIKVM_BOOT_OPT} \ |
| 1127 | {TMP_DIR_OPTION} \ |
| 1128 | -XX:DumpNativeStackOnSigQuit:false \ |
| 1129 | -cp {DALVIKVM_CLASSPATH} {MAIN} {ARGS}" |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 1130 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1131 | if SIMPLEPERF: |
| 1132 | dalvikvm_cmdline = f"simpleperf record {dalvikvm_cmdline} && simpleperf report" |
Ulya Trafimovich | 7f7f644 | 2021-11-05 15:26:13 +0000 | [diff] [blame] | 1133 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1134 | def sanitize_dex2oat_cmdline(cmdline: str) -> str: |
| 1135 | args = [] |
| 1136 | for arg in cmdline.split(" "): |
| 1137 | if arg == "--class-loader-context=&": |
| 1138 | arg = "--class-loader-context=\&" |
| 1139 | args.append(arg) |
| 1140 | return " ".join(args) |
Andreas Gampe | 038a198 | 2020-03-11 23:06:42 +0000 | [diff] [blame] | 1141 | |
David Srbecky | fe3d9c9 | 2022-11-10 18:57:15 +0000 | [diff] [blame] | 1142 | # Remove whitespace. |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1143 | dex2oat_cmdline = sanitize_dex2oat_cmdline(dex2oat_cmdline) |
| 1144 | dalvikvm_cmdline = re.sub(" +", " ", dalvikvm_cmdline) |
| 1145 | dm_cmdline = re.sub(" +", " ", dm_cmdline) |
| 1146 | vdex_cmdline = sanitize_dex2oat_cmdline(vdex_cmdline) |
| 1147 | profman_cmdline = re.sub(" +", " ", profman_cmdline) |
Andreas Gampe | b31a8e7 | 2017-05-16 10:30:24 -0700 | [diff] [blame] | 1148 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1149 | # Use an empty ASAN_OPTIONS to enable defaults. |
| 1150 | # Note: this is required as envsetup right now exports detect_leaks=0. |
| 1151 | RUN_TEST_ASAN_OPTIONS = "" |
Andreas Gampe | 5840839 | 2017-05-16 10:45:46 -0700 | [diff] [blame] | 1152 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1153 | # Multiple shutdown leaks. b/38341789 |
| 1154 | if RUN_TEST_ASAN_OPTIONS != "": |
| 1155 | RUN_TEST_ASAN_OPTIONS = f"{RUN_TEST_ASAN_OPTIONS}:" |
| 1156 | RUN_TEST_ASAN_OPTIONS = f"{RUN_TEST_ASAN_OPTIONS}detect_leaks=0" |
| 1157 | |
David Srbecky | fe3d9c9 | 2022-11-10 18:57:15 +0000 | [diff] [blame] | 1158 | assert not args.external_log_tags, "Deprecated: use --android-log-tags=*:v" |
| 1159 | |
| 1160 | ANDROID_LOG_TAGS = args.android_log_tags |
Nicolas Geoffray | f39f04c | 2018-03-05 15:42:11 +0000 | [diff] [blame] | 1161 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1162 | if not HOST: |
Roland Levillain | 72f6774 | 2019-03-06 15:48:08 +0000 | [diff] [blame] | 1163 | # Populate LD_LIBRARY_PATH. |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1164 | LD_LIBRARY_PATH = "" |
David Srbecky | bfa76b3 | 2022-06-20 21:30:56 +0100 | [diff] [blame] | 1165 | if ANDROID_ROOT != "/system": |
Nicolas Geoffray | eb441dd | 2014-10-31 15:34:50 +0000 | [diff] [blame] | 1166 | # Current default installation is dalvikvm 64bits and dex2oat 32bits, |
| 1167 | # so we can only use LD_LIBRARY_PATH when testing on a local |
| 1168 | # installation. |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1169 | LD_LIBRARY_PATH = f"{ANDROID_ROOT}/{LIBRARY_DIRECTORY}" |
Martin Stjernholm | 0d0f8df | 2021-04-28 16:47:01 +0100 | [diff] [blame] | 1170 | |
| 1171 | # This adds libarttest(d).so to the default linker namespace when dalvikvm |
| 1172 | # is run from /apex/com.android.art/bin. Since that namespace is essentially |
| 1173 | # an alias for the com_android_art namespace, that gives libarttest(d).so |
| 1174 | # full access to the internal ART libraries. |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1175 | LD_LIBRARY_PATH = f"/data/{TEST_DIRECTORY}/com.android.art/lib{SUFFIX64}:{LD_LIBRARY_PATH}" |
| 1176 | dlib = ("" if TEST_IS_NDEBUG else "d") |
| 1177 | art_test_internal_libraries = [ |
| 1178 | f"libartagent{dlib}.so", |
| 1179 | f"libarttest{dlib}.so", |
| 1180 | f"libtiagent{dlib}.so", |
| 1181 | f"libtistress{dlib}.so", |
David Srbecky | bfa76b3 | 2022-06-20 21:30:56 +0100 | [diff] [blame] | 1182 | ] |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1183 | NATIVELOADER_DEFAULT_NAMESPACE_LIBS = ":".join(art_test_internal_libraries) |
| 1184 | dlib = "" |
| 1185 | art_test_internal_libraries = [] |
Martin Stjernholm | 0d0f8df | 2021-04-28 16:47:01 +0100 | [diff] [blame] | 1186 | |
Roland Levillain | 72f6774 | 2019-03-06 15:48:08 +0000 | [diff] [blame] | 1187 | # Needed to access the test's Odex files. |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1188 | LD_LIBRARY_PATH = f"{DEX_LOCATION}/oat/{ISA}:{LD_LIBRARY_PATH}" |
Roland Levillain | 72f6774 | 2019-03-06 15:48:08 +0000 | [diff] [blame] | 1189 | # Needed to access the test's native libraries (see e.g. 674-hiddenapi, |
David Srbecky | bfa76b3 | 2022-06-20 21:30:56 +0100 | [diff] [blame] | 1190 | # which generates `libhiddenapitest_*.so` libraries in `{DEX_LOCATION}`). |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1191 | LD_LIBRARY_PATH = f"{DEX_LOCATION}:{LD_LIBRARY_PATH}" |
Nicolas Geoffray | eb441dd | 2014-10-31 15:34:50 +0000 | [diff] [blame] | 1192 | |
Roland Levillain | 72f6774 | 2019-03-06 15:48:08 +0000 | [diff] [blame] | 1193 | # Prepend directories to the path on device. |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1194 | PREPEND_TARGET_PATH = ANDROID_ART_BIN_DIR |
David Srbecky | bfa76b3 | 2022-06-20 21:30:56 +0100 | [diff] [blame] | 1195 | if ANDROID_ROOT != "/system": |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1196 | PREPEND_TARGET_PATH = f"{PREPEND_TARGET_PATH}:{ANDROID_ROOT}/bin" |
Roland Levillain | 72f6774 | 2019-03-06 15:48:08 +0000 | [diff] [blame] | 1197 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1198 | timeout_dumper_cmd = "" |
Andreas Gampe | a613808 | 2019-09-11 11:08:23 -0700 | [diff] [blame] | 1199 | |
David Srbecky | bfa76b3 | 2022-06-20 21:30:56 +0100 | [diff] [blame] | 1200 | if TIMEOUT_DUMPER: |
Andreas Gampe | 975d70b | 2019-09-11 11:00:18 -0700 | [diff] [blame] | 1201 | # Use "-l" to dump to logcat. That is convenience for the build bot crash symbolization. |
Andreas Gampe | 38a2818 | 2019-09-13 11:36:11 -0700 | [diff] [blame] | 1202 | # Use exit code 124 for toybox timeout (b/141007616). |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1203 | timeout_dumper_cmd = f"{TIMEOUT_DUMPER} -l -s 15 -e 124" |
Andreas Gampe | 975d70b | 2019-09-11 11:00:18 -0700 | [diff] [blame] | 1204 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1205 | timeout_prefix = "" |
David Srbecky | bfa76b3 | 2022-06-20 21:30:56 +0100 | [diff] [blame] | 1206 | if TIME_OUT == "timeout": |
Andreas Gampe | 975d70b | 2019-09-11 11:00:18 -0700 | [diff] [blame] | 1207 | # Add timeout command if time out is desired. |
| 1208 | # |
| 1209 | # Note: We first send SIGTERM (the timeout default, signal 15) to the signal dumper, which |
| 1210 | # will induce a full thread dump before killing the process. To ensure any issues in |
| 1211 | # dumping do not lead to a deadlock, we also use the "-k" option to definitely kill the |
| 1212 | # child. |
| 1213 | # Note: Using "--foreground" to not propagate the signal to children, i.e., the runtime. |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1214 | timeout_prefix = f"timeout --foreground -k 120s {TIME_OUT_VALUE}s {timeout_dumper_cmd} {cmdline}" |
Andreas Gampe | 975d70b | 2019-09-11 11:00:18 -0700 | [diff] [blame] | 1215 | |
David Srbecky | d7674c2 | 2022-10-03 18:22:13 +0100 | [diff] [blame] | 1216 | env = { |
| 1217 | "ASAN_OPTIONS": RUN_TEST_ASAN_OPTIONS, |
| 1218 | "ANDROID_DATA": DEX_LOCATION, |
| 1219 | "DEX_LOCATION": DEX_LOCATION, |
| 1220 | "ANDROID_ROOT": ANDROID_ROOT, |
| 1221 | "ANDROID_I18N_ROOT": ANDROID_I18N_ROOT, |
| 1222 | "ANDROID_ART_ROOT": ANDROID_ART_ROOT, |
| 1223 | "ANDROID_TZDATA_ROOT": ANDROID_TZDATA_ROOT, |
| 1224 | "ANDROID_LOG_TAGS": ANDROID_LOG_TAGS, |
| 1225 | "LD_LIBRARY_PATH": LD_LIBRARY_PATH, |
| 1226 | "NATIVELOADER_DEFAULT_NAMESPACE_LIBS": NATIVELOADER_DEFAULT_NAMESPACE_LIBS, |
| 1227 | "PATH": f"{PREPEND_TARGET_PATH}:$PATH", |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1228 | } # pyformat: disable |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 1229 | |
David Srbecky | e4e701b | 2022-10-24 11:00:31 +0000 | [diff] [blame] | 1230 | def run_cmd(cmdline: str, env={}, **kwargs) -> subprocess.CompletedProcess: |
| 1231 | if cmdline == "true" or DRY_RUN: |
| 1232 | return run('true') # Noop command which just executes the linux 'true' binary. |
David Srbecky | d7674c2 | 2022-10-03 18:22:13 +0100 | [diff] [blame] | 1233 | cmdline = (f"cd {DEX_LOCATION} && " + |
| 1234 | "".join(f"export {k}={v} && " for k, v in env.items()) + |
| 1235 | cmdline) |
| 1236 | # Create a script with the command. The command can get longer than the longest |
| 1237 | # allowed adb command and there is no way to get the exit status from a adb shell command. |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1238 | with NamedTemporaryFile(mode="w") as cmdfile: |
David Srbecky | 93749ed | 2022-11-09 15:24:45 +0000 | [diff] [blame] | 1239 | cmdfile.write("echo '$$ {}'\n".format(cmdline.replace("'", r"'\''"))) |
David Srbecky | d7674c2 | 2022-10-03 18:22:13 +0100 | [diff] [blame] | 1240 | cmdfile.write(cmdline) |
| 1241 | cmdfile.flush() |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1242 | adb.push( |
| 1243 | cmdfile.name, f"{CHROOT_DEX_LOCATION}/cmdline.sh", save_cmd=False) |
David Srbecky | 93749ed | 2022-11-09 15:24:45 +0000 | [diff] [blame] | 1244 | chroot_prefix = f"chroot {CHROOT}" if CHROOT else "" |
David Srbecky | e4e701b | 2022-10-24 11:00:31 +0000 | [diff] [blame] | 1245 | return adb.shell(f"{chroot_prefix} sh {DEX_LOCATION}/cmdline.sh", **kwargs) |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 1246 | |
David Srbecky | fe3d9c9 | 2022-11-10 18:57:15 +0000 | [diff] [blame] | 1247 | if USE_GDB or USE_GDBSERVER: |
David Srbecky | d7674c2 | 2022-10-03 18:22:13 +0100 | [diff] [blame] | 1248 | print(f"Forward {GDBSERVER_PORT} to local port and connect GDB") |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 1249 | |
David Srbecky | 66bd69a | 2022-11-21 18:33:08 +0000 | [diff] [blame] | 1250 | run_cmd(f"rm -rf {DEX_LOCATION}/{{oat,dalvik-cache}}/ && mkdir -p {mkdir_locations}") |
David Srbecky | d7674c2 | 2022-10-03 18:22:13 +0100 | [diff] [blame] | 1251 | run_cmd(f"{profman_cmdline}", env) |
| 1252 | run_cmd(f"{dex2oat_cmdline}", env) |
| 1253 | run_cmd(f"{dm_cmdline}", env) |
| 1254 | run_cmd(f"{vdex_cmdline}", env) |
| 1255 | run_cmd(f"{strip_cmdline}") |
| 1256 | run_cmd(f"{sync_cmdline}") |
David Srbecky | 93749ed | 2022-11-09 15:24:45 +0000 | [diff] [blame] | 1257 | run_cmd(tee(f"{timeout_prefix} {dalvikvm_cmdline}"), |
David Srbecky | 35a48ce | 2022-11-09 12:19:29 +0000 | [diff] [blame] | 1258 | env, |
David Srbecky | 35a48ce | 2022-11-09 12:19:29 +0000 | [diff] [blame] | 1259 | expected_exit_code=args.expected_exit_code) |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1260 | else: |
Calin Juravle | 24bd3f9 | 2017-05-11 00:36:53 -0700 | [diff] [blame] | 1261 | # Host run. |
David Srbecky | c6d2a79 | 2022-08-18 14:15:43 +0100 | [diff] [blame] | 1262 | if USE_ZIPAPEX or USE_EXRACTED_ZIPAPEX: |
Alex Light | 20802ca | 2018-12-05 15:36:03 -0800 | [diff] [blame] | 1263 | # Put the zipapex files in front of the ld-library-path |
David Srbecky | d7674c2 | 2022-10-03 18:22:13 +0100 | [diff] [blame] | 1264 | LD_LIBRARY_PATH = f"{ANDROID_DATA}/zipapex/{LIBRARY_DIRECTORY}:{ANDROID_ROOT}/{TEST_DIRECTORY}" |
David Srbecky | bfa76b3 | 2022-06-20 21:30:56 +0100 | [diff] [blame] | 1265 | else: |
David Srbecky | d7674c2 | 2022-10-03 18:22:13 +0100 | [diff] [blame] | 1266 | LD_LIBRARY_PATH = f"{ANDROID_ROOT}/{LIBRARY_DIRECTORY}:{ANDROID_ROOT}/{TEST_DIRECTORY}" |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 1267 | |
David Srbecky | d7674c2 | 2022-10-03 18:22:13 +0100 | [diff] [blame] | 1268 | env = { |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1269 | "ANDROID_PRINTF_LOG": "brief", |
| 1270 | "ASAN_OPTIONS": RUN_TEST_ASAN_OPTIONS, |
| 1271 | "ANDROID_DATA": DEX_LOCATION, |
| 1272 | "DEX_LOCATION": DEX_LOCATION, |
| 1273 | "ANDROID_ROOT": ANDROID_ROOT, |
| 1274 | "ANDROID_I18N_ROOT": ANDROID_I18N_ROOT, |
| 1275 | "ANDROID_ART_ROOT": ANDROID_ART_ROOT, |
| 1276 | "ANDROID_TZDATA_ROOT": ANDROID_TZDATA_ROOT, |
| 1277 | "ANDROID_LOG_TAGS": ANDROID_LOG_TAGS, |
| 1278 | "LD_LIBRARY_PATH": LD_LIBRARY_PATH, |
| 1279 | "PATH": f"{PATH}:{ANDROID_ART_BIN_DIR}", |
| 1280 | # Temporarily disable address space layout randomization (ASLR). |
| 1281 | # This is needed on the host so that the linker loads core.oat at the necessary address. |
| 1282 | "LD_USE_LOAD_BIAS": "1", |
David Srbecky | d7674c2 | 2022-10-03 18:22:13 +0100 | [diff] [blame] | 1283 | } |
David Srbecky | c9ede38 | 2015-06-20 06:03:53 +0100 | [diff] [blame] | 1284 | |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1285 | cmdline = dalvikvm_cmdline |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 1286 | |
David Srbecky | bfa76b3 | 2022-06-20 21:30:56 +0100 | [diff] [blame] | 1287 | if TIME_OUT == "gdb": |
| 1288 | if run("uname").stdout.strip() == "Darwin": |
Hiroshi Yamauchi | 6ffb9cc | 2015-08-31 15:14:17 -0700 | [diff] [blame] | 1289 | # Fall back to timeout on Mac. |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1290 | TIME_OUT = "timeout" |
David Srbecky | bfa76b3 | 2022-06-20 21:30:56 +0100 | [diff] [blame] | 1291 | elif ISA == "x86": |
Hiroshi Yamauchi | c823eff | 2015-09-01 16:21:35 -0700 | [diff] [blame] | 1292 | # prctl call may fail in 32-bit on an older (3.2) 64-bit Linux kernel. Fall back to timeout. |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1293 | TIME_OUT = "timeout" |
David Srbecky | bfa76b3 | 2022-06-20 21:30:56 +0100 | [diff] [blame] | 1294 | else: |
Hiroshi Yamauchi | 6ffb9cc | 2015-08-31 15:14:17 -0700 | [diff] [blame] | 1295 | # Check if gdb is available. |
David Srbecky | e60b4a7 | 2022-09-27 14:53:06 +0100 | [diff] [blame] | 1296 | proc = run('gdb --eval-command="quit"', check=False, save_cmd=False) |
David Srbecky | bfa76b3 | 2022-06-20 21:30:56 +0100 | [diff] [blame] | 1297 | if proc.returncode != 0: |
Hiroshi Yamauchi | 6ffb9cc | 2015-08-31 15:14:17 -0700 | [diff] [blame] | 1298 | # gdb isn't available. Fall back to timeout. |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1299 | TIME_OUT = "timeout" |
Hiroshi Yamauchi | 6ffb9cc | 2015-08-31 15:14:17 -0700 | [diff] [blame] | 1300 | |
David Srbecky | bfa76b3 | 2022-06-20 21:30:56 +0100 | [diff] [blame] | 1301 | if TIME_OUT == "timeout": |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 1302 | # Add timeout command if time out is desired. |
Andreas Gampe | 038bb22 | 2015-01-13 19:48:14 -0800 | [diff] [blame] | 1303 | # |
Andreas Gampe | 0df2aba | 2019-06-10 16:53:55 -0700 | [diff] [blame] | 1304 | # Note: We first send SIGTERM (the timeout default, signal 15) to the signal dumper, which |
| 1305 | # will induce a full thread dump before killing the process. To ensure any issues in |
| 1306 | # dumping do not lead to a deadlock, we also use the "-k" option to definitely kill the |
| 1307 | # child. |
Andreas Gampe | 4bdcf5d | 2018-12-14 10:48:53 -0800 | [diff] [blame] | 1308 | # Note: Using "--foreground" to not propagate the signal to children, i.e., the runtime. |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1309 | cmdline = f"timeout --foreground -k 120s {TIME_OUT_VALUE}s {TIMEOUT_DUMPER} -s 15 {cmdline}" |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 1310 | |
David Srbecky | bfa76b3 | 2022-06-20 21:30:56 +0100 | [diff] [blame] | 1311 | os.chdir(ANDROID_BUILD_TOP) |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 1312 | |
Calin Juravle | 24bd3f9 | 2017-05-11 00:36:53 -0700 | [diff] [blame] | 1313 | # Make sure we delete any existing compiler artifacts. |
| 1314 | # This enables tests to call the RUN script multiple times in a row |
| 1315 | # without worrying about interference. |
David Srbecky | bfa76b3 | 2022-06-20 21:30:56 +0100 | [diff] [blame] | 1316 | shutil.rmtree(f"{DEX_LOCATION}/oat", ignore_errors=True) |
| 1317 | shutil.rmtree(f"{DEX_LOCATION}/dalvik-cache/", ignore_errors=True) |
Calin Juravle | 24bd3f9 | 2017-05-11 00:36:53 -0700 | [diff] [blame] | 1318 | |
David Srbecky | bfa76b3 | 2022-06-20 21:30:56 +0100 | [diff] [blame] | 1319 | run(f"mkdir -p {mkdir_locations}", save_cmd=False) |
David Srbecky | e60b4a7 | 2022-09-27 14:53:06 +0100 | [diff] [blame] | 1320 | run(setupapex_cmdline) |
| 1321 | if run(installapex_test_cmdline, check=False).returncode != 0: |
| 1322 | run(installapex_cmdline) |
| 1323 | run(linkroot_cmdline) |
| 1324 | run(linkroot_overlay_cmdline) |
David Srbecky | d7674c2 | 2022-10-03 18:22:13 +0100 | [diff] [blame] | 1325 | run(profman_cmdline, env) |
| 1326 | run(dex2oat_cmdline, env) |
| 1327 | run(dm_cmdline, env) |
| 1328 | run(vdex_cmdline, env) |
David Srbecky | e60b4a7 | 2022-09-27 14:53:06 +0100 | [diff] [blame] | 1329 | run(strip_cmdline) |
| 1330 | run(sync_cmdline) |
Andreas Gampe | a878082 | 2015-03-13 19:51:09 -0700 | [diff] [blame] | 1331 | |
David Srbecky | c6d2a79 | 2022-08-18 14:15:43 +0100 | [diff] [blame] | 1332 | if CREATE_RUNNER: |
David Srbecky | bfa76b3 | 2022-06-20 21:30:56 +0100 | [diff] [blame] | 1333 | with open(f"{DEX_LOCATION}/runit.sh", "w") as f: |
| 1334 | f.write("#!/bin/bash") |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1335 | for var in ("ANDROID_PRINTF_LOG ANDROID_DATA ANDROID_ROOT " |
| 1336 | "ANDROID_I18N_ROOT ANDROID_TZDATA_ROOT ANDROID_ART_ROOT " |
| 1337 | "LD_LIBRARY_PATH DYLD_LIBRARY_PATH PATH LD_USE_LOAD_BIAS" |
| 1338 | ).split(" "): |
David Srbecky | bfa76b3 | 2022-06-20 21:30:56 +0100 | [diff] [blame] | 1339 | value = os.environ.get(var, "") |
| 1340 | f.write(f'export {var}="{value}"') |
David Srbecky | fe3d9c9 | 2022-11-10 18:57:15 +0000 | [diff] [blame] | 1341 | f.write(cmdline) |
David Srbecky | bfa76b3 | 2022-06-20 21:30:56 +0100 | [diff] [blame] | 1342 | os.chmod("{DEX_LOCATION}/runit.sh", 0o777) |
| 1343 | print(f"Runnable test script written to {DEX_LOCATION}/runit.sh") |
David Srbecky | c6d2a79 | 2022-08-18 14:15:43 +0100 | [diff] [blame] | 1344 | if DRY_RUN: |
David Srbecky | e4e701b | 2022-10-24 11:00:31 +0000 | [diff] [blame] | 1345 | return |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 1346 | |
David Srbecky | c6d2a79 | 2022-08-18 14:15:43 +0100 | [diff] [blame] | 1347 | if USE_GDB: |
Nicolas Geoffray | 1a58b7f | 2014-10-06 12:23:04 +0100 | [diff] [blame] | 1348 | # When running under gdb, we cannot do piping and grepping... |
Dmitrii Ishcheikin | e60131a | 2022-10-07 11:45:44 +0000 | [diff] [blame] | 1349 | env["TERM"] = os.environ.get("TERM", "") |
David Srbecky | d828fc1 | 2022-10-12 14:45:04 +0100 | [diff] [blame] | 1350 | subprocess.run(cmdline, env=env, shell=True) |
David Srbecky | c6d2a79 | 2022-08-18 14:15:43 +0100 | [diff] [blame] | 1351 | elif USE_GDBSERVER: |
Dmitrii Ishcheikin | e60131a | 2022-10-07 11:45:44 +0000 | [diff] [blame] | 1352 | print(f"Connect to {GDBSERVER_PORT}") |
Alex Light | e4b4a18 | 2019-02-12 14:19:49 -0800 | [diff] [blame] | 1353 | # When running under gdb, we cannot do piping and grepping... |
David Srbecky | d828fc1 | 2022-10-12 14:45:04 +0100 | [diff] [blame] | 1354 | subprocess.run(cmdline, env=env, shell=True) |
David Srbecky | bfa76b3 | 2022-06-20 21:30:56 +0100 | [diff] [blame] | 1355 | else: |
| 1356 | if TIME_OUT != "gdb": |
David Srbecky | 93749ed | 2022-11-09 15:24:45 +0000 | [diff] [blame] | 1357 | run(tee(cmdline), |
David Srbecky | e4e701b | 2022-10-24 11:00:31 +0000 | [diff] [blame] | 1358 | env, |
David Srbecky | e4e701b | 2022-10-24 11:00:31 +0000 | [diff] [blame] | 1359 | expected_exit_code=args.expected_exit_code) |
David Srbecky | fe3d9c9 | 2022-11-10 18:57:15 +0000 | [diff] [blame] | 1360 | |
David Srbecky | b5e9703 | 2022-11-16 15:02:33 +0000 | [diff] [blame] | 1361 | # Remove unwanted log messages from stderr before diffing with the expected output. |
| 1362 | # NB: The unwanted log line can be interleaved in the middle of wanted stderr printf. |
| 1363 | # In particular, unhandled exception is printed using several unterminated printfs. |
David Srbecky | fe3d9c9 | 2022-11-10 18:57:15 +0000 | [diff] [blame] | 1364 | ALL_LOG_TAGS = ["V", "D", "I", "W", "E", "F", "S"] |
| 1365 | skip_tag_set = "|".join(ALL_LOG_TAGS[:ALL_LOG_TAGS.index(args.diff_min_log_tag.upper())]) |
David Srbecky | b5e9703 | 2022-11-16 15:02:33 +0000 | [diff] [blame] | 1366 | skip_reg_exp = fr'[[:alnum:]]+ ({skip_tag_set}) #-# #:#:# [^\n]*\n'.replace('#', '[0-9]+') |
| 1367 | run(fr"sed -i -z -E 's/{skip_reg_exp}//g' '{args.stderr_file}'") |
David Srbecky | fe3d9c9 | 2022-11-10 18:57:15 +0000 | [diff] [blame] | 1368 | if not HAVE_IMAGE: |
David Srbecky | b0c6bbf | 2022-11-15 13:46:15 +0000 | [diff] [blame] | 1369 | message = "(Unable to open file|Could not create image space)" |
| 1370 | run(fr"sed -i -E '/^dalvikvm(|32|64) E .* {message}/d' '{args.stderr_file}'") |
David Srbecky | b5e9703 | 2022-11-16 15:02:33 +0000 | [diff] [blame] | 1371 | if ANDROID_LOG_TAGS != "*:i" and "D" in skip_tag_set: |
David Srbecky | fe3d9c9 | 2022-11-10 18:57:15 +0000 | [diff] [blame] | 1372 | run(fr"sed -i -E '/^(Time zone|I18n) APEX ICU file found/d' '{args.stderr_file}'") |
David Srbecky | bfa76b3 | 2022-06-20 21:30:56 +0100 | [diff] [blame] | 1373 | else: |
Hiroshi Yamauchi | 6ffb9cc | 2015-08-31 15:14:17 -0700 | [diff] [blame] | 1374 | # With a thread dump that uses gdb if a timeout. |
David Srbecky | d828fc1 | 2022-10-12 14:45:04 +0100 | [diff] [blame] | 1375 | proc = run(cmdline, check=False) |
David Srbecky | bfa76b3 | 2022-06-20 21:30:56 +0100 | [diff] [blame] | 1376 | # TODO: Spawn a watcher process. |
| 1377 | raise Exception("Not implemented") |
| 1378 | # ( sleep {TIME_OUT_VALUE} && \ |
| 1379 | # echo "##### Thread dump using gdb on test timeout" && \ |
| 1380 | # ( gdb -q -p {pid} --eval-command="info thread" --eval-command="thread apply all bt" \ |
| 1381 | # --eval-command="call exit(124)" --eval-command=quit || \ |
| 1382 | # kill {pid} )) 2> /dev/null & watcher=$! |
David Srbecky | 94d2141 | 2022-10-10 16:02:51 +0100 | [diff] [blame] | 1383 | test_exit_status = proc.returncode |
David Srbecky | bfa76b3 | 2022-06-20 21:30:56 +0100 | [diff] [blame] | 1384 | # pkill -P {watcher} 2> /dev/null # kill the sleep which will in turn end the watcher as well |
David Srbecky | e4e701b | 2022-10-24 11:00:31 +0000 | [diff] [blame] | 1385 | if proc.returncode == 124 and TIME_OUT == "timeout": |
| 1386 | print("\e[91mTEST TIMED OUT!\e[0m", file=sys.stderr) |
| 1387 | assert proc.returncode == args.expected_exit_code, f"exit code: {proc.returncode}" |