Files
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

103 lines
3.0 KiB
C++

//===-- FifoFilesTest.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 "FifoFiles.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Testing/Support/Error.h"
#include "gtest/gtest.h"
#include <chrono>
#include <thread>
using namespace lldb_dap;
using namespace llvm;
namespace {
std::string MakeTempFifoPath() {
llvm::SmallString<128> temp_path;
llvm::sys::fs::createUniquePath("lldb-dap-fifo-%%%%%%", temp_path,
/*MakeAbsolute=*/true);
return temp_path.str().str();
}
} // namespace
TEST(FifoFilesTest, CreateAndDestroyFifoFile) {
std::string fifo_path = MakeTempFifoPath();
auto fifo = CreateFifoFile(fifo_path);
EXPECT_THAT_EXPECTED(fifo, llvm::Succeeded());
// File should exist.
EXPECT_TRUE(llvm::sys::fs::exists(fifo_path));
// Destructor should remove the file.
fifo->reset();
EXPECT_FALSE(llvm::sys::fs::exists(fifo_path));
}
TEST(FifoFilesTest, SendAndReceiveJSON) {
std::string fifo_path = MakeTempFifoPath();
auto fifo = CreateFifoFile(fifo_path);
EXPECT_THAT_EXPECTED(fifo, llvm::Succeeded());
FifoFileIO writer(*fifo, "writer");
FifoFileIO reader(*fifo, "reader");
llvm::json::Object obj;
obj["foo"] = "bar";
obj["num"] = 42;
// Writer thread.
std::thread writer_thread([&]() {
EXPECT_THAT_ERROR(writer.SendJSON(llvm::json::Value(std::move(obj)),
std::chrono::milliseconds(500)),
llvm::Succeeded());
});
// Reader thread.
std::thread reader_thread([&]() {
auto result = reader.ReadJSON(std::chrono::milliseconds(500));
EXPECT_THAT_EXPECTED(result, llvm::Succeeded());
auto *read_obj = result->getAsObject();
ASSERT_NE(read_obj, nullptr);
EXPECT_EQ((*read_obj)["foo"].getAsString(), "bar");
EXPECT_EQ((*read_obj)["num"].getAsInteger(), 42);
});
writer_thread.join();
reader_thread.join();
}
TEST(FifoFilesTest, ReadTimeout) {
std::string fifo_path = MakeTempFifoPath();
auto fifo = CreateFifoFile(fifo_path);
EXPECT_THAT_EXPECTED(fifo, llvm::Succeeded());
FifoFileIO reader(*fifo, "reader");
// No writer, should timeout.
auto result = reader.ReadJSON(std::chrono::milliseconds(100));
EXPECT_THAT_EXPECTED(result, llvm::Failed());
}
TEST(FifoFilesTest, WriteTimeout) {
std::string fifo_path = MakeTempFifoPath();
auto fifo = CreateFifoFile(fifo_path);
EXPECT_THAT_EXPECTED(fifo, llvm::Succeeded());
FifoFileIO writer(*fifo, "writer");
// No reader, should timeout.
llvm::json::Object obj;
obj["foo"] = "bar";
EXPECT_THAT_ERROR(writer.SendJSON(llvm::json::Value(std::move(obj)),
std::chrono::milliseconds(100)),
llvm::Failed());
}