Skip to content

[lldb] Make sure that a Progress "completed" update is always repor… #9068

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
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions lldb/source/Core/Progress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ Progress::~Progress() {
// Make sure to always report progress completed when this object is
// destructed so it indicates the progress dialog/activity should go away.
std::lock_guard<std::mutex> guard(m_mutex);
if (!m_completed)
m_completed = m_total;
m_completed = m_total;
ReportProgress();

// Report to the ProgressManager if that subsystem is enabled.
Expand Down
75 changes: 75 additions & 0 deletions lldb/unittests/Core/ProgressReportTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,81 @@ TEST_F(ProgressReportTest, TestReportCreation) {
EXPECT_EQ(data->GetMessage(), "Progress report 1: Starting report 1");
}

TEST_F(ProgressReportTest, TestReportDestructionWithPartialProgress) {
ListenerSP listener_sp = CreateListenerFor(lldb::eBroadcastBitProgress);
EventSP event_sp;
const ProgressEventData *data;

// Create a finite progress report and only increment to a non-completed
// state before destruction.
{
Progress progress("Finite progress", "Report 1", 100);
progress.Increment(3);
}

// Verify that the progress in the events are:
// 1. At construction: 0 out of 100
// 2. At increment: 3 out of 100
// 3. At destruction: 100 out of 100
ASSERT_TRUE(listener_sp->GetEvent(event_sp, TIMEOUT));
data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
EXPECT_EQ(data->GetDetails(), "Report 1");
EXPECT_TRUE(data->IsFinite());
EXPECT_EQ(data->GetCompleted(), (uint64_t)0);
EXPECT_EQ(data->GetTotal(), (uint64_t)100);
EXPECT_EQ(data->GetMessage(), "Finite progress: Report 1");

ASSERT_TRUE(listener_sp->GetEvent(event_sp, TIMEOUT));
data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
EXPECT_EQ(data->GetDetails(), "Report 1");
EXPECT_TRUE(data->IsFinite());
EXPECT_EQ(data->GetCompleted(), (uint64_t)3);
EXPECT_EQ(data->GetTotal(), (uint64_t)100);
EXPECT_EQ(data->GetMessage(), "Finite progress: Report 1");

ASSERT_TRUE(listener_sp->GetEvent(event_sp, TIMEOUT));
data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
EXPECT_EQ(data->GetDetails(), "Report 1");
EXPECT_TRUE(data->IsFinite());
EXPECT_EQ(data->GetCompleted(), (uint64_t)100);
EXPECT_EQ(data->GetTotal(), (uint64_t)100);
EXPECT_EQ(data->GetMessage(), "Finite progress: Report 1");

// Create an infinite progress report and increment by some amount.
{
Progress progress("Infinite progress", "Report 2");
progress.Increment(3);
}

// Verify that the progress in the events are:
// 1. At construction: 0
// 2. At increment: 3
// 3. At destruction: Progress::kNonDeterministicTotal
ASSERT_TRUE(listener_sp->GetEvent(event_sp, TIMEOUT));
data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
EXPECT_EQ(data->GetDetails(), "Report 2");
EXPECT_FALSE(data->IsFinite());
EXPECT_EQ(data->GetCompleted(), (uint64_t)0);
EXPECT_EQ(data->GetTotal(), Progress::kNonDeterministicTotal);
EXPECT_EQ(data->GetMessage(), "Infinite progress: Report 2");

ASSERT_TRUE(listener_sp->GetEvent(event_sp, TIMEOUT));
data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
EXPECT_EQ(data->GetDetails(), "Report 2");
EXPECT_FALSE(data->IsFinite());
EXPECT_EQ(data->GetCompleted(), (uint64_t)3);
EXPECT_EQ(data->GetTotal(), Progress::kNonDeterministicTotal);
EXPECT_EQ(data->GetMessage(), "Infinite progress: Report 2");

ASSERT_TRUE(listener_sp->GetEvent(event_sp, TIMEOUT));
data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
EXPECT_EQ(data->GetDetails(), "Report 2");
EXPECT_FALSE(data->IsFinite());
EXPECT_EQ(data->GetCompleted(), Progress::kNonDeterministicTotal);
EXPECT_EQ(data->GetTotal(), Progress::kNonDeterministicTotal);
EXPECT_EQ(data->GetMessage(), "Infinite progress: Report 2");
}

TEST_F(ProgressReportTest, TestProgressManager) {
ListenerSP listener_sp =
CreateListenerFor(lldb::eBroadcastBitProgressCategory);
Expand Down