Skip to content

[lldb] Fix intel trace plugin tests #133826

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 2 commits into from
Apr 1, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ def wrapper(*args, **kwargs):
return wrapper


def skipIfNoIntelPT(func):
"""Skip tests if the system does not support tracing."""

supported = os.path.exists("/sys/bus/event_source/devices/intel_pt/type")
return unittest.skipIf(not supported, "intel-pt tracing is unsupported")(func)


# Class that should be used by all python Intel PT tests.
#
# It has a handy check that skips the test if the intel-pt plugin is not enabled.
Expand Down
3 changes: 2 additions & 1 deletion lldb/source/Target/ProcessTrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ ProcessSP ProcessTrace::CreateInstance(TargetSP target_sp,
bool can_connect) {
if (can_connect)
return nullptr;
return std::make_shared<ProcessTrace>(target_sp, listener_sp, *crash_file);
return std::make_shared<ProcessTrace>(target_sp, listener_sp,
crash_file ? *crash_file : FileSpec());
}

bool ProcessTrace::CanDebug(TargetSP target_sp, bool plugin_specified_by_name) {
Expand Down
2 changes: 2 additions & 0 deletions lldb/test/API/commands/trace/TestTraceDumpFunctionCalls.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def testFunctionCallsWithErrors(self):
],
)

@skipIfNoIntelPT
def testInlineFunctionCalls(self):
self.expect(
"file " + os.path.join(self.getSourceDir(), "inline-function", "a.out")
Expand Down Expand Up @@ -194,6 +195,7 @@ def testInlineFunctionCalls(self):
],
)

@skipIfNoIntelPT
def testIncompleteInlineFunctionCalls(self):
self.expect(
"file " + os.path.join(self.getSourceDir(), "inline-function", "a.out")
Expand Down
1 change: 1 addition & 0 deletions lldb/test/API/commands/trace/TestTraceEvents.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def testCPUEvents(self):
],
)

@skipIfNoIntelPT
@testSBAPIAndCommands
def testPauseEvents(self):
"""
Expand Down
2 changes: 2 additions & 0 deletions lldb/test/API/commands/trace/TestTraceSave.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def testErrorMessages(self):
"trace save", substrs=["error: Process is not being traced"], error=True
)

@skipIfNoIntelPT
def testSaveToInvalidDir(self):
self.expect(
"target create "
Expand Down Expand Up @@ -165,6 +166,7 @@ def checkSessionBundle(session_file_path):
copied_cpu = find(lambda cor: cor["id"] == cpu["id"], copy["cpus"])
self.assertIsNotNone(copied_cpu)

@skipIfNoIntelPT
def testSaveTrace(self):
self.expect(
"target create "
Expand Down
1 change: 1 addition & 0 deletions lldb/test/API/commands/trace/TestTraceStartStop.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from lldbsuite.test.decorators import *


@skipIfNoIntelPT
class TestTraceStartStop(TraceIntelPTTestCaseBase):
def expectGenericHelpMessageForStartCommand(self):
self.expect(
Expand Down
1 change: 1 addition & 0 deletions lldb/test/API/commands/trace/TestTraceTSC.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from lldbsuite.test.decorators import *


@skipIfNoIntelPT
class TestTraceTimestampCounters(TraceIntelPTTestCaseBase):
@testSBAPIAndCommands
@skipIf(oslist=no_match(["linux"]), archs=no_match(["i386", "x86_64"]))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from lldbsuite.test.decorators import *


@skipIfNoIntelPT
class TestTraceStartStopMultipleThreads(TraceIntelPTTestCaseBase):
@skipIf(oslist=no_match(["linux"]), archs=no_match(["i386", "x86_64"]))
@testSBAPIAndCommands
Expand Down
4 changes: 3 additions & 1 deletion lldb/unittests/Process/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ endif()
add_subdirectory(Utility)
add_subdirectory(minidump)

add_lldb_unittest(ProcessEventDataTests
add_lldb_unittest(ProcessTests
ProcessEventDataTest.cpp
ProcessTraceTest.cpp

LINK_LIBS
lldbCore
Expand All @@ -18,5 +19,6 @@ add_lldb_unittest(ProcessEventDataTests
lldbUtility
lldbUtilityHelpers
lldbInterpreter
lldbPluginPlatformLinux
lldbPluginPlatformMacOSX
)
63 changes: 63 additions & 0 deletions lldb/unittests/Process/ProcessTraceTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//===-- ProcessEventDataTest.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 "lldb/Target/ProcessTrace.h"
#include "Plugins/Platform/Linux/PlatformLinux.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Host/HostInfo.h"
#include "gtest/gtest.h"

using namespace lldb_private;
using namespace lldb;
using namespace platform_linux;

// This is needed for the tests that create a trace process.
class ProcessTraceTest : public ::testing::Test {
public:
void SetUp() override {
ProcessTrace::Initialize();
FileSystem::Initialize();
HostInfo::Initialize();
PlatformLinux::Initialize();
}
void TearDown() override {
PlatformLinux::Initialize();
HostInfo::Terminate();
FileSystem::Terminate();
ProcessTrace::Terminate();
}
};

TargetSP CreateTarget(DebuggerSP &debugger_sp, const ArchSpec &arch) {
PlatformSP platform_sp;
TargetSP target_sp;
debugger_sp->GetTargetList().CreateTarget(
*debugger_sp, "", arch, eLoadDependentsNo, platform_sp, target_sp);
return target_sp;
}

// Test that we can create a process trace with a nullptr core file.
TEST_F(ProcessTraceTest, ConstructorWithNullptrCoreFile) {
ArchSpec arch("i386-pc-linux");

Platform::SetHostPlatform(PlatformLinux::CreateInstance(true, &arch));
ASSERT_NE(Platform::GetHostPlatform(), nullptr);

DebuggerSP debugger_sp = Debugger::CreateInstance();
ASSERT_TRUE(debugger_sp);

TargetSP target_sp = CreateTarget(debugger_sp, arch);
ASSERT_TRUE(target_sp);

ProcessSP process_sp = target_sp->CreateProcess(
/*listener*/ nullptr, "trace",
/*crash_file*/ nullptr,
/*can_connect*/ false);

ASSERT_NE(process_sp, nullptr);
}
Loading