(check_program, result, timeout)
| 54 | |
| 55 | |
| 56 | def unsafe_execute(check_program, result, timeout): |
| 57 | |
| 58 | with create_tempdir(): |
| 59 | |
| 60 | # These system calls are needed when cleaning up tempdir. |
| 61 | import os |
| 62 | import shutil |
| 63 | |
| 64 | rmtree = shutil.rmtree |
| 65 | rmdir = os.rmdir |
| 66 | chdir = os.chdir |
| 67 | |
| 68 | # Disable functionalities that can make destructive changes to the test. |
| 69 | reliability_guard() |
| 70 | |
| 71 | # Run program. |
| 72 | try: |
| 73 | exec_globals = {} |
| 74 | with swallow_io(): |
| 75 | with time_limit(timeout): |
| 76 | exec(check_program, exec_globals) |
| 77 | result.append("passed") |
| 78 | except TimeoutException: |
| 79 | result.append("timed out") |
| 80 | except BaseException as e: |
| 81 | result.append(f"failed: {e}") |
| 82 | |
| 83 | # Needed for cleaning up. |
| 84 | shutil.rmtree = rmtree |
| 85 | os.rmdir = rmdir |
| 86 | os.chdir = chdir |
| 87 | |
| 88 | |
| 89 | @contextlib.contextmanager |
nothing calls this directly
no test coverage detected
searching dependent graphs…