Files
TheRock/compiler/amd-llvm/lldb/unittests/DAP/TestBase.cpp
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

135 lines
4.7 KiB
C++

//===-- TestBase.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 "TestBase.h"
#include "DAP.h"
#include "DAPLog.h"
#include "Handler/RequestHandler.h"
#include "Handler/ResponseHandler.h"
#include "TestingSupport/TestUtilities.h"
#include "lldb/API/SBDefines.h"
#include "lldb/API/SBStructuredData.h"
#include "lldb/Host/MainLoop.h"
#include "lldb/Host/Pipe.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Error.h"
#include "llvm/Testing/Support/Error.h"
#include "gtest/gtest.h"
#include <cstdio>
#include <memory>
using namespace llvm;
using namespace lldb;
using namespace lldb_dap;
using namespace lldb_dap::protocol;
using namespace lldb_dap_tests;
using lldb_private::File;
using lldb_private::FileSpec;
using lldb_private::FileSystem;
using lldb_private::MainLoop;
using lldb_private::Pipe;
void TransportBase::SetUp() {
std::tie(to_client, to_server) = TestDAPTransport::createPair(loop);
log = std::make_unique<Log>(llvm::outs(), log_mutex);
dap = std::make_unique<DAP>(
/*log=*/*log,
/*default_repl_mode=*/ReplMode::Auto,
/*pre_init_commands=*/std::vector<String>(),
/*no_lldbinit=*/false,
/*client_name=*/"test_client",
/*transport=*/*to_client, /*loop=*/loop);
EXPECT_THAT_ERROR(to_server->RegisterMessageHandler(*dap), Succeeded());
EXPECT_THAT_ERROR(to_client->RegisterMessageHandler(client), Succeeded());
}
void TransportBase::Run() {
bool addition_succeeded = loop.AddPendingCallback(
[](lldb_private::MainLoopBase &loop) { loop.RequestTermination(); });
EXPECT_TRUE(addition_succeeded);
EXPECT_THAT_ERROR(loop.Run().takeError(), llvm::Succeeded());
}
void DAPTestBase::SetUp() { TransportBase::SetUp(); }
void DAPTestBase::TearDown() {
if (core)
ASSERT_THAT_ERROR(core->discard(), Succeeded());
if (binary)
ASSERT_THAT_ERROR(binary->discard(), Succeeded());
}
void DAPTestBase::SetUpTestSuite() {
lldb::SBError error = SBDebugger::InitializeWithErrorHandling();
EXPECT_TRUE(error.Success());
}
void DAPTestBase::TearDownTestSuite() { SBDebugger::Terminate(); }
bool DAPTestBase::GetDebuggerSupportsTarget(StringRef platform) {
EXPECT_TRUE(dap->debugger);
lldb::SBStructuredData data = dap->debugger.GetBuildConfiguration()
.GetValueForKey("targets")
.GetValueForKey("value");
for (size_t i = 0; i < data.GetSize(); i++) {
char buf[100] = {0};
size_t size = data.GetItemAtIndex(i).GetStringValue(buf, sizeof(buf));
if (StringRef(buf, size) == platform)
return true;
}
return false;
}
void DAPTestBase::CreateDebugger() {
dap->debugger = lldb::SBDebugger::Create();
ASSERT_TRUE(dap->debugger);
dap->target = dap->debugger.GetDummyTarget();
Expected<lldb::FileUP> dev_null = FileSystem::Instance().Open(
FileSpec(FileSystem::DEV_NULL), File::eOpenOptionReadWrite);
ASSERT_THAT_EXPECTED(dev_null, Succeeded());
lldb::FileSP dev_null_sp = std::move(*dev_null);
std::FILE *dev_null_stream = dev_null_sp->GetStream();
ASSERT_THAT_ERROR(dap->ConfigureIO(dev_null_stream, dev_null_stream),
Succeeded());
dap->debugger.SetInputFile(dap->in);
auto out_fd = dap->out.GetWriteFileDescriptor();
ASSERT_THAT_EXPECTED(out_fd, Succeeded());
dap->debugger.SetOutputFile(lldb::SBFile(*out_fd, "w", false));
auto err_fd = dap->out.GetWriteFileDescriptor();
ASSERT_THAT_EXPECTED(err_fd, Succeeded());
dap->debugger.SetErrorFile(lldb::SBFile(*err_fd, "w", false));
}
void DAPTestBase::LoadCore() {
ASSERT_TRUE(dap->debugger);
llvm::Expected<lldb_private::TestFile> binary_yaml =
lldb_private::TestFile::fromYamlFile(k_linux_binary);
ASSERT_THAT_EXPECTED(binary_yaml, Succeeded());
llvm::Expected<llvm::sys::fs::TempFile> binary_file =
binary_yaml->writeToTemporaryFile();
ASSERT_THAT_EXPECTED(binary_file, Succeeded());
binary = std::move(*binary_file);
dap->target = dap->debugger.CreateTarget(binary->TmpName.data());
ASSERT_TRUE(dap->target);
llvm::Expected<lldb_private::TestFile> core_yaml =
lldb_private::TestFile::fromYamlFile(k_linux_core);
ASSERT_THAT_EXPECTED(core_yaml, Succeeded());
llvm::Expected<llvm::sys::fs::TempFile> core_file =
core_yaml->writeToTemporaryFile();
ASSERT_THAT_EXPECTED(core_file, Succeeded());
this->core = std::move(*core_file);
SBProcess process = dap->target.LoadCore(this->core->TmpName.data());
ASSERT_TRUE(process);
}