test: Add RHI integration test framework
Add integration tests for RHI module: - Add tests/RHI/integration/ directory with CMakeLists.txt - Add RHIIntegrationFixture for shared test utilities - Add minimal integration test (window creation, basic rendering) - Add compare_ppm.py for image comparison - Add run_integration_test.py test runner script These integration tests verify the complete rendering pipeline by comparing rendered output against ground truth PPM files.
This commit is contained in:
73
tests/RHI/integration/minimal/main.cpp
Normal file
73
tests/RHI/integration/minimal/main.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "../fixtures/RHIIntegrationFixture.h"
|
||||
|
||||
using namespace XCEngine::RHI;
|
||||
using namespace XCEngine::RHI::Integration;
|
||||
|
||||
namespace {
|
||||
|
||||
class MinimalTest : public RHIIntegrationFixture {
|
||||
protected:
|
||||
void RenderFrame() override;
|
||||
};
|
||||
|
||||
void MinimalTest::RenderFrame() {
|
||||
RHICommandList* cmdList = GetCommandList();
|
||||
RHICommandQueue* cmdQueue = GetCommandQueue();
|
||||
|
||||
cmdList->Reset();
|
||||
|
||||
Viewport viewport = { 0.0f, 0.0f, 1280.0f, 720.0f, 0.0f, 1.0f };
|
||||
Rect scissorRect = { 0, 0, 1280, 720 };
|
||||
cmdList->SetViewport(viewport);
|
||||
cmdList->SetScissorRect(scissorRect);
|
||||
|
||||
float clearColor[] = { 1.0f, 0.0f, 0.0f, 1.0f };
|
||||
cmdList->Clear(clearColor[0], clearColor[1], clearColor[2], clearColor[3], 1);
|
||||
|
||||
cmdList->Close();
|
||||
void* cmdLists[] = { cmdList };
|
||||
cmdQueue->ExecuteCommandLists(1, cmdLists);
|
||||
}
|
||||
|
||||
TEST_P(MinimalTest, RenderClear) {
|
||||
RHICommandQueue* cmdQueue = GetCommandQueue();
|
||||
RHISwapChain* swapChain = GetSwapChain();
|
||||
const int targetFrameCount = 30;
|
||||
|
||||
for (int frameCount = 0; frameCount <= targetFrameCount; ++frameCount) {
|
||||
if (frameCount > 0) {
|
||||
cmdQueue->WaitForPreviousFrame();
|
||||
}
|
||||
|
||||
BeginRender();
|
||||
RenderFrame();
|
||||
EndRender();
|
||||
|
||||
if (frameCount >= targetFrameCount) {
|
||||
cmdQueue->WaitForIdle();
|
||||
ASSERT_TRUE(TakeScreenshot("minimal.ppm"));
|
||||
ASSERT_TRUE(CompareWithGoldenTemplate("minimal.ppm",
|
||||
(GetBackendType() == RHIType::D3D12) ? "GT_D3D12.ppm" : "GT_OpenGL.ppm",
|
||||
(GetBackendType() == RHIType::D3D12) ? 0.0f : 5.0f));
|
||||
break;
|
||||
}
|
||||
|
||||
swapChain->Present(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(D3D12, MinimalTest, ::testing::Values(RHIType::D3D12));
|
||||
INSTANTIATE_TEST_SUITE_P(OpenGL, MinimalTest, ::testing::Values(RHIType::OpenGL));
|
||||
|
||||
GTEST_API_ int main(int argc, char** argv) {
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
Reference in New Issue
Block a user