From 4b49e581351923e224693d1b38dc69a82dbd841e Mon Sep 17 00:00:00 2001 From: fiestorra Date: Mon, 30 Nov 2026 12:39:51 +0100 Subject: [PATCH 1/2] display_white_cache: accept that the first get() may already have the value it woke The test asserted that the first get() returns 0.0f, but get() is what wakes the worker to read, and value_.load() runs after the wake: on a loaded host the read lands before the load and the assertion fails. Replaced with the part that does not race - the value is either the fallback or the fresh read - and kept the reads() transition checks that pin the wake-up itself. --- runtime/test/display_white_cache_test.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/runtime/test/display_white_cache_test.cpp b/runtime/test/display_white_cache_test.cpp index f8105b3196..fd9e5ee85d 100644 --- a/runtime/test/display_white_cache_test.cpp +++ b/runtime/test/display_white_cache_test.cpp @@ -38,7 +38,12 @@ int main() { leonida::DisplayWhiteCache cache([&] { return windows.load(); }, std::chrono::hours(1)); std::this_thread::sleep_for(20ms); // the worker is in its wait by now ok &= check(cache.reads() == 0, "nothing is read before the first HDR10 present asks"); - ok &= check(cache.get() == 0.0f, "the first get() has no value yet (the caller falls back to 203)"); + // The first get() is what wakes the worker, so by the time it returns the read may already have + // landed: scheduling decides whether value_ is still empty. Accept both outcomes and assert the + // part that does not race - that it never returns anything but "no value" or the fresh read. + const float first = cache.get(); + ok &= check(first == 0.0f || first == 240.0f, + "the first get() returns no value yet, or the value it woke the worker to read"); ok &= check(within(2s, [&] { return cache.reads() == 1; }), "the first get() wakes the worker to read now"); ok &= check(within(2s, [&] { return cache.get() == 240.0f; }), "and the value it read is cached"); windows = 300.0f; From 6859ae5edd1ee4981d4c1282f6af7a1094bd5f69 Mon Sep 17 00:00:00 2001 From: fiestorra Date: Mon, 30 Nov 2026 15:36:50 +0100 Subject: [PATCH 2/2] display_white_cache: indent the new assertions with the block they belong to The four lines went in at four spaces while the block they sit in is at eight, and the body of the pull request showed them correctly, so the diff and the description disagreed. Whitespace only: the text, the numbers and the behaviour are unchanged, and the test still exits 0. --- runtime/test/display_white_cache_test.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/runtime/test/display_white_cache_test.cpp b/runtime/test/display_white_cache_test.cpp index fd9e5ee85d..8741f5d9b9 100644 --- a/runtime/test/display_white_cache_test.cpp +++ b/runtime/test/display_white_cache_test.cpp @@ -39,11 +39,11 @@ int main() { std::this_thread::sleep_for(20ms); // the worker is in its wait by now ok &= check(cache.reads() == 0, "nothing is read before the first HDR10 present asks"); // The first get() is what wakes the worker, so by the time it returns the read may already have - // landed: scheduling decides whether value_ is still empty. Accept both outcomes and assert the - // part that does not race - that it never returns anything but "no value" or the fresh read. - const float first = cache.get(); - ok &= check(first == 0.0f || first == 240.0f, - "the first get() returns no value yet, or the value it woke the worker to read"); + // landed: scheduling decides whether value_ is still empty. Accept both outcomes and assert the + // part that does not race - that it never returns anything but "no value" or the fresh read. + const float first = cache.get(); + ok &= check(first == 0.0f || first == 240.0f, + "the first get() returns no value yet, or the value it woke the worker to read"); ok &= check(within(2s, [&] { return cache.reads() == 1; }), "the first get() wakes the worker to read now"); ok &= check(within(2s, [&] { return cache.get() == 240.0f; }), "and the value it read is cached"); windows = 300.0f;