Skip to content

Commit 10343b6

Browse files
committed
[lldb][progress][NFC] Add unit test for progress reports
This test is being added as a way to check the behaviour of how progress events are broadcasted when reports are started and ended with the current implementation of progress reports. Here we're mainly checking and ensuring that the current behaviour is that progress events are broadcasted individually and placed in the event queue in order of their creation.
1 parent 1d3300d commit 10343b6

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-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: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#include "Plugins/Platform/MacOSX/PlatformMacOSX.h"
2+
#include "Plugins/Platform/MacOSX/PlatformRemoteMacOSX.h"
3+
#include "lldb/Core/Debugger.h"
4+
#include "lldb/Core/Progress.h"
5+
#include "lldb/Host/FileSystem.h"
6+
#include "lldb/Host/HostInfo.h"
7+
#include "lldb/Utility/Listener.h"
8+
#include "gtest/gtest.h"
9+
#include <thread>
10+
11+
using namespace lldb;
12+
using namespace lldb_private;
13+
14+
namespace {
15+
class ProgressReportTest : public ::testing::Test {
16+
public:
17+
void SetUp() override {
18+
FileSystem::Initialize();
19+
HostInfo::Initialize();
20+
PlatformMacOSX::Initialize();
21+
Debugger::Initialize(nullptr);
22+
}
23+
void TearDown() override {
24+
Debugger::Terminate();
25+
PlatformMacOSX::Terminate();
26+
HostInfo::Terminate();
27+
FileSystem::Terminate();
28+
}
29+
};
30+
} // namespace
31+
TEST_F(ProgressReportTest, TestReportCreation) {
32+
std::chrono::milliseconds timeout(100);
33+
34+
// Set up the debugger, make sure that was done properly
35+
ArchSpec arch("x86_64-apple-macosx-");
36+
Platform::SetHostPlatform(PlatformRemoteMacOSX::CreateInstance(true, &arch));
37+
38+
DebuggerSP debugger_sp = Debugger::CreateInstance();
39+
ASSERT_TRUE(debugger_sp);
40+
41+
// Get the debugger's broadcaster
42+
Broadcaster &broadcaster = debugger_sp->GetBroadcaster();
43+
44+
// Create a listener, make sure it can receive events and that it's
45+
// listening to the correct broadcast bit
46+
ListenerSP listener_sp = Listener::MakeListener("progress-listener");
47+
48+
listener_sp->StartListeningForEvents(&broadcaster,
49+
Debugger::eBroadcastBitProgress);
50+
EXPECT_TRUE(
51+
broadcaster.EventTypeHasListeners(Debugger::eBroadcastBitProgress));
52+
53+
EventSP event_sp;
54+
const ProgressEventData *data;
55+
56+
// Scope this for RAII on the progress objects
57+
// Create progress reports and check that their respective events for having
58+
// started are broadcasted
59+
{
60+
Progress progress1("Progress report 1", "Starting report 1");
61+
EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout));
62+
63+
data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
64+
ASSERT_EQ(data->GetDetails(), "Starting report 1");
65+
66+
Progress progress2("Progress report 2", "Starting report 2");
67+
EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout));
68+
69+
data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
70+
ASSERT_EQ(data->GetDetails(), "Starting report 2");
71+
72+
Progress progress3("Progress report 3", "Starting report 3");
73+
EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout));
74+
ASSERT_TRUE(event_sp);
75+
76+
data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
77+
ASSERT_EQ(data->GetDetails(), "Starting report 3");
78+
79+
std::this_thread::sleep_for(timeout);
80+
}
81+
82+
// Progress report objects should be destroyed at this point so
83+
// get each report from the queue and check that they've been
84+
// destroyed in reverse order
85+
std::this_thread::sleep_for(timeout);
86+
EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout));
87+
data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
88+
89+
ASSERT_EQ(data->GetTitle(), "Progress report 3");
90+
ASSERT_TRUE(data->GetCompleted());
91+
92+
std::this_thread::sleep_for(timeout);
93+
EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout));
94+
data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
95+
96+
ASSERT_EQ(data->GetTitle(), "Progress report 2");
97+
ASSERT_TRUE(data->GetCompleted());
98+
99+
std::this_thread::sleep_for(timeout);
100+
EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout));
101+
data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
102+
103+
ASSERT_EQ(data->GetTitle(), "Progress report 1");
104+
ASSERT_TRUE(data->GetCompleted());
105+
}

0 commit comments

Comments
 (0)