|
| 1 | +#!/usr/bin/env python3 |
| 2 | +"""校验单个 SDK 的分支测试和串行并发压测结果。""" |
| 3 | + |
| 4 | +import argparse |
| 5 | +import csv |
| 6 | +from pathlib import Path |
| 7 | + |
| 8 | + |
| 9 | +CONCURRENCY_LEVELS = {"100", "300", "500", "800", "1000"} |
| 10 | +WORKLOADS = {"http", "sse"} |
| 11 | +BRANCHES = {"feature/1.0.x", "feature/2.0.x", "feature/3.0.x"} |
| 12 | + |
| 13 | + |
| 14 | +def parse_args(): |
| 15 | + parser = argparse.ArgumentParser() |
| 16 | + parser.add_argument("--sdk", required=True) |
| 17 | + parser.add_argument("--results", required=True) |
| 18 | + parser.add_argument("--branches", required=True) |
| 19 | + return parser.parse_args() |
| 20 | + |
| 21 | + |
| 22 | +def read_rows(path, delimiter=","): |
| 23 | + target = Path(path) |
| 24 | + if not target.is_file(): |
| 25 | + raise SystemExit(f"FAIL missing result file: {target}") |
| 26 | + with target.open(newline="", encoding="utf-8") as handle: |
| 27 | + return list(csv.DictReader(handle, delimiter=delimiter)) |
| 28 | + |
| 29 | + |
| 30 | +def verify_branches(sdk, path): |
| 31 | + rows = read_rows(path, "\t") |
| 32 | + expected = {(sdk, branch) for branch in BRANCHES} |
| 33 | + actual = { |
| 34 | + (row.get("sdk"), row.get("branch")) |
| 35 | + for row in rows |
| 36 | + if row.get("status") == "PASS" |
| 37 | + } |
| 38 | + if len(rows) != 3 or actual != expected: |
| 39 | + raise SystemExit("FAIL branch verification must contain exactly 3 passing rows") |
| 40 | + |
| 41 | + |
| 42 | +def verify_benchmarks(sdk, path): |
| 43 | + rows = read_rows(path) |
| 44 | + expected = { |
| 45 | + (sdk, workload, concurrency) |
| 46 | + for workload in WORKLOADS |
| 47 | + for concurrency in CONCURRENCY_LEVELS |
| 48 | + } |
| 49 | + actual = { |
| 50 | + (row.get("sdk"), row.get("workload"), row.get("concurrency")) |
| 51 | + for row in rows |
| 52 | + } |
| 53 | + if len(rows) != 10 or actual != expected: |
| 54 | + raise SystemExit("FAIL benchmark results must contain exactly 10 unique runs") |
| 55 | + |
| 56 | + intervals = [] |
| 57 | + for row in rows: |
| 58 | + if row.get("status") != "PASS" or int(row.get("errors", "-1")) != 0: |
| 59 | + raise SystemExit(f"FAIL benchmark errors: {row}") |
| 60 | + if float(row.get("avg_cpu_pct", "-1")) < 0: |
| 61 | + raise SystemExit(f"FAIL invalid average CPU: {row}") |
| 62 | + if float(row.get("peak_cpu_pct", "0")) <= 0: |
| 63 | + raise SystemExit(f"FAIL invalid peak CPU: {row}") |
| 64 | + if float(row.get("peak_rss_mb", "0")) <= 0: |
| 65 | + raise SystemExit(f"FAIL invalid peak RSS: {row}") |
| 66 | + if float(row.get("throughput_per_sec", "0")) <= 0: |
| 67 | + raise SystemExit(f"FAIL invalid throughput: {row}") |
| 68 | + start = int(row["started_epoch_ms"]) |
| 69 | + end = int(row["ended_epoch_ms"]) |
| 70 | + if end <= start: |
| 71 | + raise SystemExit(f"FAIL invalid interval: {row}") |
| 72 | + intervals.append((start, end, row)) |
| 73 | + |
| 74 | + intervals.sort(key=lambda value: value[0]) |
| 75 | + for previous, current in zip(intervals, intervals[1:]): |
| 76 | + if current[0] < previous[1]: |
| 77 | + raise SystemExit( |
| 78 | + f"FAIL overlapping benchmark runs: {previous[2]} and {current[2]}" |
| 79 | + ) |
| 80 | + |
| 81 | + |
| 82 | +def main(): |
| 83 | + args = parse_args() |
| 84 | + verify_branches(args.sdk, args.branches) |
| 85 | + verify_benchmarks(args.sdk, args.results) |
| 86 | + print(f"{args.sdk.upper()}_BENCHMARK_RESULTS_PASS") |
| 87 | + |
| 88 | + |
| 89 | +if __name__ == "__main__": |
| 90 | + main() |
0 commit comments