xref: /llvm-project/compiler-rt/test/sanitizer_common/ios_commands/iossim_run.py (revision fb310c0af9f366454c61a4be18dc5aa791d23d0a)
1#!/usr/bin/python
2
3import glob, os, pipes, sys, subprocess
4
5
6if not "SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER" in os.environ:
7  raise EnvironmentError("Specify SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER to select which simulator to use.")
8
9device_id = os.environ["SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER"]
10
11for e in ["ASAN_OPTIONS", "TSAN_OPTIONS", "UBSAN_OPTIONS"]:
12  if e in os.environ:
13    os.environ["SIMCTL_CHILD_" + e] = os.environ[e]
14
15prog = sys.argv[1]
16exit_code = None
17if prog == 'rm':
18  # The simulator and host actually share the same file system so we can just
19  # execute directly on the host.
20  rm_args = []
21  for arg in sys.argv[2:]:
22    if '*' in arg or '?' in arg:
23      # Don't quote glob pattern
24      rm_args.append(arg)
25    else:
26      # FIXME(dliew): pipes.quote() is deprecated
27      rm_args.append(pipes.quote(arg))
28  rm_cmd_line = ["/bin/rm"] + rm_args
29  rm_cmd_line_str = ' '.join(rm_cmd_line)
30  # We use `shell=True` so that any wildcard globs get expanded by the shell.
31  exitcode = subprocess.call(rm_cmd_line_str, shell=True)
32else:
33  exitcode = subprocess.call(["xcrun", "simctl", "spawn", device_id] + sys.argv[1:])
34if exitcode > 125:
35  exitcode = 126
36sys.exit(exitcode)
37