Files
TheRock/compiler/amd-llvm/lldb/unittests/TestingSupport/Host/JSONTransportTestUtilities.h
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

92 lines
3.1 KiB
C++

//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#ifndef LLDB_UNITTESTS_TESTINGSUPPORT_HOST_JSONTRANSPORTTESTUTILITIES_H
#define LLDB_UNITTESTS_TESTINGSUPPORT_HOST_JSONTRANSPORTTESTUTILITIES_H
#include "lldb/Host/FileSystem.h"
#include "lldb/Host/JSONTransport.h"
#include "lldb/Host/MainLoop.h"
#include "lldb/Utility/FileSpec.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Testing/Support/Error.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <cstddef>
#include <memory>
#include <utility>
template <typename Proto>
class TestTransport final
: public lldb_private::transport::JSONTransport<Proto> {
public:
using MessageHandler =
typename lldb_private::transport::JSONTransport<Proto>::MessageHandler;
static std::pair<std::unique_ptr<TestTransport<Proto>>,
std::unique_ptr<TestTransport<Proto>>>
createPair(lldb_private::MainLoop &loop) {
std::unique_ptr<TestTransport<Proto>> transports[2] = {
std::make_unique<TestTransport<Proto>>(loop),
std::make_unique<TestTransport<Proto>>(loop)};
return std::make_pair(std::move(transports[0]), std::move(transports[1]));
}
explicit TestTransport(lldb_private::MainLoop &loop) : m_loop(loop) {}
llvm::Error Send(const typename Proto::Evt &evt) override {
EXPECT_TRUE(m_handler) << "Send called before RegisterMessageHandler";
m_loop.AddPendingCallback([this, evt](lldb_private::MainLoopBase &) {
m_handler->Received(evt);
});
return llvm::Error::success();
}
llvm::Error Send(const typename Proto::Req &req) override {
EXPECT_TRUE(m_handler) << "Send called before RegisterMessageHandler";
m_loop.AddPendingCallback([this, req](lldb_private::MainLoopBase &) {
m_handler->Received(req);
});
return llvm::Error::success();
}
llvm::Error Send(const typename Proto::Resp &resp) override {
EXPECT_TRUE(m_handler) << "Send called before RegisterMessageHandler";
m_loop.AddPendingCallback([this, resp](lldb_private::MainLoopBase &) {
m_handler->Received(resp);
});
return llvm::Error::success();
}
llvm::Error RegisterMessageHandler(MessageHandler &handler) override {
if (!m_handler)
m_handler = &handler;
return llvm::Error::success();
}
protected:
void Log(llvm::StringRef message) override {};
private:
lldb_private::MainLoop &m_loop;
MessageHandler *m_handler = nullptr;
};
template <typename Proto>
class MockMessageHandler final
: public lldb_private::transport::JSONTransport<Proto>::MessageHandler {
public:
MOCK_METHOD(void, Received, (const typename Proto::Req &), (override));
MOCK_METHOD(void, Received, (const typename Proto::Resp &), (override));
MOCK_METHOD(void, Received, (const typename Proto::Evt &), (override));
MOCK_METHOD(void, OnError, (llvm::Error), (override));
MOCK_METHOD(void, OnClosed, (), (override));
};
#endif