| 
8 | 8 | 
 
  | 
9 | 9 | #include "TestBase.h"  | 
10 | 10 | #include "Protocol/ProtocolBase.h"  | 
 | 11 | +#include "TestingSupport/TestUtilities.h"  | 
 | 12 | +#include "lldb/API/SBDefines.h"  | 
 | 13 | +#include "lldb/API/SBStructuredData.h"  | 
11 | 14 | #include "lldb/Host/File.h"  | 
12 | 15 | #include "lldb/Host/Pipe.h"  | 
 | 16 | +#include "lldb/lldb-forward.h"  | 
 | 17 | +#include "llvm/ADT/StringRef.h"  | 
13 | 18 | #include "llvm/Testing/Support/Error.h"  | 
 | 19 | +#include "gtest/gtest.h"  | 
 | 20 | +#include <memory>  | 
14 | 21 | 
 
  | 
15 | 22 | using namespace llvm;  | 
16 | 23 | using namespace lldb;  | 
@@ -55,6 +62,62 @@ void DAPTestBase::SetUp() {  | 
55 | 62 |       /*transport=*/*to_dap);  | 
56 | 63 | }  | 
57 | 64 | 
 
  | 
 | 65 | +void DAPTestBase::TearDown() {  | 
 | 66 | +  if (core)  | 
 | 67 | +    ASSERT_THAT_ERROR(core->discard(), Succeeded());  | 
 | 68 | +  if (binary)  | 
 | 69 | +    ASSERT_THAT_ERROR(binary->discard(), Succeeded());  | 
 | 70 | +}  | 
 | 71 | + | 
 | 72 | +void DAPTestBase::SetUpTestSuite() {  | 
 | 73 | +  lldb::SBError error = SBDebugger::InitializeWithErrorHandling();  | 
 | 74 | +  EXPECT_TRUE(error.Success());  | 
 | 75 | +}  | 
 | 76 | +void DAPTestBase::TeatUpTestSuite() { SBDebugger::Terminate(); }  | 
 | 77 | + | 
 | 78 | +bool DAPTestBase::GetDebuggerSupportsTarget(llvm::StringRef platform) {  | 
 | 79 | +  EXPECT_TRUE(dap->debugger);  | 
 | 80 | + | 
 | 81 | +  lldb::SBStructuredData data = dap->debugger.GetBuildConfiguration()  | 
 | 82 | +                                    .GetValueForKey("targets")  | 
 | 83 | +                                    .GetValueForKey("value");  | 
 | 84 | +  for (size_t i = 0; i < data.GetSize(); i++) {  | 
 | 85 | +    char buf[100] = {0};  | 
 | 86 | +    size_t size = data.GetItemAtIndex(i).GetStringValue(buf, sizeof(buf));  | 
 | 87 | +    if (llvm::StringRef(buf, size) == platform)  | 
 | 88 | +      return true;  | 
 | 89 | +  }  | 
 | 90 | + | 
 | 91 | +  return false;  | 
 | 92 | +}  | 
 | 93 | + | 
 | 94 | +void DAPTestBase::CreateDebugger() {  | 
 | 95 | +  dap->debugger = lldb::SBDebugger::Create();  | 
 | 96 | +  ASSERT_TRUE(dap->debugger);  | 
 | 97 | +}  | 
 | 98 | + | 
 | 99 | +void DAPTestBase::LoadCore() {  | 
 | 100 | +  ASSERT_TRUE(dap->debugger);  | 
 | 101 | +  llvm::Expected<lldb_private::TestFile> binary_yaml =  | 
 | 102 | +      lldb_private::TestFile::fromYamlFile(k_linux_binary);  | 
 | 103 | +  ASSERT_THAT_EXPECTED(binary_yaml, Succeeded());  | 
 | 104 | +  llvm::Expected<llvm::sys::fs::TempFile> binary_file =  | 
 | 105 | +      binary_yaml->writeToTemporaryFile();  | 
 | 106 | +  ASSERT_THAT_EXPECTED(binary_file, Succeeded());  | 
 | 107 | +  binary = std::move(*binary_file);  | 
 | 108 | +  dap->target = dap->debugger.CreateTarget(binary->TmpName.data());  | 
 | 109 | +  ASSERT_TRUE(dap->target);  | 
 | 110 | +  llvm::Expected<lldb_private::TestFile> core_yaml =  | 
 | 111 | +      lldb_private::TestFile::fromYamlFile(k_linux_core);  | 
 | 112 | +  ASSERT_THAT_EXPECTED(core_yaml, Succeeded());  | 
 | 113 | +  llvm::Expected<llvm::sys::fs::TempFile> core_file =  | 
 | 114 | +      core_yaml->writeToTemporaryFile();  | 
 | 115 | +  ASSERT_THAT_EXPECTED(core_file, Succeeded());  | 
 | 116 | +  this->core = std::move(*core_file);  | 
 | 117 | +  SBProcess process = dap->target.LoadCore(this->core->TmpName.data());  | 
 | 118 | +  ASSERT_TRUE(process);  | 
 | 119 | +}  | 
 | 120 | + | 
58 | 121 | std::vector<Message> DAPTestBase::DrainOutput() {  | 
59 | 122 |   std::vector<Message> msgs;  | 
60 | 123 |   output.CloseWriteFileDescriptor();  | 
 | 
0 commit comments