Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / sanitizer_common / ios_commands / iossim_run.py
blob5e977ea5ed908378bec9d9fd0c9f782a71b94999
1 #!/usr/bin/env python3
3 import glob, os, pipes, sys, subprocess
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")
10 if not device_id:
11 raise EnvironmentError(
12 "Specify SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER to select which simulator to use."
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",
24 if e in os.environ:
25 os.environ["SIMCTL_CHILD_" + e] = os.environ[e]
27 find_atos_cmd = "xcrun -sdk iphonesimulator -f atos"
28 atos_path = (
29 subprocess.run(
30 find_atos_cmd.split(),
31 stdout=subprocess.PIPE,
32 stderr=subprocess.PIPE,
33 check=True,
35 .stdout.decode()
36 .strip()
38 for san in ["ASAN", "TSAN", "UBSAN", "LSAN"]:
39 os.environ[f"SIMCTL_CHILD_{san}_SYMBOLIZER_PATH"] = atos_path
41 prog = sys.argv[1]
42 exit_code = None
43 if prog == "rm":
44 # The simulator and host actually share the same file system so we can just
45 # execute directly on the host.
46 rm_args = []
47 for arg in sys.argv[2:]:
48 if "*" in arg or "?" in arg:
49 # Don't quote glob pattern
50 rm_args.append(arg)
51 else:
52 # FIXME(dliew): pipes.quote() is deprecated
53 rm_args.append(pipes.quote(arg))
54 rm_cmd_line = ["/bin/rm"] + rm_args
55 rm_cmd_line_str = " ".join(rm_cmd_line)
56 # We use `shell=True` so that any wildcard globs get expanded by the shell.
58 if iossim_run_verbose:
59 print("RUNNING: \t{}".format(rm_cmd_line_str), flush=True)
61 exitcode = subprocess.call(rm_cmd_line_str, shell=True)
63 else:
64 cmd = ["xcrun", "simctl", "spawn", "--standalone"]
66 if wait_for_debug:
67 cmd.append("--wait-for-debugger")
69 cmd.append(device_id)
70 cmd += sys.argv[1:]
72 if iossim_run_verbose:
73 print("RUNNING: \t{}".format(" ".join(cmd)), flush=True)
75 exitcode = subprocess.call(cmd)
76 if exitcode > 125:
77 exitcode = 126
78 sys.exit(exitcode)