(
ref_code_with_contract: str,
entry_point: str,
generator_code: str,
timeout_second: float = PERF_CURATE_TIMEOUT_SECOND + 1,
)
| 78 | # 2. whether the generator stops in a well-defined manner |
| 79 | # -- if False, we might want to try another generator |
| 80 | def sample_one_input( |
| 81 | ref_code_with_contract: str, |
| 82 | entry_point: str, |
| 83 | generator_code: str, |
| 84 | timeout_second: float = PERF_CURATE_TIMEOUT_SECOND + 1, |
| 85 | ) -> Tuple[List[Any], bool]: |
| 86 | # These system calls are needed when cleaning up tempdir. |
| 87 | import os |
| 88 | import shutil |
| 89 | |
| 90 | rmtree = shutil.rmtree |
| 91 | rmdir = os.rmdir |
| 92 | chdir = os.chdir |
| 93 | # Disable functionalities that can make destructive changes to the test. |
| 94 | # :imit memory usages. |
| 95 | maximum_memory_bytes = PERF_RAM_GB_PER_PROC * 1024 * 1024 * 1024 |
| 96 | reliability_guard(maximum_memory_bytes=maximum_memory_bytes) |
| 97 | exec_globals = {} |
| 98 | |
| 99 | # eval the func def with contract |
| 100 | exec(ref_code_with_contract, exec_globals) |
| 101 | fn = exec_globals[entry_point] |
| 102 | |
| 103 | # eval the generator |
| 104 | generator_code = "from typing import *\n" + generator_code |
| 105 | try: |
| 106 | exec(generator_code, exec_globals) |
| 107 | generator = exec_globals["perf_input_gen"] |
| 108 | except Exception: |
| 109 | print(colored(f"⚠️ [GEN EVAL] Exception ~ {entry_point}:", "red")) |
| 110 | print(colored(format_exc(), "red")) |
| 111 | return [], False |
| 112 | |
| 113 | well_defined_exit = True |
| 114 | return_inputs = [] |
| 115 | |
| 116 | for fac in range(1, 27): |
| 117 | scale = 2**fac |
| 118 | print(f"[INPUT GEN] scale=2**{fac}") |
| 119 | try: |
| 120 | with time_limit(timeout_second): |
| 121 | test_input = generator(scale) |
| 122 | if not isinstance(test_input, tuple): |
| 123 | test_input = (test_input,) |
| 124 | # integers should stay in the range of 64-bit |
| 125 | if any( |
| 126 | isinstance(arg, int) and not (-(2**63) <= arg < 2**63) |
| 127 | for arg in test_input |
| 128 | ): |
| 129 | print(colored(f"[INPUT GEN] Int overflow against 64bit", "yellow")) |
| 130 | break |
| 131 | # hack list integer |
| 132 | if isinstance(test_input[0], list) and any( |
| 133 | not (-(2**63) <= v < 2**63) |
| 134 | for v in test_input[0] |
| 135 | if isinstance(v, int) |
| 136 | ): |
| 137 | print(colored(f"[INPUT GEN] Int overflow against 64bit", "yellow")) |
nothing calls this directly
no test coverage detected