third_party_vulkan-loader/tests/loader_get_proc_addr_tests.cpp
Charles Giessen b8f496c409 Refactor tests FrameworkEnvironment class
Move all the behavior found in child classes of FrameworkEnvironment to the
FrameworkEnvironment itself, allowing easier composibility of behavior. The
original idea was to allow special case behavior for specific test cases but
this resulted in a lot of code duplication and difficulty combining different
framework behavior, such as adding a fake ICD and setting VK_ICD_FILENAMES at
the same time.
2021-12-10 17:08:23 -07:00

124 lines
6.4 KiB
C++

/*
* Copyright (c) 2021 The Khronos Group Inc.
* Copyright (c) 2021 Valve Corporation
* Copyright (c) 2021 LunarG, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and/or associated documentation files (the "Materials"), to
* deal in the Materials without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Materials, and to permit persons to whom the Materials are
* furnished to do so, subject to the following conditions:
*
* The above copyright notice(s) and this permission notice shall be included in
* all copies or substantial portions of the Materials.
*
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
*
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE
* USE OR OTHER DEALINGS IN THE MATERIALS.
*
* Author: Charles Giessen <charles@lunarg.com>
*/
#include "test_environment.h"
// Load the global function pointers with and without a NULL vkInstance handle.
// Call the function to make sure it is callable, don't care about what is returned.
TEST(GetProcAddr, GlobalFunctions) {
FrameworkEnvironment env{};
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_6));
env.get_test_icd().physical_devices.emplace_back("physical_device_0");
auto& gipa = env.vulkan_functions.vkGetInstanceProcAddr;
// global entry points with NULL instance handle
{
auto EnumerateInstanceExtensionProperties =
reinterpret_cast<PFN_vkEnumerateInstanceExtensionProperties>(gipa(NULL, "vkEnumerateInstanceExtensionProperties"));
handle_assert_has_value(EnumerateInstanceExtensionProperties);
uint32_t ext_count = 0;
ASSERT_EQ(VK_SUCCESS, EnumerateInstanceExtensionProperties("", &ext_count, nullptr));
auto EnumerateInstanceLayerProperties =
reinterpret_cast<PFN_vkEnumerateInstanceLayerProperties>(gipa(NULL, "vkEnumerateInstanceLayerProperties"));
handle_assert_has_value(EnumerateInstanceLayerProperties);
uint32_t layer_count = 0;
ASSERT_EQ(VK_SUCCESS, EnumerateInstanceLayerProperties(&layer_count, nullptr));
auto EnumerateInstanceVersion = reinterpret_cast<PFN_vkEnumerateInstanceVersion>(gipa(NULL, "vkEnumerateInstanceVersion"));
handle_assert_has_value(EnumerateInstanceVersion);
uint32_t api_version = 0;
EnumerateInstanceVersion(&api_version);
auto GetInstanceProcAddr = reinterpret_cast<PFN_vkGetInstanceProcAddr>(gipa(NULL, "vkGetInstanceProcAddr"));
handle_assert_has_value(GetInstanceProcAddr);
GetInstanceProcAddr(NULL, "vkGetInstanceProcAddr");
auto CreateInstance = reinterpret_cast<PFN_vkCreateInstance>(gipa(NULL, "vkCreateInstance"));
handle_assert_has_value(CreateInstance);
}
// Now create an instance and query the functions again - should work because the instance version is less than 1.2
for (int i = 0; i <= 2; i++) {
InstWrapper inst{env.vulkan_functions};
inst.create_info.api_version = VK_MAKE_API_VERSION(0, 1, i, 0);
inst.CheckCreate();
auto EnumerateInstanceExtensionProperties =
reinterpret_cast<PFN_vkEnumerateInstanceExtensionProperties>(gipa(inst, "vkEnumerateInstanceExtensionProperties"));
handle_assert_has_value(EnumerateInstanceExtensionProperties);
uint32_t ext_count = 0;
ASSERT_EQ(VK_SUCCESS, EnumerateInstanceExtensionProperties("", &ext_count, nullptr));
auto EnumerateInstanceLayerProperties =
reinterpret_cast<PFN_vkEnumerateInstanceLayerProperties>(gipa(inst, "vkEnumerateInstanceLayerProperties"));
handle_assert_has_value(EnumerateInstanceLayerProperties);
uint32_t layer_count = 0;
ASSERT_EQ(VK_SUCCESS, EnumerateInstanceLayerProperties(&layer_count, nullptr));
auto EnumerateInstanceVersion = reinterpret_cast<PFN_vkEnumerateInstanceVersion>(gipa(inst, "vkEnumerateInstanceVersion"));
handle_assert_has_value(EnumerateInstanceVersion);
uint32_t api_version = 0;
EnumerateInstanceVersion(&api_version);
auto GetInstanceProcAddr = reinterpret_cast<PFN_vkGetInstanceProcAddr>(gipa(inst, "vkGetInstanceProcAddr"));
handle_assert_has_value(GetInstanceProcAddr);
GetInstanceProcAddr(NULL, "vkGetInstanceProcAddr");
auto CreateInstance = reinterpret_cast<PFN_vkCreateInstance>(gipa(inst, "vkCreateInstance"));
handle_assert_has_value(CreateInstance);
}
{
// Create a 1.3 instance - now everything should return NULL
InstWrapper inst{env.vulkan_functions};
inst.create_info.api_version = VK_MAKE_API_VERSION(0, 1, 3, 0);
inst.CheckCreate();
auto EnumerateInstanceExtensionProperties =
reinterpret_cast<PFN_vkEnumerateInstanceExtensionProperties>(gipa(inst, "vkEnumerateInstanceExtensionProperties"));
handle_assert_null(EnumerateInstanceExtensionProperties);
auto EnumerateInstanceLayerProperties =
reinterpret_cast<PFN_vkEnumerateInstanceLayerProperties>(gipa(inst, "vkEnumerateInstanceLayerProperties"));
handle_assert_null(EnumerateInstanceLayerProperties);
auto EnumerateInstanceVersion = reinterpret_cast<PFN_vkEnumerateInstanceVersion>(gipa(inst, "vkEnumerateInstanceVersion"));
handle_assert_null(EnumerateInstanceVersion);
auto CreateInstance = reinterpret_cast<PFN_vkCreateInstance>(gipa(inst, "vkCreateInstance"));
handle_assert_null(CreateInstance);
auto GetInstanceProcAddr = reinterpret_cast<PFN_vkGetInstanceProcAddr>(gipa(inst, "vkGetInstanceProcAddr"));
handle_assert_null(GetInstanceProcAddr);
// get a non pre-instance function pointer
auto EnumeratePhysicalDevices = reinterpret_cast<PFN_vkGetInstanceProcAddr>(gipa(inst, "vkEnumeratePhysicalDevices"));
handle_assert_has_value(EnumeratePhysicalDevices);
EnumeratePhysicalDevices = reinterpret_cast<PFN_vkGetInstanceProcAddr>(gipa(NULL, "vkEnumeratePhysicalDevices"));
handle_assert_null(EnumeratePhysicalDevices);
}
}