()
| 59 | |
| 60 | |
| 61 | def main(): |
| 62 | parser = argparse.ArgumentParser(description=__doc__) |
| 63 | selection = parser.add_mutually_exclusive_group(required=True) |
| 64 | selection.add_argument('--build', action='store_true', |
| 65 | help='build offline/locked/release from fingerprinted source') |
| 66 | selection.add_argument('--binary', type=Path, |
| 67 | help='existing agent_sandbox_bench executable (build provenance not assumed)') |
| 68 | parser.add_argument('--output', required=True, type=Path, |
| 69 | help='new artifact directory; must not exist') |
| 70 | parser.add_argument('--profile', choices=PROFILES, default='many-files') |
| 71 | for name in ('files-east', 'files-west', 'lines', 'edits'): |
| 72 | parser.add_argument('--' + name, type=int) |
| 73 | parser.add_argument('--iterations', type=int, default=8) |
| 74 | parser.add_argument('--warmups', type=int, default=1) |
| 75 | parser.add_argument('--keep-fixtures', action='store_true') |
| 76 | parser.add_argument('--allow-debug', action='store_true', |
| 77 | help='correctness smoke only, not performance evidence') |
| 78 | args = parser.parse_args() |
| 79 | if args.iterations < 1 or args.warmups < 0: |
| 80 | parser.error('iterations must be positive and warmups nonnegative') |
| 81 | output = args.output.resolve() |
| 82 | output.mkdir(parents=True, exist_ok=False) |
| 83 | output.chmod(0o700) |
| 84 | source_before = source_fingerprint() |
| 85 | metadata = dict(outcome='incomplete', source_sha256=source_before, |
| 86 | source_binding='fingerprinted offline release build' if args.build |
| 87 | else 'caller-supplied binary; source/build association unverified', |
| 88 | platform=platform.platform(), logical_cpus=os.cpu_count(), |
| 89 | concurrency_control='OS cache and unrelated system load are not controlled') |
| 90 | try: |
| 91 | candidate = args.binary.resolve() if args.binary else None |
| 92 | if args.build: |
| 93 | command = ['cargo', 'build', '--release', '--offline', '--locked', '-p', 'libatomic', |
| 94 | '--example', 'agent_sandbox_bench', '--message-format=json-render-diagnostics'] |
| 95 | build_env = dict(os.environ, CARGO_NET_OFFLINE='true') |
| 96 | build_env.setdefault('CARGO_BUILD_JOBS', '2') |
| 97 | build_env.setdefault('CARGO_PROFILE_RELEASE_STRIP', 'none') |
| 98 | metadata['build_command'] = command |
| 99 | result = subprocess.run(command, cwd=ROOT, env=build_env, capture_output=True) |
| 100 | (output / 'build.stdout.jsonl').write_bytes(result.stdout) |
| 101 | (output / 'build.stderr.log').write_bytes(result.stderr) |
| 102 | result.check_returncode() |
| 103 | for line in result.stdout.splitlines(): |
| 104 | event = json.loads(line) |
| 105 | if event.get('reason') == 'compiler-artifact' and \ |
| 106 | event.get('target', {}).get('name') == 'agent_sandbox_bench' and \ |
| 107 | event.get('executable'): |
| 108 | candidate = Path(event['executable']) |
| 109 | if candidate is None: |
| 110 | raise RuntimeError('Cargo did not report the benchmark executable') |
| 111 | if source_fingerprint() != source_before: |
| 112 | raise RuntimeError('source changed during build; discard this candidate') |
| 113 | if candidate is None or not candidate.is_file(): |
| 114 | raise RuntimeError('benchmark executable not found') |
| 115 | binary = output / 'agent_sandbox_bench' |
| 116 | shutil.copy2(candidate, binary) |
| 117 | metadata['binary_sha256'] = digest(binary) |
| 118 | config = {name.replace('_', '-'): value |
no test coverage detected