From e0f34b97fb015faea0112c70727f4a17747f9e4b Mon Sep 17 00:00:00 2001 From: Joel Linn Date: Tue, 1 Mar 2022 23:41:57 +0100 Subject: [PATCH] [Base] Check for correct thread in HResTimer tests --- src/xenia/base/testing/threading_test.cc | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/xenia/base/testing/threading_test.cc b/src/xenia/base/testing/threading_test.cc index 94d8ec11c..3a8b119c1 100644 --- a/src/xenia/base/testing/threading_test.cc +++ b/src/xenia/base/testing/threading_test.cc @@ -180,12 +180,21 @@ TEST_CASE("HighResolutionTimer") { // Smaller values are not as precise and fail the test const auto wait_time = 500ms; + const Thread* timer_thread = nullptr; + // Time the actual sleep duration { const auto interval = 50ms; std::atomic counter(0); auto start = std::chrono::steady_clock::now(); - auto cb = [&counter] { ++counter; }; + auto cb = [&counter, &timer_thread] { + if (counter == 0) { + timer_thread = Thread::GetCurrentThread(); + } else { + REQUIRE(Thread::GetCurrentThread() == timer_thread); + } + ++counter; + }; auto pTimer = HighResolutionTimer::CreateRepeating(interval, cb); Sleep(wait_time); pTimer.reset(); @@ -206,8 +215,14 @@ TEST_CASE("HighResolutionTimer") { std::atomic counter1(0); std::atomic counter2(0); auto start = std::chrono::steady_clock::now(); - auto cb1 = [&counter1] { ++counter1; }; - auto cb2 = [&counter2] { ++counter2; }; + auto cb1 = [&counter1, timer_thread] { + ++counter1; + REQUIRE(Thread::GetCurrentThread() == timer_thread); + }; + auto cb2 = [&counter2, timer_thread] { + ++counter2; + REQUIRE(Thread::GetCurrentThread() == timer_thread); + }; auto pTimer1 = HighResolutionTimer::CreateRepeating(interval1, cb1); auto pTimer2 = HighResolutionTimer::CreateRepeating(interval2, cb2); Sleep(wait_time);