From 7040985c553c1a5ecf998bc61e53e5ae76fd41c1 Mon Sep 17 00:00:00 2001 From: Charles Giessen Date: Thu, 15 Jun 2023 18:25:42 -0600 Subject: test: Add basic MockICD test --- tests/icd/mock_icd_tests.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++-- tests/main.cpp | 12 ------------ 2 files changed, 44 insertions(+), 14 deletions(-) (limited to 'tests') diff --git a/tests/icd/mock_icd_tests.cpp b/tests/icd/mock_icd_tests.cpp index 18025dfa..78372134 100644 --- a/tests/icd/mock_icd_tests.cpp +++ b/tests/icd/mock_icd_tests.cpp @@ -17,9 +17,51 @@ * */ +#include + +#include +#include + #include "gtest/gtest.h" +#include "vulkan/vulkan.h" + +// Location of the built binaries in this repo +#include "binary_locations.h" + +#if defined(WIN32) +int set_environment_var(const char* name, const char* value) { return SetEnvironmentVariableA(name, cur_value); } +#else +int set_environment_var(const char* name, const char* value) { return setenv(name, value, 1); } +#endif TEST(MockICD, Basic) { - // only to make sure tests can be run - ASSERT_TRUE(true); + // Necessary to point the loader at the mock driver + set_environment_var("VK_DRIVER_FILES", MOCK_ICD_JSON_MANIFEST_PATH); + // Prevents layers from being loaded at all + set_environment_var("VK_LOADER_LAYERS_DISABLE", "~all~"); + + uint32_t count = 0; + VkResult res = vkEnumerateInstanceExtensionProperties(nullptr, &count, nullptr); + ASSERT_EQ(res, VK_SUCCESS); + ASSERT_GT(count, 0); + std::vector inst_ext_props{count, VkExtensionProperties{}}; + res = vkEnumerateInstanceExtensionProperties(nullptr, &count, inst_ext_props.data()); + ASSERT_EQ(res, VK_SUCCESS); + + VkInstanceCreateInfo inst_create_info{}; + VkInstance inst{}; + res = vkCreateInstance(&inst_create_info, nullptr, &inst); + ASSERT_EQ(res, VK_SUCCESS); + + res = vkEnumeratePhysicalDevices(inst, &count, nullptr); + ASSERT_EQ(res, VK_SUCCESS); + ASSERT_GT(count, 0); + std::vector phys_devs{count}; + res = vkEnumeratePhysicalDevices(inst, &count, phys_devs.data()); + ASSERT_EQ(res, VK_SUCCESS); + + VkDeviceCreateInfo dev_create_info{}; + VkDevice device{}; + res = vkCreateDevice(phys_devs.at(0), &dev_create_info, nullptr, &device); + ASSERT_EQ(res, VK_SUCCESS); } diff --git a/tests/main.cpp b/tests/main.cpp index a14e8e99..31131426 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -26,18 +26,6 @@ int main(int argc, char **argv) { int result; -#if defined(_WIN32) -#if !defined(NDEBUG) - _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE); - _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); -#endif - // Avoid "Abort, Retry, Ignore" dialog boxes - _set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT); - SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); - _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE); - _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); -#endif - ::testing::InitGoogleTest(&argc, argv); result = RUN_ALL_TESTS(); -- cgit v1.2.3