[Feat] (MG_Test/Backend/DirectVulkan): some sanity tests

This commit is contained in:
2026-02-10 13:24:24 +08:00
parent acc826ee9f
commit 1c2924eef9
3 changed files with 122 additions and 0 deletions
@@ -0,0 +1,37 @@
cmake_minimum_required(VERSION 3.14)
message(STATUS "Generating build files for MobileGL DirectVulkan Integration Test...")
add_executable(
DirectVulkanSanityTest
SanityTest.cpp
)
target_include_directories(DirectVulkanSanityTest PRIVATE
${MGL_ROOT}/include
${MGL_ROOT}/MobileGL
)
if (WIN32)
# I know this is horrible, but glfw only provides binary but not CMake config for Windows, so we have to manually link against the library and include directories
#set(GLFW_ROOT path/to/glfw-3.4.bin.WIN64)
target_include_directories(DirectVulkanSanityTest PRIVATE ${GLFW_ROOT}/include)
target_link_directories(DirectVulkanSanityTest PRIVATE ${GLFW_ROOT}/lib-vc2022)
target_link_libraries(DirectVulkanSanityTest PRIVATE glfw3_mt.lib)
else()
find_package(glfw3 REQUIRED)
target_link_libraries(DirectVulkanSanityTest PRIVATE glfw)
endif()
find_package(Vulkan REQUIRED)
target_include_directories(DirectVulkanSanityTest PUBLIC ${Vulkan_INCLUDE_DIRS})
target_link_libraries(DirectVulkanSanityTest PRIVATE Vulkan::Vulkan)
target_link_libraries(
DirectVulkanSanityTest PRIVATE
GTest::gtest_main
${LINK_LIBRARIES}
)
include(GoogleTest)
gtest_discover_tests(DirectVulkanSanityTest)
@@ -0,0 +1,82 @@
// MobileGL - MobileGL/MG_Test/Backend/DirectVulkan/SanityTest.cpp
// Copyright (c) 2025-2026 MobileGL-Dev
// Licensed under the GNU Lesser General Public License v3.0:
// https://www.gnu.org/licenses/gpl-3.0.txt
// https://www.gnu.org/licenses/lgpl-3.0.txt
// SPDX-License-Identifier: LGPL-3.0-only
// End of Source File Header
#include <gtest/gtest.h>
#include <iostream>
#include <vector>
#include <vulkan/vulkan.h>
TEST(DirectVulkanSanity, ExtensionEnumeration) {
uint32_t extensionCount = 0;
vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr);
std::cout << extensionCount << " extensions supported\n";
std::vector<VkExtensionProperties> extensions(extensionCount);
vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, extensions.data());
for(const auto& extension : extensions) {
std::cout << extension.extensionName
<< " (r." << extension.specVersion << ")\n";
}
}
#include <GLFW/glfw3.h>
TEST(DirectVulkanSanity, WindowCreation) {
glfwInit();
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
GLFWwindow* window = glfwCreateWindow(800, 600, "MobileGL WindowCreation", nullptr, nullptr);
while(!glfwWindowShouldClose(window)) {
glfwPollEvents();
}
glfwDestroyWindow(window);
glfwTerminate();
}
#define EGLAPI
#include <EGL/egl.h>
#ifdef _WIN32
#define GLFW_EXPOSE_NATIVE_WIN32
#endif
#include <GLFW/glfw3native.h>
TEST(DirectVulkanSanity, ContextCreation) {
glfwInit();
static EGLint const attribute_list[] = {
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_NONE
};
EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
eglInitialize(display, nullptr, nullptr);
EGLConfig config;
EGLint num_config;
eglChooseConfig(display, attribute_list, &config, 1, &num_config);
EGLContext context = eglCreateContext(display, config, EGL_NO_CONTEXT, nullptr);
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
GLFWwindow* window = glfwCreateWindow(800, 600, "MobileGL ContextCreation", nullptr, nullptr);
#ifdef _WIN32
EGLNativeWindowType nativewindow = glfwGetWin32Window(window);
#endif
EGLSurface surface = eglCreateWindowSurface(display, config, nativewindow, nullptr);
while(!glfwWindowShouldClose(window)) {
glfwPollEvents();
}
glfwDestroyWindow(window);
glfwTerminate();
}
+3
View File
@@ -61,3 +61,6 @@ gtest_discover_tests(SanityTest)
add_subdirectory(Buffer)
add_subdirectory(VertexArray)
add_subdirectory(Program)
if (ENABLE_INTEGRATION_TESTS)
add_subdirectory(Backend/DirectVulkan)
endif()