Files
airdef/tools/test_raid_bench.py
T
chexit c08b737296
build / mod (push) Failing after 32s
Reproducible raid/replay render bench and #147 instancing measurements
tools/raid_bench.py (+ tests): the #147 step-0 driver replaces the #126
scratch script. One battle at fixed ticks (waves inside resident terrain —
far waves stall at the unknown-chunk edge and no fight happens), fingerprint
chat lines at control ticks, then the raid's own recording replayed. Both
render paths are benched on the SAME recording in ONE process via the
engine's diagnostic `model-instancing off|on` toggle (cross-process battles
diverge in event timing: 16 vs 32 kills at one control tick), pairs in
alternating order; idle cold/warm, mid-battle window, reload (F3+T), replay
seek, away-camera checks, and static off/on stills for pixel parity
(hd_bench motion-mask methodology). report.json carries gitlinks, device,
mod_models counters, CPU/GPU p50/p95/p99/max, raw frame times, >25/33 ms
frame counts, guest fuel and streaming queues.

Engine gitlink: one mass mod-model group GPU-instanced (retained mesh per
pack generation, current/previous pose/id/light instance stream shared by
main, motion and shadow passes, per-vertex fallback to parity, runtime
diagnostic toggle, stats raw + guest fuel reporting).

Measurements: docs/measurements/issue-147-instancing/ (M5/Metal, 2560x1440;
RTX 3060 pending). docs/REPO-MAP.md and docs/ENGINE.md pin updated.

Co-Authored-By: Kimi Code <noreply@moonshot.ai>
2026-11-21 11:39:43 +03:00

68 lines
2.9 KiB
Python

"""Тесты драйвера raid_bench (#147): перцентили как в FrameStats, худшие кадры,
расписание боя и разбор отпечатка. Запуск: python3 -m unittest tools/test_raid_bench.py."""
import sys
import unittest
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent))
import raid_bench as rb # noqa: E402
class Percentiles(unittest.TestCase):
def test_ceil_index_like_frame_stats(self):
# FrameStats::summary: sorted[ceil(n*p).clamp(1, n) - 1].
v = [float(i) for i in range(1, 101)] # 1..100
self.assertEqual(rb.percentile(v, 0.5), 50.0)
self.assertEqual(rb.percentile(v, 0.95), 95.0)
self.assertEqual(rb.percentile(v, 0.99), 99.0)
self.assertEqual(rb.percentile(v, 1.0), 100.0)
def test_small_and_empty(self):
self.assertIsNone(rb.percentile([], 0.95))
self.assertEqual(rb.percentile([7.0], 0.99), 7.0)
self.assertEqual(rb.percentile([3.0, 1.0, 2.0], 0.5), 2.0)
# ceil(2*0.95)=2 -> второй из двух.
self.assertEqual(rb.percentile([1.0, 9.0], 0.95), 9.0)
def test_unsorted_input(self):
self.assertEqual(rb.percentile([9.0, 1.0, 5.0], 0.5), 5.0)
class FrameSummary(unittest.TestCase):
def test_worst_frame_counts(self):
raw = {"frame_ms": [10.0, 25.0, 25.1, 33.0, 33.4, 100.0],
"cpu_ms": [5.0, 20.0], "gpu_ms": []}
s = rb.frame_summary(raw)
self.assertEqual(s["frames_over_25ms"], 4) # строго больше 25
self.assertEqual(s["frames_over_33ms"], 2) # строго больше 33
self.assertEqual(s["frame_ms"]["max_ms"], 100.0)
self.assertEqual(s["frame_ms"]["p99_ms"], 100.0)
self.assertEqual(s["gpu_ms"]["n"], 0)
self.assertIsNone(s["gpu_ms"]["p95_ms"])
def test_empty(self):
s = rb.frame_summary({})
self.assertEqual(s["frames_over_25ms"], 0)
self.assertIsNone(s["cpu_ms"]["avg_ms"])
class Battle(unittest.TestCase):
def test_schedule_is_ordered_and_early(self):
ticks = [t for t, _ in rb.BATTLE_SCHEDULE]
self.assertEqual(ticks, sorted(ticks))
self.assertLess(ticks[-1], rb.FINGERPRINT_TICKS[0])
self.assertLess(rb.FINGERPRINT_TICKS[-1], rb.BATTLE_END)
def test_fingerprint_regex_reads_the_stats_line(self):
line = ("В воздухе: 40, ракет: 12, ПВО: 14, сбито: 3, поражений: 1, "
"разбились о препятствия: 0; удары по ПУ: пущено 0, уничтожено 0, "
"подавлено 0, промахов 0, сбито ПВО 0; мир: Polygon")
m = rb.STATS_RE.search(line)
self.assertIsNotNone(m)
self.assertEqual(m.groups(), ("40", "12", "14", "3", "1"))
self.assertIsNone(rb.STATS_RE.search("ВОЗДУШНАЯ ТРЕВОГА"))
if __name__ == "__main__":
unittest.main()