-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[lldb][progress][NFC] Add unit test for progress reports #79533
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
Show all changes
4 commits
Select commit
Hold shift + click to select a range
10343b6
[lldb][progress][NFC] Add unit test for progress reports
chelcassanova 9843ff7
Simplify set up, remove timeouts, add license
chelcassanova bb71954
Check all events outside of scope, use correct check for total
chelcassanova f3f2d84
Use static var to check progress total
chelcassanova File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
//===-- ProgressReportTest.cpp --------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "Plugins/Platform/MacOSX/PlatformMacOSX.h" | ||
#include "Plugins/Platform/MacOSX/PlatformRemoteMacOSX.h" | ||
#include "TestingSupport/SubsystemRAII.h" | ||
#include "lldb/Core/Debugger.h" | ||
#include "lldb/Core/Progress.h" | ||
#include "lldb/Host/FileSystem.h" | ||
#include "lldb/Host/HostInfo.h" | ||
#include "lldb/Utility/Listener.h" | ||
#include "gtest/gtest.h" | ||
#include <thread> | ||
|
||
using namespace lldb; | ||
using namespace lldb_private; | ||
|
||
class ProgressReportTest : public ::testing::Test { | ||
SubsystemRAII<FileSystem, HostInfo, PlatformMacOSX> subsystems; | ||
|
||
// The debugger's initialization function can't be called with no arguments | ||
// so calling it using SubsystemRAII will cause the test build to fail as | ||
// SubsystemRAII will call Initialize with no arguments. As such we set it up | ||
// here the usual way. | ||
void SetUp() override { Debugger::Initialize(nullptr); } | ||
void TearDown() override { Debugger::Terminate(); } | ||
}; | ||
|
||
TEST_F(ProgressReportTest, TestReportCreation) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: missing newline |
||
std::chrono::milliseconds timeout(100); | ||
|
||
// Set up the debugger, make sure that was done properly. | ||
ArchSpec arch("x86_64-apple-macosx-"); | ||
Platform::SetHostPlatform(PlatformRemoteMacOSX::CreateInstance(true, &arch)); | ||
|
||
DebuggerSP debugger_sp = Debugger::CreateInstance(); | ||
ASSERT_TRUE(debugger_sp); | ||
|
||
// Get the debugger's broadcaster. | ||
Broadcaster &broadcaster = debugger_sp->GetBroadcaster(); | ||
|
||
// Create a listener, make sure it can receive events and that it's | ||
// listening to the correct broadcast bit. | ||
ListenerSP listener_sp = Listener::MakeListener("progress-listener"); | ||
|
||
listener_sp->StartListeningForEvents(&broadcaster, | ||
Debugger::eBroadcastBitProgress); | ||
EXPECT_TRUE( | ||
broadcaster.EventTypeHasListeners(Debugger::eBroadcastBitProgress)); | ||
|
||
EventSP event_sp; | ||
const ProgressEventData *data; | ||
|
||
// Scope this for RAII on the progress objects. | ||
// Create progress reports and check that their respective events for having | ||
// started and ended are broadcasted. | ||
{ | ||
Progress progress1("Progress report 1", "Starting report 1"); | ||
Progress progress2("Progress report 2", "Starting report 2"); | ||
Progress progress3("Progress report 3", "Starting report 3"); | ||
} | ||
|
||
// Start popping events from the queue, they should have been recevied | ||
// in this order: | ||
// Starting progress: 1, 2, 3 | ||
// Ending progress: 3, 2, 1 | ||
EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout)); | ||
data = ProgressEventData::GetEventDataFromEvent(event_sp.get()); | ||
|
||
ASSERT_EQ(data->GetDetails(), "Starting report 1"); | ||
ASSERT_FALSE(data->IsFinite()); | ||
ASSERT_FALSE(data->GetCompleted()); | ||
ASSERT_EQ(data->GetTotal(), Progress::kNonDeterministicTotal); | ||
ASSERT_EQ(data->GetMessage(), "Progress report 1: Starting report 1"); | ||
|
||
EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout)); | ||
data = ProgressEventData::GetEventDataFromEvent(event_sp.get()); | ||
|
||
ASSERT_EQ(data->GetDetails(), "Starting report 2"); | ||
ASSERT_FALSE(data->IsFinite()); | ||
ASSERT_FALSE(data->GetCompleted()); | ||
ASSERT_EQ(data->GetTotal(), Progress::kNonDeterministicTotal); | ||
ASSERT_EQ(data->GetMessage(), "Progress report 2: Starting report 2"); | ||
|
||
EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout)); | ||
data = ProgressEventData::GetEventDataFromEvent(event_sp.get()); | ||
ASSERT_EQ(data->GetDetails(), "Starting report 3"); | ||
ASSERT_FALSE(data->IsFinite()); | ||
ASSERT_FALSE(data->GetCompleted()); | ||
ASSERT_EQ(data->GetTotal(), Progress::kNonDeterministicTotal); | ||
ASSERT_EQ(data->GetMessage(), "Progress report 3: Starting report 3"); | ||
|
||
// Progress report objects should be destroyed at this point so | ||
// get each report from the queue and check that they've been | ||
// destroyed in reverse order. | ||
EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout)); | ||
data = ProgressEventData::GetEventDataFromEvent(event_sp.get()); | ||
|
||
ASSERT_EQ(data->GetTitle(), "Progress report 3"); | ||
ASSERT_TRUE(data->GetCompleted()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a few more tests for each complete event
|
||
ASSERT_FALSE(data->IsFinite()); | ||
ASSERT_EQ(data->GetMessage(), "Progress report 3: Starting report 3"); | ||
|
||
EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout)); | ||
data = ProgressEventData::GetEventDataFromEvent(event_sp.get()); | ||
|
||
ASSERT_EQ(data->GetTitle(), "Progress report 2"); | ||
ASSERT_TRUE(data->GetCompleted()); | ||
ASSERT_FALSE(data->IsFinite()); | ||
ASSERT_EQ(data->GetMessage(), "Progress report 2: Starting report 2"); | ||
|
||
EXPECT_TRUE(listener_sp->GetEvent(event_sp, timeout)); | ||
data = ProgressEventData::GetEventDataFromEvent(event_sp.get()); | ||
|
||
ASSERT_EQ(data->GetTitle(), "Progress report 1"); | ||
ASSERT_TRUE(data->GetCompleted()); | ||
ASSERT_FALSE(data->IsFinite()); | ||
ASSERT_EQ(data->GetMessage(), "Progress report 1: Starting report 1"); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget to include the license header in this file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do! I told myself I'd add it at the end then I fully forgot to do that 🙃