(check_program, result, timeout)
| 85 | |
| 86 | |
| 87 | def unsafe_execute(check_program, result, timeout): |
| 88 | |
| 89 | with create_tempdir(): |
| 90 | |
| 91 | # These system calls are needed when cleaning up tempdir. |
| 92 | import os |
| 93 | import shutil |
| 94 | |
| 95 | rmtree = shutil.rmtree |
| 96 | rmdir = os.rmdir |
| 97 | chdir = os.chdir |
| 98 | |
| 99 | # Disable functionalities that can make destructive changes to the test. |
| 100 | reliability_guard() |
| 101 | |
| 102 | # Run program. |
| 103 | try: |
| 104 | exec_globals = {} |
| 105 | with swallow_io(): |
| 106 | with time_limit(timeout): |
| 107 | exec(check_program, exec_globals) |
| 108 | result.append("passed") |
| 109 | except TimeoutException: |
| 110 | result.append("timed out") |
| 111 | except BaseException as e: |
| 112 | result.append(f"failed: {e}") |
| 113 | |
| 114 | # Needed for cleaning up. |
| 115 | shutil.rmtree = rmtree |
| 116 | os.rmdir = rmdir |
| 117 | os.chdir = chdir |
| 118 | |
| 119 | |
| 120 | @contextlib.contextmanager |
nothing calls this directly
no test coverage detected