brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.3 KiB · ec39406 Raw
81 lines · python
1#!/usr/bin/env python32 3import glob, os, shlex, sys, subprocess4 5 6device_id = os.environ.get("SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER")7iossim_run_verbose = os.environ.get("SANITIZER_IOSSIM_RUN_VERBOSE")8wait_for_debug = os.environ.get("SANITIZER_IOSSIM_RUN_WAIT_FOR_DEBUGGER")9 10if not device_id:11    raise EnvironmentError(12        "Specify SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER to select which simulator to use."13    )14 15for e in [16    "ASAN_OPTIONS",17    "TSAN_OPTIONS",18    "UBSAN_OPTIONS",19    "LSAN_OPTIONS",20    "APPLE_ASAN_INIT_FOR_DLOPEN",21    "ASAN_ACTIVATION_OPTIONS",22    "MallocNanoZone",23]:24    simctl_version = "SIMCTL_CHILD_" + e25    # iossim_env.py might have already set these using arguments it was given26    # (and that we can't see from inside this script). Don't overwrite them!27    if e in os.environ and simctl_version not in os.environ:28        os.environ[simctl_version] = os.environ[e]29 30find_atos_cmd = "xcrun -sdk iphonesimulator -f atos"31atos_path = (32    subprocess.run(33        find_atos_cmd.split(),34        stdout=subprocess.PIPE,35        stderr=subprocess.PIPE,36        check=True,37    )38    .stdout.decode()39    .strip()40)41for san in ["ASAN", "TSAN", "UBSAN", "LSAN"]:42    os.environ[f"SIMCTL_CHILD_{san}_SYMBOLIZER_PATH"] = atos_path43 44prog = sys.argv[1]45exit_code = None46if prog == "rm":47    # The simulator and host actually share the same file system so we can just48    # execute directly on the host.49    rm_args = []50    for arg in sys.argv[2:]:51        if "*" in arg or "?" in arg:52            # Don't quote glob pattern53            rm_args.append(arg)54        else:55            rm_args.append(shlex.quote(arg))56    rm_cmd_line = ["/bin/rm"] + rm_args57    rm_cmd_line_str = " ".join(rm_cmd_line)58    # We use `shell=True` so that any wildcard globs get expanded by the shell.59 60    if iossim_run_verbose:61        print("RUNNING: \t{}".format(rm_cmd_line_str), flush=True)62 63    exitcode = subprocess.call(rm_cmd_line_str, shell=True)64 65else:66    cmd = ["xcrun", "simctl", "spawn", "--standalone"]67 68    if wait_for_debug:69        cmd.append("--wait-for-debugger")70 71    cmd.append(device_id)72    cmd += sys.argv[1:]73 74    if iossim_run_verbose:75        print("RUNNING: \t{}".format(" ".join(cmd)), flush=True)76 77    exitcode = subprocess.call(cmd)78if exitcode > 125:79    exitcode = 12680sys.exit(exitcode)81