selftest: add on-disk SelfTestReport log; report PASS/FAIL details from steps

This commit is contained in:
2026-06-16 19:53:39 +02:00
parent 2c5c40524d
commit 7d2fd1ab65
2 changed files with 53 additions and 10 deletions
@@ -45,16 +45,20 @@ internal sealed class GlobalStyleScopeAllocStep : ISelfTestStep
GlobalStyleScope.Push(theme, registry, opacity).Dispose();
var delta = GC.GetAllocatedBytesForCurrentThread() - before;
if (delta > AllocBudgetBytes)
{
ImGui.Text(
$"GlobalStyleScope.Push allocated {delta} bytes/cycle "
+ $"(budget {AllocBudgetBytes}) — StackHandle is not GC-free."
);
return SelfTestStepResult.Fail;
}
return SelfTestStepResult.Pass;
// Report the measured figure on BOTH outcomes (Flo's request: don't just
// show Pass) — the byte delta is the whole point of the GC-reserve probe.
var ok = delta <= AllocBudgetBytes;
var status = ok ? "PASS" : "FAIL";
SelfTestReport.Append(
Name,
status,
new[] { $"Push/Dispose allocated {delta} bytes/cycle (budget {AllocBudgetBytes})" }
);
ImGui.Text(
$"GlobalStyleScope.Push allocated {delta} bytes/cycle "
+ $"(budget {AllocBudgetBytes}) — {status}."
);
return ok ? SelfTestStepResult.Pass : SelfTestStepResult.Fail;
}
public void CleanUp() { }
+39
View File
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
namespace HellionChat.SelfTests;
// Shared report sink so manual self-test steps leave a readable trace on disk,
// not just a green Pass that flashes by for a single frame. Each call appends a
// timestamped block to selftest-report.log in the plugin ConfigDirectory; the
// human reads the tail after running the self-test runner. Same idea as the B5
// perf-baseline.json (durable, copy-pasteable output) but as one shared append
// log so a full run leaves every reporting step's findings in one place.
// Append (not atomic tmp+move) is fine: the runner is single-threaded on the
// draw thread and a torn trailing line on a crash is acceptable for a debug log.
internal static class SelfTestReport
{
internal static string Append(string stepName, string status, IReadOnlyList<string> details)
{
var path = Path.Join(Plugin.Interface.ConfigDirectory.FullName, "selftest-report.log");
var stamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
var sb = new StringBuilder();
sb.Append("=== ")
.Append(stamp)
.Append(" | ")
.Append(stepName)
.Append(" | ")
.Append(status)
.Append(" ===\n");
foreach (var line in details)
sb.Append(" ").Append(line).Append('\n');
sb.Append('\n');
File.AppendAllText(path, sb.ToString());
return path;
}
}