Skip to content

Commit debc9d6

Browse files
chelcassanovaCarlos Gálvez
authored and
Carlos Gálvez
committed
Reland "[lldb][progress][NFC] Add unit test for progress reports (llvm#79533)"
This reverts commit 209fe1f. The original commit failed to due an assertion failure in the unit test `ProgressReportTest` that the commit added. The Debugger::Initialize() function was called more than once which triggered the assertion, so this commit calls that function under a `std::call_once`.
1 parent bd380c9 commit debc9d6

File tree

2 files changed

+128
-0
lines changed

2 files changed

+128
-0
lines changed

lldb/unittests/Core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ add_lldb_unittest(LLDBCoreTests
77
FormatEntityTest.cpp
88
MangledTest.cpp
99
ModuleSpecTest.cpp
10+
ProgressReportTest.cpp
1011
RichManglingContextTest.cpp
1112
SourceLocationSpecTest.cpp
1213
SourceManagerTest.cpp
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
//===-- ProgressReportTest.cpp --------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "Plugins/Platform/MacOSX/PlatformMacOSX.h"
10+
#include "Plugins/Platform/MacOSX/PlatformRemoteMacOSX.h"
11+
#include "TestingSupport/SubsystemRAII.h"
12+
#include "lldb/Core/Debugger.h"
13+
#include "lldb/Core/Progress.h"
14+
#include "lldb/Host/FileSystem.h"
15+
#include "lldb/Host/HostInfo.h"
16+
#include "lldb/Utility/Listener.h"
17+
#include "gtest/gtest.h"
18+
#include <mutex>
19+
20+
using namespace lldb;
21+
using namespace lldb_private;
22+
23+
static std::once_flag debugger_initialize_flag;
24+
class ProgressReportTest : public ::testing::Test {
25+
SubsystemRAII<FileSystem, HostInfo, PlatformMacOSX> subsystems;
26+
27+
// The debugger's initialization function can't be called with no arguments
28+
// so calling it using SubsystemRAII will cause the test build to fail as
29+
// SubsystemRAII will call Initialize with no arguments. As such we set it up
30+
// here the usual way.
31+
void SetUp() override {
32+
std::call_once(debugger_initialize_flag,
33+
[]() { Debugger::Initialize(nullptr); });
34+
};
35+
};
36+
37+
TEST_F(ProgressReportTest, TestReportCreation) {
38+
std::chrono::milliseconds timeout(100);
39+
40+
// Set up the debugger, make sure that was done properly.
41+
ArchSpec arch("x86_64-apple-macosx-");
42+
Platform::SetHostPlatform(PlatformRemoteMacOSX::CreateInstance(true, &arch));
43+
44+
DebuggerSP debugger_sp = Debugger::CreateInstance();
45+
ASSERT_TRUE(debugger_sp);
46+
47+
// Get the debugger's broadcaster.
48+
Broadcaster &broadcaster = debugger_sp->GetBroadcaster();
49+
50+
// Create a listener, make sure it can receive events and that it's
51+
// listening to the correct broadcast bit.
52+
ListenerSP listener_sp = Listener::MakeListener("progress-listener");
53+
54+
listener_sp->StartListeningForEvents(&broadcaster,
55+
Debugger::eBroadcastBitProgress);
56+
EXPECT_TRUE(
57+
broadcaster.EventTypeHasListeners(Debugger::eBroadcastBitProgress));
58+
59+
EventSP event_sp;
60+
const ProgressEventData *data;
61+
62+
// Scope this for RAII on the progress objects.
63+
// Create progress reports and check that their respective events for having
64+
// started and ended are broadcasted.
65+
{
66+
Progress progress1("Progress report 1", "Starting report 1");
67+
Progress progress2("Progress report 2", "Starting report 2");
68+
Progress progress3("Progress report 3", "Starting report 3");
69+
}
70+
71+
// Start popping events from the queue, they should have been recevied
72+
// in this order:
73+
// Starting progress: 1, 2, 3
74+
// Ending progress: 3, 2, 1
75+
EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout));
76+
data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
77+
78+
ASSERT_EQ(data->GetDetails(), "Starting report 1");
79+
ASSERT_FALSE(data->IsFinite());
80+
ASSERT_FALSE(data->GetCompleted());
81+
ASSERT_EQ(data->GetTotal(), Progress::kNonDeterministicTotal);
82+
ASSERT_EQ(data->GetMessage(), "Progress report 1: Starting report 1");
83+
84+
EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout));
85+
data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
86+
87+
ASSERT_EQ(data->GetDetails(), "Starting report 2");
88+
ASSERT_FALSE(data->IsFinite());
89+
ASSERT_FALSE(data->GetCompleted());
90+
ASSERT_EQ(data->GetTotal(), Progress::kNonDeterministicTotal);
91+
ASSERT_EQ(data->GetMessage(), "Progress report 2: Starting report 2");
92+
93+
EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout));
94+
data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
95+
ASSERT_EQ(data->GetDetails(), "Starting report 3");
96+
ASSERT_FALSE(data->IsFinite());
97+
ASSERT_FALSE(data->GetCompleted());
98+
ASSERT_EQ(data->GetTotal(), Progress::kNonDeterministicTotal);
99+
ASSERT_EQ(data->GetMessage(), "Progress report 3: Starting report 3");
100+
101+
// Progress report objects should be destroyed at this point so
102+
// get each report from the queue and check that they've been
103+
// destroyed in reverse order.
104+
EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout));
105+
data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
106+
107+
ASSERT_EQ(data->GetTitle(), "Progress report 3");
108+
ASSERT_TRUE(data->GetCompleted());
109+
ASSERT_FALSE(data->IsFinite());
110+
ASSERT_EQ(data->GetMessage(), "Progress report 3: Starting report 3");
111+
112+
EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout));
113+
data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
114+
115+
ASSERT_EQ(data->GetTitle(), "Progress report 2");
116+
ASSERT_TRUE(data->GetCompleted());
117+
ASSERT_FALSE(data->IsFinite());
118+
ASSERT_EQ(data->GetMessage(), "Progress report 2: Starting report 2");
119+
120+
EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout));
121+
data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
122+
123+
ASSERT_EQ(data->GetTitle(), "Progress report 1");
124+
ASSERT_TRUE(data->GetCompleted());
125+
ASSERT_FALSE(data->IsFinite());
126+
ASSERT_EQ(data->GetMessage(), "Progress report 1: Starting report 1");
127+
}

0 commit comments

Comments
 (0)