()
| 10 | |
| 11 | |
| 12 | def main(): |
| 13 | collector, runner, suite, receipt, *arguments = sys.argv[1:] |
| 14 | original = subprocess.Popen |
| 15 | children = [] |
| 16 | |
| 17 | def nofile(): |
| 18 | resource.setrlimit(resource.RLIMIT_NOFILE, (7, 7)) |
| 19 | |
| 20 | def launch(args, *positional, **keywords): |
| 21 | selected = (isinstance(args, (list, tuple)) and len(args) == 2 |
| 22 | and os.fspath(args[0]) == runner and os.fspath(args[1]) == suite) |
| 23 | if selected: |
| 24 | if keywords.get("preexec_fn") is not None: |
| 25 | raise RuntimeError("native fault boundary already has a pre-exec callback") |
| 26 | keywords["preexec_fn"] = nofile |
| 27 | process = original(args, *positional, **keywords) |
| 28 | if selected: |
| 29 | children.append((process, {"pid": process.pid, "argv": list(args), |
| 30 | "rlimit_nofile": 7, |
| 31 | "start_new_session": keywords.get("start_new_session", False)})) |
| 32 | return process |
| 33 | |
| 34 | subprocess.Popen = launch |
| 35 | sys.path.insert(0, str(Path(collector).parent)) |
| 36 | sys.argv = [collector] + arguments |
| 37 | try: |
| 38 | runpy.run_path(collector, run_name="__main__") |
| 39 | finally: |
| 40 | rows = [] |
| 41 | for process, row in children: |
| 42 | row["exit"] = process.returncode |
| 43 | rows.append(row) |
| 44 | with open(receipt, "x", encoding="utf-8") as stream: |
| 45 | json.dump({"fault": "native_child_fixed_nofile_7", "children": rows}, stream, indent=2) |
| 46 | stream.write("\n") |
| 47 | |
| 48 | |
| 49 | if __name__ == "__main__": |
no test coverage detected