Debian Codegraph @

compiler-rt/test/sanitizer_common/ios_commands/iossim_run.py

raw
1 #!/usr/bin/env python3
2
3 import glob, os, shlex, sys, subprocess
4
5
6 device_id = os.environ.get("SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER")
7 iossim_run_verbose = os.environ.get("SANITIZER_IOSSIM_RUN_VERBOSE")
8 wait_for_debug = os.environ.get("SANITIZER_IOSSIM_RUN_WAIT_FOR_DEBUGGER")
9
10 if not device_id:
11 raise EnvironmentError(
12 "Specify SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER to select which simulator to use."
13 )
14
15 for 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_" + e
25 # iossim_env.py might have already set these using arguments it was given
26 # (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
30 find_atos_cmd = "xcrun -sdk iphonesimulator -f atos"
31 atos_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 )
41 for san in ["ASAN", "TSAN", "UBSAN", "LSAN"]:
42 os.environ[f"SIMCTL_CHILD_{san}_SYMBOLIZER_PATH"] = atos_path
43
44 prog = sys.argv[1]
45 exit_code = None
46 if prog == "rm":
47 # The simulator and host actually share the same file system so we can just
48 # 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 pattern
53 rm_args.append(arg)
54 else:
55 rm_args.append(shlex.quote(arg))
56 rm_cmd_line = ["/bin/rm"] + rm_args
57 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
65 else:
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)
78 if exitcode > 125:
79 exitcode = 126
80 sys.exit(exitcode)