third_party_vulkan-loader/tests/loader_unknown_ext_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

67 lines
2.9 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"
class UnknownExtension : public ::testing::Test {
protected:
virtual void SetUp() {
env = std::unique_ptr<FrameworkEnvironment>(new FrameworkEnvironment());
env->add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA));
}
virtual void TearDown() { env.reset(); }
std::unique_ptr<FrameworkEnvironment> env;
};
/*
Creates a TestICD with a function unknown to the loader called vkNotRealFuncTEST. The TestICD, when vk_icdGetPhysicalDeviceProcAddr
is called, will return the custom_physical_device_function if the function name matches vkNotRealFuncTEST. The test then calls the
function to verify that the unknown physical device function dispatching is working correctly.
*/
VkResult custom_physical_device_function(VkPhysicalDevice device, int foo, int bar) { return VK_SUCCESS; }
using PFN_custom_physical_device_function = decltype(&custom_physical_device_function);
TEST_F(UnknownExtension, ICDKnownExtension) {
auto& driver = env->get_test_icd();
const char* fake_function_name = "vkNotRealFuncTEST";
driver.physical_devices.emplace_back("physical_device_0");
driver.custom_physical_device_functions.push_back(
VulkanFunction{fake_function_name, reinterpret_cast<void*>(custom_physical_device_function)});
InstWrapper inst{env->vulkan_functions};
inst.CheckCreate();
VkPhysicalDevice phys_dev = inst.GetPhysDev();
PFN_custom_physical_device_function returned_func = reinterpret_cast<PFN_custom_physical_device_function>(
env->vulkan_functions.vkGetInstanceProcAddr(inst.inst, fake_function_name));
ASSERT_NE(returned_func, nullptr);
ASSERT_EQ(returned_func(phys_dev, 42, 58008), VK_SUCCESS);
}