Skip to content
Snippets Groups Projects
Commit 078e5690 authored by Avi Kivity's avatar Avi Kivity
Browse files

tests: add test for wait_for(predicate)

parent 5bcb1d5c
No related branches found
No related tags found
No related merge requests found
...@@ -89,3 +89,33 @@ BOOST_AUTO_TEST_CASE(test_waitqueue_2) ...@@ -89,3 +89,33 @@ BOOST_AUTO_TEST_CASE(test_waitqueue_2)
waker.join(); waker.join();
} }
} }
BOOST_AUTO_TEST_CASE(test_wait_for_predicate)
{
std::atomic<bool> x = { false };
auto sleeper = sched::thread::current();
sched::thread waker([&] {
sched::thread::sleep_until(nanotime() + 1_s);
x.store(true);
sleeper->wake();
});
waker.start();
// send some spurious wakeups for fun
sched::thread false_waker([&] {
for (auto i = 0; i < 100; ++i) {
sched::thread::sleep_until(nanotime() + 100_ms);
sleeper->wake();
}
});
sched::timer tmr(*sched::thread::current());
tmr.set(nanotime() + 500_ms);
sched::thread::wait_for(tmr, [&] { return x.load(); });
BOOST_REQUIRE(tmr.expired());
BOOST_REQUIRE(!x.load());
tmr.cancel();
sched::thread::wait_for(tmr, [&] { return x.load(); });
BOOST_REQUIRE(!tmr.expired());
BOOST_REQUIRE(x.load());
waker.join();
false_waker.join();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment