39 lines
1.5 KiB
C++
39 lines
1.5 KiB
C++
#include "render_3D/detail/Gpu_Completion_Service.h"
|
|
#include <gtest/gtest.h>
|
|
#include <atomic>
|
|
#include <chrono>
|
|
#include <thread>
|
|
#include <utility>
|
|
namespace renderive::render_3d::detail {
|
|
namespace {
|
|
TEST(GpuCompletionService, UsesOneProcessWideService) {
|
|
EXPECT_EQ(&Gpu_Completion_Service::instance(), &Gpu_Completion_Service::instance());
|
|
}
|
|
TEST(GpuCompletionService, AbandonedReservationDoesNotComplete) {
|
|
std::atomic<int> completion_count{};
|
|
{
|
|
auto prepared = Gpu_Completion_Service::instance().prepare(
|
|
[&](Gpu_Completion_Service::Result) {
|
|
completion_count.fetch_add(1, std::memory_order_relaxed);
|
|
}, false);
|
|
ASSERT_TRUE(prepared);
|
|
}
|
|
EXPECT_EQ(completion_count.load(std::memory_order_relaxed), 0);
|
|
}
|
|
TEST(GpuCompletionService, CanceledReservationWakesIdleService) {
|
|
auto& service = Gpu_Completion_Service::instance();
|
|
const auto baseline = service.statistics().in_flight;
|
|
{
|
|
auto prepared = service.prepare([](Gpu_Completion_Service::Result) {}, false);
|
|
ASSERT_TRUE(prepared);
|
|
EXPECT_EQ(service.statistics().in_flight, baseline + 1);
|
|
}
|
|
const auto deadline = std::chrono::steady_clock::now() + std::chrono::milliseconds(100);
|
|
while (service.statistics().in_flight != baseline &&
|
|
std::chrono::steady_clock::now() < deadline)
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
|
EXPECT_EQ(service.statistics().in_flight, baseline);
|
|
}
|
|
}
|
|
}
|