diff options
| author | Jan Trencansky <jan.trencansky@protonmail.com> | 2026-11-25 18:18:55 -0500 |
|---|---|---|
| committer | Jan Trencansky <jan.trencansky@protonmail.com> | 2026-11-25 18:18:55 -0500 |
| commit | d4fb292344088e7925ddeb3bbceb5a9ac46de8c2 (patch) | |
| tree | 551a4e8b93953b3b481b3a30739ca73eb45615e8 /runtime/test/dev_overlay_test.cpp | |
| parent | 244387529b6fb4992b601704d32016e7beeadd28 (diff) | |
| parent | ffcfe68f12891826a2b15e19f31149d8bb44e778 (diff) | |
Merge main into rt-title-hud-vram-budget
Brings in #2137 (LEONIDA_DEV_OVERLAY), which the next commit extends.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/test/dev_overlay_test.cpp')
| -rw-r--r-- | runtime/test/dev_overlay_test.cpp | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/runtime/test/dev_overlay_test.cpp b/runtime/test/dev_overlay_test.cpp new file mode 100644 index 000000000..b366ec2ed --- /dev/null +++ b/runtime/test/dev_overlay_test.cpp | |||
| @@ -0,0 +1,98 @@ | |||
| 1 | // src/dev_overlay.h: the text of a sample, the counter differences, the phase bookkeeping behind its "now" line | ||
| 2 | // (submit_phases.h) and the pipeline builds in flight (dev_status.h). No window, GPU or game file. | ||
| 3 | #include "dev_overlay.h" | ||
| 4 | |||
| 5 | #include <cstdio> | ||
| 6 | #include <string> | ||
| 7 | #include <thread> | ||
| 8 | #include <vector> | ||
| 9 | |||
| 10 | #define CHECK(condition) do { \ | ||
| 11 | if (!(condition)) { \ | ||
| 12 | std::fprintf(stderr, "line %d: %s\n", __LINE__, #condition); \ | ||
| 13 | return 1; \ | ||
| 14 | } \ | ||
| 15 | } while (0) | ||
| 16 | |||
| 17 | namespace sp = leonida::submit_phases; | ||
| 18 | namespace dov = leonida::dev_overlay; | ||
| 19 | |||
| 20 | static bool has(const std::vector<std::string>& lines, const char* part) { | ||
| 21 | for (const auto& line : lines) | ||
| 22 | if (line.find(part) != std::string::npos) return true; | ||
| 23 | return false; | ||
| 24 | } | ||
| 25 | |||
| 26 | int main() { | ||
| 27 | // A total that went down was reset by its log line: what it holds is the new part. | ||
| 28 | std::uint64_t before = 0; | ||
| 29 | CHECK(dov::grown(10, before) == 10 && before == 10); | ||
| 30 | CHECK(dov::grown(25, before) == 15); | ||
| 31 | CHECK(dov::grown(4, before) == 4 && before == 4); | ||
| 32 | |||
| 33 | // Nested scopes: the inner one is running, then the outer one again, then none. | ||
| 34 | CHECK(sp::running().phase == -1); | ||
| 35 | { | ||
| 36 | const sp::Scope replay(sp::replay); | ||
| 37 | CHECK(sp::running().phase == sp::replay); | ||
| 38 | { | ||
| 39 | const sp::Scope textures(sp::textures); | ||
| 40 | CHECK(sp::running().phase == sp::textures); | ||
| 41 | } | ||
| 42 | CHECK(sp::running().phase == sp::replay); | ||
| 43 | } | ||
| 44 | CHECK(sp::running().phase == -1); | ||
| 45 | |||
| 46 | // Two threads whose scopes overlap and end in the order they began: no phase stays behind. | ||
| 47 | { | ||
| 48 | std::atomic<int> step{0}; | ||
| 49 | std::thread a([&] { | ||
| 50 | const sp::Scope heaps(sp::heaps); | ||
| 51 | step = 1; | ||
| 52 | while (step.load() < 2) std::this_thread::yield(); | ||
| 53 | }); | ||
| 54 | std::thread b([&] { | ||
| 55 | while (step.load() < 1) std::this_thread::yield(); | ||
| 56 | const sp::Scope shadows(sp::shadows); | ||
| 57 | step = 2; | ||
| 58 | while (step.load() < 3) std::this_thread::yield(); | ||
| 59 | }); | ||
| 60 | a.join(); | ||
| 61 | CHECK(sp::running().phase == sp::shadows); | ||
| 62 | step = 3; | ||
| 63 | b.join(); | ||
| 64 | CHECK(sp::running().phase == -1); | ||
| 65 | } | ||
| 66 | |||
| 67 | // The builds in flight and the last one's name, cut to its buffer. | ||
| 68 | auto& builds = leonida::dev_status::builds(); | ||
| 69 | const auto done = builds.done.load(); | ||
| 70 | { | ||
| 71 | const leonida::dev_status::Build one("one"); | ||
| 72 | const leonida::dev_status::Build two(std::string(500, 'x').c_str()); | ||
| 73 | CHECK(builds.active.load() == 2 && builds.last() == std::string(95, 'x')); | ||
| 74 | } | ||
| 75 | CHECK(builds.active.load() == 0 && builds.done.load() == done + 2); | ||
| 76 | |||
| 77 | dov::Sample s; | ||
| 78 | auto text = dov::lines(s, 12); | ||
| 79 | CHECK(text.size() == 6); | ||
| 80 | CHECK(has(text, "12 s") && has(text, "now: the title's own code") && has(text, "pipelines: 0 built")); | ||
| 81 | CHECK(!has(text, "building")); | ||
| 82 | s.frames = 8.44; | ||
| 83 | s.phase = sp::textures; | ||
| 84 | s.phase_for = 3.9; | ||
| 85 | s.phase_ms[sp::shadows] = 2; | ||
| 86 | s.phase_ms[sp::geometry] = 1.5; | ||
| 87 | s.building = 3; | ||
| 88 | s.built = 853; | ||
| 89 | s.build = std::string(200, 'n'); // longer than the line's part for it | ||
| 90 | s.drawn = 3029; | ||
| 91 | s.skipped = 38363; | ||
| 92 | text = dov::lines(s, 147); | ||
| 93 | CHECK(has(text, "8.4 fps") && has(text, "now: refreshing textures for 3 s") && has(text, "copies 3.5")); | ||
| 94 | CHECK(has(text, "853 built, 3 building (nnn") && has(text, "3029 drawn, 38363 skipped")); | ||
| 95 | for (const auto& line : text) CHECK(line.size() < 160); | ||
| 96 | std::puts("dev_overlay_test: ok"); | ||
| 97 | return 0; | ||
| 98 | } | ||