test: record measured callback fuel in budget reports
Co-Authored-By: Codex <noreply@openai.com>
This commit is contained in:
+20
-2
@@ -161,6 +161,16 @@ BUDGET_SCENARIO = "tests/budgets/wasm_flat_budget.toml"
|
||||
BUDGET_ASSERTED_SHA256 = "bcc0359289ab20ab3de608bcc130f72d2cf88f9f6fbc470d7b6846e9db5d11df"
|
||||
|
||||
|
||||
def fuel_measurements(output):
|
||||
"""Read the pinned host's callback counters; never infer them from source caps."""
|
||||
samples = []
|
||||
for mod_id, callback, calls, maximum, budget, failures in re.findall(
|
||||
r"(?m)^fuel (\S+) (\S+): calls=(\d+) max=(\d+) budget=(\d+) failures=(\d+)\s*$", output):
|
||||
samples.append({"mod": mod_id, "callback": callback, "calls": int(calls),
|
||||
"max_used": int(maximum), "budget": int(budget), "failures": int(failures)})
|
||||
return samples
|
||||
|
||||
|
||||
def test_budgets():
|
||||
"""Run the opt-in heavy scenario and always write a machine-readable report."""
|
||||
report_path = Path(os.environ.get("AIRDEF_BUDGET_REPORT") or
|
||||
@@ -178,7 +188,9 @@ def test_budgets():
|
||||
"accepted_raids_asserted": None, "snapshot_airborne_asserted": None,
|
||||
"snapshot_tick": None, "peak_airborne_observed": None},
|
||||
"runtime_limits": {"source": "horizon/crates/horizon-mods/src/runtime.rs",
|
||||
"metering": "source_configured; measured_per_scenario: unavailable"},
|
||||
"metering": "source_configured"},
|
||||
"measured_fuel": {"available": False, "callbacks": [],
|
||||
"scope": "guest callback fuel; excludes host CPU, memory and GPU time"},
|
||||
}
|
||||
|
||||
def git(*args, text=True):
|
||||
@@ -253,7 +265,8 @@ def test_budgets():
|
||||
(isolated / "tests").mkdir()
|
||||
(isolated / "tests" / "wasm_budget.toml").write_bytes(fixture_bytes)
|
||||
command = [cargo(), "run", "--locked", "--manifest-path", FORK / "Cargo.toml",
|
||||
"-p", "cargo-horizon-mod", "--", "horizon-mod", "test", "--hmod", artifact, "budget"]
|
||||
"-p", "cargo-horizon-mod", "--", "horizon-mod", "test", "--hmod", artifact,
|
||||
"--fuel-profile", "budget"]
|
||||
print("+", " ".join(str(c) for c in command), flush=True)
|
||||
result = subprocess.run([str(c) for c in command], cwd=isolated, env=build_env,
|
||||
text=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
@@ -261,6 +274,11 @@ def test_budgets():
|
||||
report["exit_code"] = result.returncode
|
||||
report["status"] = "passed" if result.returncode == 0 else "failed"
|
||||
report["output"] = result.stdout[-12000:]
|
||||
samples = fuel_measurements(result.stdout)
|
||||
report["measured_fuel"].update({"available": bool(samples), "callbacks": samples})
|
||||
if result.returncode == 0 and not samples:
|
||||
report["status"] = "failed"
|
||||
raise RuntimeError("pinned runtime did not return requested callback fuel counters")
|
||||
# These assertions belong to this exact fixture, not to arbitrary edited scripts.
|
||||
if result.returncode == 0 and report["scenario_sha256"] == BUDGET_ASSERTED_SHA256:
|
||||
counts["accepted_raids_asserted"] = 2
|
||||
|
||||
Reference in New Issue
Block a user