Skip to content

[🍒 stable/20240723] [lldb] Fix synchronization in AlarmTest (NFC) #9617

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lldb/unittests/Host/AlarmTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ TEST(AlarmTest, Create) {
// Leave plenty of time for all the alarms to fire.
std::this_thread::sleep_for(TEST_TIMEOUT);

// Acquire the lock to check the callbacks.
std::lock_guard<std::mutex> guard(m);

// Make sure all the alarms fired around the expected time.
for (size_t i = 0; i < 5; ++i)
EXPECT_GE(callbacks_actual[i], callbacks_expected[i]);
Expand Down Expand Up @@ -83,6 +86,9 @@ TEST(AlarmTest, Exit) {
// Let the alarm go out of scope before any alarm had a chance to fire.
}

// Acquire the lock to check the callbacks.
std::lock_guard<std::mutex> guard(m);

// Make sure none of the alarms fired.
for (bool callback : callbacks)
EXPECT_TRUE(callback);
Expand Down Expand Up @@ -113,6 +119,9 @@ TEST(AlarmTest, Cancel) {
// Leave plenty of time for all the alarms to fire.
std::this_thread::sleep_for(TEST_TIMEOUT);

// Acquire the lock to check the callbacks.
std::lock_guard<std::mutex> guard(m);

// Make sure none of the first 4 alarms fired.
for (size_t i = 0; i < 4; ++i)
EXPECT_FALSE(callbacks[i]);
Expand Down Expand Up @@ -146,13 +155,17 @@ TEST(AlarmTest, Restart) {

// Update the last 2 alarms.
for (size_t i = 3; i < 5; ++i) {
std::lock_guard<std::mutex> guard(m);
callbacks_expected[i] = std::chrono::system_clock::now() + ALARM_TIMEOUT;
EXPECT_TRUE(alarm.Restart(handles[i]));
}

// Leave plenty of time for all the alarms to fire.
std::this_thread::sleep_for(TEST_TIMEOUT);

// Acquire the lock to check the callbacks.
std::lock_guard<std::mutex> guard(m);

// Make sure all the alarms around the expected time.
for (size_t i = 0; i < 5; ++i)
EXPECT_GE(callbacks_actual[i], callbacks_expected[i]);
Expand Down