aboutsummaryrefslogtreecommitdiff
path: root/lldb/unittests/Process/ProcessTraceTest.cpp
blob: fc6b92e8682484c56a0d9ef416328d5b21c10928 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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);
}