"""Synthetic tool used only by the opt-in SDK fault suite. No device/network I/O.""" import json import os from pathlib import Path import subprocess import sys import time def main(): mode = sys.argv[1] if mode == "sleep": time.sleep(60) elif mode == "tree": child = subprocess.Popen( [sys.executable, "-I", "-B", __file__, "sleep"], stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, creationflags=subprocess.CREATE_NO_WINDOW if os.name == "nt" else 0, ) Path(sys.argv[2]).write_text(json.dumps({"pid": child.pid}), encoding="utf-8") if sys.argv[3] == "linger": time.sleep(60) elif mode == "echo": data = sys.stdin.buffer.read() sys.stdout.buffer.write(data) sys.stderr.buffer.write(b"synthetic-stderr") elif mode == "overflow": while True: os.write(1, b"x" * 65536) elif mode == "failure": raise SystemExit(7) else: raise SystemExit(2) if __name__ == "__main__": main()