1a3e1b111SJulian Lettner#!/usr/bin/env python3 2132c829eSKuba Mracek 3fb310c0aSDan Liewimport glob, os, pipes, sys, subprocess 4132c829eSKuba Mracek 5132c829eSKuba Mracek 6*f98ee40fSTobias Hietadevice_id = os.environ.get("SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER") 7*f98ee40fSTobias Hietaiossim_run_verbose = os.environ.get("SANITIZER_IOSSIM_RUN_VERBOSE") 8*f98ee40fSTobias Hietawait_for_debug = os.environ.get("SANITIZER_IOSSIM_RUN_WAIT_FOR_DEBUGGER") 9d71fc323SEmily Shi 10cdb45605SJulian Lettnerif not device_id: 11*f98ee40fSTobias Hieta raise EnvironmentError( 12*f98ee40fSTobias Hieta "Specify SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER to select which simulator to use." 13*f98ee40fSTobias Hieta ) 14132c829eSKuba Mracek 15df1c3aaaSEmily Shifor e in [ 16df1c3aaaSEmily Shi "ASAN_OPTIONS", 17df1c3aaaSEmily Shi "TSAN_OPTIONS", 18df1c3aaaSEmily Shi "UBSAN_OPTIONS", 19ebd8eee6SJulian Lettner "LSAN_OPTIONS", 20df1c3aaaSEmily Shi "APPLE_ASAN_INIT_FOR_DLOPEN", 21df1c3aaaSEmily Shi "ASAN_ACTIVATION_OPTIONS", 22df1c3aaaSEmily Shi "MallocNanoZone", 23df1c3aaaSEmily Shi]: 2491f3fa5fSKuba Mracek if e in os.environ: 2591f3fa5fSKuba Mracek os.environ["SIMCTL_CHILD_" + e] = os.environ[e] 26132c829eSKuba Mracek 27*f98ee40fSTobias Hietafind_atos_cmd = "xcrun -sdk iphonesimulator -f atos" 28*f98ee40fSTobias Hietaatos_path = ( 29*f98ee40fSTobias Hieta subprocess.run( 30*f98ee40fSTobias Hieta find_atos_cmd.split(), 31*f98ee40fSTobias Hieta stdout=subprocess.PIPE, 32*f98ee40fSTobias Hieta stderr=subprocess.PIPE, 33*f98ee40fSTobias Hieta check=True, 34*f98ee40fSTobias Hieta ) 35*f98ee40fSTobias Hieta .stdout.decode() 36*f98ee40fSTobias Hieta .strip() 37*f98ee40fSTobias Hieta) 38*f98ee40fSTobias Hietafor san in ["ASAN", "TSAN", "UBSAN", "LSAN"]: 39*f98ee40fSTobias Hieta os.environ[f"SIMCTL_CHILD_{san}_SYMBOLIZER_PATH"] = atos_path 40361bb473SJulian Lettner 41fb310c0aSDan Liewprog = sys.argv[1] 42fb310c0aSDan Liewexit_code = None 43*f98ee40fSTobias Hietaif prog == "rm": 44fb310c0aSDan Liew # The simulator and host actually share the same file system so we can just 45fb310c0aSDan Liew # execute directly on the host. 46fb310c0aSDan Liew rm_args = [] 47fb310c0aSDan Liew for arg in sys.argv[2:]: 48*f98ee40fSTobias Hieta if "*" in arg or "?" in arg: 49fb310c0aSDan Liew # Don't quote glob pattern 50fb310c0aSDan Liew rm_args.append(arg) 51fb310c0aSDan Liew else: 52fb310c0aSDan Liew # FIXME(dliew): pipes.quote() is deprecated 53fb310c0aSDan Liew rm_args.append(pipes.quote(arg)) 54fb310c0aSDan Liew rm_cmd_line = ["/bin/rm"] + rm_args 55*f98ee40fSTobias Hieta rm_cmd_line_str = " ".join(rm_cmd_line) 56fb310c0aSDan Liew # We use `shell=True` so that any wildcard globs get expanded by the shell. 57d71fc323SEmily Shi 58d71fc323SEmily Shi if iossim_run_verbose: 59ebd8eee6SJulian Lettner print("RUNNING: \t{}".format(rm_cmd_line_str), flush=True) 60d71fc323SEmily Shi 61fb310c0aSDan Liew exitcode = subprocess.call(rm_cmd_line_str, shell=True) 62d71fc323SEmily Shi 63fb310c0aSDan Liewelse: 64d71fc323SEmily Shi cmd = ["xcrun", "simctl", "spawn", "--standalone"] 65d71fc323SEmily Shi 66d71fc323SEmily Shi if wait_for_debug: 67d71fc323SEmily Shi cmd.append("--wait-for-debugger") 68d71fc323SEmily Shi 69d71fc323SEmily Shi cmd.append(device_id) 70d71fc323SEmily Shi cmd += sys.argv[1:] 71d71fc323SEmily Shi 72d71fc323SEmily Shi if iossim_run_verbose: 73ebd8eee6SJulian Lettner print("RUNNING: \t{}".format(" ".join(cmd)), flush=True) 74d71fc323SEmily Shi 75d71fc323SEmily Shi exitcode = subprocess.call(cmd) 76132c829eSKuba Mracekif exitcode > 125: 77132c829eSKuba Mracek exitcode = 126 78132c829eSKuba Mraceksys.exit(exitcode) 79