Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/tests/gpu_testing.hh
| /* SPDX-License-Identifier: Apache-2.0 */ | /* SPDX-License-Identifier: Apache-2.0 */ | ||||
| #include "testing/testing.h" | #include "testing/testing.h" | ||||
| #include "GHOST_C-api.h" | #include "GHOST_C-api.h" | ||||
| #include "GPU_platform.h" | |||||
| struct GPUContext; | struct GPUContext; | ||||
| namespace blender::gpu { | namespace blender::gpu { | ||||
| /* Test class that setups a GPUContext for test cases. | /* Test class that setups a GPUContext for test cases. | ||||
| * | * | ||||
| * Usage: | * Usage: | ||||
| * TEST_F(GPUTest, my_gpu_test) { | * TEST_F(GPUTest, my_gpu_test) { | ||||
| * ... | * ... | ||||
| * } | * } | ||||
| */ | */ | ||||
| class GPUTest : public ::testing::Test { | class GPUTest : public ::testing::Test { | ||||
| private: | private: | ||||
| GHOST_TDrawingContextType draw_context_type = GHOST_kDrawingContextTypeNone; | GHOST_TDrawingContextType draw_context_type = GHOST_kDrawingContextTypeNone; | ||||
| eGPUBackendType gpu_backend_type; | |||||
| GHOST_SystemHandle ghost_system; | GHOST_SystemHandle ghost_system; | ||||
| GHOST_ContextHandle ghost_context; | GHOST_ContextHandle ghost_context; | ||||
| struct GPUContext *context; | struct GPUContext *context; | ||||
| protected: | protected: | ||||
| GPUTest(GHOST_TDrawingContextType draw_context_type) : draw_context_type(draw_context_type) | GPUTest(GHOST_TDrawingContextType draw_context_type, eGPUBackendType gpu_backend_type) | ||||
| : draw_context_type(draw_context_type), gpu_backend_type(gpu_backend_type) | |||||
| { | { | ||||
| } | } | ||||
| void SetUp() override; | void SetUp() override; | ||||
| void TearDown() override; | void TearDown() override; | ||||
| }; | }; | ||||
| class GPUOpenGLTest : public GPUTest { | class GPUOpenGLTest : public GPUTest { | ||||
| public: | public: | ||||
| GPUOpenGLTest() : GPUTest(GHOST_kDrawingContextTypeOpenGL) | GPUOpenGLTest() : GPUTest(GHOST_kDrawingContextTypeOpenGL, GPU_BACKEND_OPENGL) | ||||
| { | { | ||||
| } | } | ||||
| }; | }; | ||||
| #define GPU_TEST(test_name) \ | #define GPU_OPENGL_TEST(test_name) \ | ||||
| TEST_F(GPUOpenGLTest, test_name) \ | TEST_F(GPUOpenGLTest, test_name) \ | ||||
| { \ | { \ | ||||
| test_##test_name(); \ | test_##test_name(); \ | ||||
| } | } | ||||
| #ifdef WITH_METAL_BACKEND | |||||
| class GPUMetalTest : public GPUTest { | |||||
| public: | |||||
| GPUMetalTest() : GPUTest(GHOST_kDrawingContextTypeMetal, GPU_BACKEND_METAL) | |||||
| { | |||||
| } | |||||
| }; | |||||
| # define GPU_METAL_TEST(test_name) \ | |||||
| TEST_F(GPUMetalTest, test_name) \ | |||||
| { \ | |||||
| test_##test_name(); \ | |||||
| } | |||||
| #else | |||||
| # define GPU_METAL_TEST(test_name) | |||||
| #endif | |||||
| #define GPU_TEST(test_name) \ | |||||
| GPU_OPENGL_TEST(test_name) \ | |||||
| GPU_METAL_TEST(test_name) | |||||
| } // namespace blender::gpu | } // namespace blender::gpu | ||||