| 1 | //===-- ProcessEventDataTest.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 "lldb/Target/ProcessTrace.h" |
| 10 | #include "Plugins/Platform/Linux/PlatformLinux.h" |
| 11 | #include "lldb/Core/Debugger.h" |
| 12 | #include "lldb/Host/HostInfo.h" |
| 13 | #include "gtest/gtest.h" |
| 14 | |
| 15 | using namespace lldb_private; |
| 16 | using namespace lldb; |
| 17 | using namespace platform_linux; |
| 18 | |
| 19 | // This is needed for the tests that create a trace process. |
| 20 | class ProcessTraceTest : public ::testing::Test { |
| 21 | public: |
| 22 | void SetUp() override { |
| 23 | ProcessTrace::Initialize(); |
| 24 | FileSystem::Initialize(); |
| 25 | HostInfo::Initialize(); |
| 26 | PlatformLinux::Initialize(); |
| 27 | } |
| 28 | void TearDown() override { |
| 29 | PlatformLinux::Initialize(); |
| 30 | HostInfo::Terminate(); |
| 31 | FileSystem::Terminate(); |
| 32 | ProcessTrace::Terminate(); |
| 33 | } |
| 34 | }; |
| 35 | |
| 36 | TargetSP CreateTarget(DebuggerSP &debugger_sp, const ArchSpec &arch) { |
| 37 | PlatformSP platform_sp; |
| 38 | TargetSP target_sp; |
| 39 | debugger_sp->GetTargetList().CreateTarget( |
| 40 | debugger&: *debugger_sp, user_exe_path: "" , arch, get_dependent_modules: eLoadDependentsNo, platform_sp, target_sp); |
| 41 | return target_sp; |
| 42 | } |
| 43 | |
| 44 | // Test that we can create a process trace with a nullptr core file. |
| 45 | TEST_F(ProcessTraceTest, ConstructorWithNullptrCoreFile) { |
| 46 | ArchSpec arch("i386-pc-linux" ); |
| 47 | |
| 48 | Platform::SetHostPlatform(PlatformLinux::CreateInstance(force: true, arch: &arch)); |
| 49 | ASSERT_NE(Platform::GetHostPlatform(), nullptr); |
| 50 | |
| 51 | DebuggerSP debugger_sp = Debugger::CreateInstance(); |
| 52 | ASSERT_TRUE(debugger_sp); |
| 53 | |
| 54 | TargetSP target_sp = CreateTarget(debugger_sp, arch); |
| 55 | ASSERT_TRUE(target_sp); |
| 56 | |
| 57 | ProcessSP process_sp = target_sp->CreateProcess( |
| 58 | /*listener*/ listener_sp: nullptr, plugin_name: "trace" , |
| 59 | /*crash_file*/ nullptr, |
| 60 | /*can_connect*/ false); |
| 61 | |
| 62 | ASSERT_NE(process_sp, nullptr); |
| 63 | } |
| 64 | |