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