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
99 lines
3.0 KiB
C++
99 lines
3.0 KiB
C++
//===-- SubsystemRAIITest.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 "gtest/gtest-spi.h"
|
|
#include "gtest/gtest.h"
|
|
|
|
#include "TestingSupport/SubsystemRAII.h"
|
|
|
|
using namespace lldb_private;
|
|
|
|
namespace {
|
|
|
|
enum class SystemState {
|
|
/// Start state of the subsystem.
|
|
Start,
|
|
/// Initialize has been called but Terminate hasn't been called yet.
|
|
Initialized,
|
|
/// Terminate has been called.
|
|
Terminated
|
|
};
|
|
|
|
struct TestSubsystem {
|
|
static SystemState state;
|
|
static void Initialize() {
|
|
assert(state == SystemState::Start);
|
|
state = SystemState::Initialized;
|
|
}
|
|
static void Terminate() {
|
|
assert(state == SystemState::Initialized);
|
|
state = SystemState::Terminated;
|
|
}
|
|
};
|
|
} // namespace
|
|
|
|
SystemState TestSubsystem::state = SystemState::Start;
|
|
|
|
TEST(SubsystemRAIITest, NormalSubsystem) {
|
|
// Tests that SubsystemRAII handles Initialize functions that return void.
|
|
EXPECT_EQ(SystemState::Start, TestSubsystem::state);
|
|
{
|
|
SubsystemRAII<TestSubsystem> subsystem;
|
|
EXPECT_EQ(SystemState::Initialized, TestSubsystem::state);
|
|
}
|
|
EXPECT_EQ(SystemState::Terminated, TestSubsystem::state);
|
|
}
|
|
|
|
static const char *SubsystemErrorString = "Initialize failed";
|
|
|
|
namespace {
|
|
struct TestSubsystemWithError {
|
|
static SystemState state;
|
|
static bool will_fail;
|
|
static llvm::Error Initialize() {
|
|
assert(state == SystemState::Start);
|
|
state = SystemState::Initialized;
|
|
if (will_fail)
|
|
return llvm::createStringError(SubsystemErrorString);
|
|
return llvm::Error::success();
|
|
}
|
|
static void Terminate() {
|
|
assert(state == SystemState::Initialized);
|
|
state = SystemState::Terminated;
|
|
}
|
|
/// Reset the subsystem to the default state for testing.
|
|
static void Reset() { state = SystemState::Start; }
|
|
};
|
|
} // namespace
|
|
|
|
SystemState TestSubsystemWithError::state = SystemState::Start;
|
|
bool TestSubsystemWithError::will_fail = false;
|
|
|
|
TEST(SubsystemRAIITest, SubsystemWithErrorSuccess) {
|
|
// Tests that SubsystemRAII handles llvm::success() returned from
|
|
// Initialize.
|
|
TestSubsystemWithError::Reset();
|
|
EXPECT_EQ(SystemState::Start, TestSubsystemWithError::state);
|
|
{
|
|
TestSubsystemWithError::will_fail = false;
|
|
SubsystemRAII<TestSubsystemWithError> subsystem;
|
|
EXPECT_EQ(SystemState::Initialized, TestSubsystemWithError::state);
|
|
}
|
|
EXPECT_EQ(SystemState::Terminated, TestSubsystemWithError::state);
|
|
}
|
|
|
|
TEST(SubsystemRAIITest, SubsystemWithErrorFailure) {
|
|
// Tests that SubsystemRAII handles any errors returned from
|
|
// Initialize.
|
|
TestSubsystemWithError::Reset();
|
|
EXPECT_EQ(SystemState::Start, TestSubsystemWithError::state);
|
|
TestSubsystemWithError::will_fail = true;
|
|
EXPECT_FATAL_FAILURE(SubsystemRAII<TestSubsystemWithError> subsystem,
|
|
SubsystemErrorString);
|
|
}
|