Skip to content

Commit 51e0d1b

Browse files
[lldb][progress][NFC] Add unit test for progress reports (#79533)
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 and deletion.
1 parent 4cb13f2 commit 51e0d1b

File tree

2 files changed

+125
-0
lines changed

2 files changed

+125
-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: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
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 <thread>
19+
20+
using namespace lldb;
21+
using namespace lldb_private;
22+
23+
class ProgressReportTest : public ::testing::Test {
24+
SubsystemRAII<FileSystem, HostInfo, PlatformMacOSX> subsystems;
25+
26+
// The debugger's initialization function can't be called with no arguments
27+
// so calling it using SubsystemRAII will cause the test build to fail as
28+
// SubsystemRAII will call Initialize with no arguments. As such we set it up
29+
// here the usual way.
30+
void SetUp() override { Debugger::Initialize(nullptr); }
31+
void TearDown() override { Debugger::Terminate(); }
32+
};
33+
34+
TEST_F(ProgressReportTest, TestReportCreation) {
35+
std::chrono::milliseconds timeout(100);
36+
37+
// Set up the debugger, make sure that was done properly.
38+
ArchSpec arch("x86_64-apple-macosx-");
39+
Platform::SetHostPlatform(PlatformRemoteMacOSX::CreateInstance(true, &arch));
40+
41+
DebuggerSP debugger_sp = Debugger::CreateInstance();
42+
ASSERT_TRUE(debugger_sp);
43+
44+
// Get the debugger's broadcaster.
45+
Broadcaster &broadcaster = debugger_sp->GetBroadcaster();
46+
47+
// Create a listener, make sure it can receive events and that it's
48+
// listening to the correct broadcast bit.
49+
ListenerSP listener_sp = Listener::MakeListener("progress-listener");
50+
51+
listener_sp->StartListeningForEvents(&broadcaster,
52+
Debugger::eBroadcastBitProgress);
53+
EXPECT_TRUE(
54+
broadcaster.EventTypeHasListeners(Debugger::eBroadcastBitProgress));
55+
56+
EventSP event_sp;
57+
const ProgressEventData *data;
58+
59+
// Scope this for RAII on the progress objects.
60+
// Create progress reports and check that their respective events for having
61+
// started and ended are broadcasted.
62+
{
63+
Progress progress1("Progress report 1", "Starting report 1");
64+
Progress progress2("Progress report 2", "Starting report 2");
65+
Progress progress3("Progress report 3", "Starting report 3");
66+
}
67+
68+
// Start popping events from the queue, they should have been recevied
69+
// in this order:
70+
// Starting progress: 1, 2, 3
71+
// Ending progress: 3, 2, 1
72+
EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout));
73+
data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
74+
75+
ASSERT_EQ(data->GetDetails(), "Starting report 1");
76+
ASSERT_FALSE(data->IsFinite());
77+
ASSERT_FALSE(data->GetCompleted());
78+
ASSERT_EQ(data->GetTotal(), Progress::kNonDeterministicTotal);
79+
ASSERT_EQ(data->GetMessage(), "Progress report 1: Starting report 1");
80+
81+
EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout));
82+
data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
83+
84+
ASSERT_EQ(data->GetDetails(), "Starting report 2");
85+
ASSERT_FALSE(data->IsFinite());
86+
ASSERT_FALSE(data->GetCompleted());
87+
ASSERT_EQ(data->GetTotal(), Progress::kNonDeterministicTotal);
88+
ASSERT_EQ(data->GetMessage(), "Progress report 2: Starting report 2");
89+
90+
EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout));
91+
data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
92+
ASSERT_EQ(data->GetDetails(), "Starting report 3");
93+
ASSERT_FALSE(data->IsFinite());
94+
ASSERT_FALSE(data->GetCompleted());
95+
ASSERT_EQ(data->GetTotal(), Progress::kNonDeterministicTotal);
96+
ASSERT_EQ(data->GetMessage(), "Progress report 3: Starting report 3");
97+
98+
// Progress report objects should be destroyed at this point so
99+
// get each report from the queue and check that they've been
100+
// destroyed in reverse order.
101+
EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout));
102+
data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
103+
104+
ASSERT_EQ(data->GetTitle(), "Progress report 3");
105+
ASSERT_TRUE(data->GetCompleted());
106+
ASSERT_FALSE(data->IsFinite());
107+
ASSERT_EQ(data->GetMessage(), "Progress report 3: Starting report 3");
108+
109+
EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout));
110+
data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
111+
112+
ASSERT_EQ(data->GetTitle(), "Progress report 2");
113+
ASSERT_TRUE(data->GetCompleted());
114+
ASSERT_FALSE(data->IsFinite());
115+
ASSERT_EQ(data->GetMessage(), "Progress report 2: Starting report 2");
116+
117+
EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout));
118+
data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
119+
120+
ASSERT_EQ(data->GetTitle(), "Progress report 1");
121+
ASSERT_TRUE(data->GetCompleted());
122+
ASSERT_FALSE(data->IsFinite());
123+
ASSERT_EQ(data->GetMessage(), "Progress report 1: Starting report 1");
124+
}

0 commit comments

Comments
 (0)