Replace TEST_F with TEST in most tests

Test fixturing (TEST_F) is useful when there is a lot of common code that needs
to be run for a suite of tests. However, the FrameworkEnvironment encapsulates
almost all of the setup work all tests needs, and so doesn't need to be in a
fixture. Making the add_icd call inside the tests makes it clear which binary
is being used.

This commit also uses the corrent signed/unsigned constants in tests, as was
warned by compilers when enhanced warnings were enabled (/W4 in msvc).
This commit is contained in:
Charles Giessen
2022-03-28 23:12:49 -06:00
committed by Charles Giessen
parent 2659877674
commit d27e4c0069
10 changed files with 2267 additions and 1965 deletions
+96 -66
View File
@@ -199,8 +199,8 @@ class MemoryTracker {
class Allocation : public ::testing::Test {
protected:
virtual void SetUp() {
env = std::unique_ptr<FrameworkEnvironment>(new FrameworkEnvironment());
env->add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2));
FrameworkEnvironment env{};
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2));
}
virtual void TearDown() { env.reset(); }
@@ -209,10 +209,13 @@ class Allocation : public ::testing::Test {
// Test making sure the allocation functions are called to allocate and cleanup everything during
// a CreateInstance/DestroyInstance call pair.
TEST_F(Allocation, Instance) {
TEST(Allocation, Instance) {
FrameworkEnvironment env{};
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2));
MemoryTracker tracker;
{
InstWrapper inst{env->vulkan_functions, tracker.get()};
InstWrapper inst{env.vulkan_functions, tracker.get()};
inst.CheckCreate();
}
ASSERT_TRUE(tracker.empty());
@@ -220,10 +223,13 @@ TEST_F(Allocation, Instance) {
// Test making sure the allocation functions are called to allocate and cleanup everything during
// a CreateInstance/DestroyInstance call pair with a call to GetInstanceProcAddr.
TEST_F(Allocation, GetInstanceProcAddr) {
TEST(Allocation, GetInstanceProcAddr) {
FrameworkEnvironment env{};
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2));
MemoryTracker tracker;
{
InstWrapper inst{env->vulkan_functions, tracker.get()};
InstWrapper inst{env.vulkan_functions, tracker.get()};
inst.CheckCreate();
auto* pfnCreateDevice = inst->vkGetInstanceProcAddr(inst, "vkCreateDevice");
@@ -235,12 +241,15 @@ TEST_F(Allocation, GetInstanceProcAddr) {
// Test making sure the allocation functions are called to allocate and cleanup everything during
// a vkEnumeratePhysicalDevices call pair.
TEST_F(Allocation, EnumeratePhysicalDevices) {
TEST(Allocation, EnumeratePhysicalDevices) {
FrameworkEnvironment env{};
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2));
MemoryTracker tracker;
auto& driver = env->get_test_icd();
auto& driver = env.get_test_icd();
driver.physical_devices.emplace_back("physical_device_0");
{
InstWrapper inst{env->vulkan_functions, tracker.get()};
InstWrapper inst{env.vulkan_functions, tracker.get()};
inst.CheckCreate();
uint32_t physical_count = 1;
uint32_t returned_physical_count = 0;
@@ -257,13 +266,16 @@ TEST_F(Allocation, EnumeratePhysicalDevices) {
// Test making sure the allocation functions are called to allocate and cleanup everything from
// vkCreateInstance, to vkCreateDevicce, and then through their destructors. With special
// allocators used on both the instance and device.
TEST_F(Allocation, InstanceAndDevice) {
TEST(Allocation, InstanceAndDevice) {
FrameworkEnvironment env{};
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2));
MemoryTracker tracker;
auto& driver = env->get_test_icd();
auto& driver = env.get_test_icd();
driver.physical_devices.emplace_back("physical_device_0");
driver.physical_devices[0].add_queue_family_properties({{VK_QUEUE_GRAPHICS_BIT, 1, 0, {1, 1, 1}}, false});
{
InstWrapper inst{env->vulkan_functions, tracker.get()};
InstWrapper inst{env.vulkan_functions, tracker.get()};
inst.CheckCreate();
uint32_t physical_count = 1;
@@ -277,15 +289,15 @@ TEST_F(Allocation, InstanceAndDevice) {
uint32_t family_count = 1;
uint32_t returned_family_count = 0;
env->vulkan_functions.vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &returned_family_count, nullptr);
env.vulkan_functions.vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &returned_family_count, nullptr);
ASSERT_EQ(returned_family_count, family_count);
VkQueueFamilyProperties family;
env->vulkan_functions.vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &returned_family_count, &family);
env.vulkan_functions.vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &returned_family_count, &family);
ASSERT_EQ(returned_family_count, family_count);
ASSERT_EQ(family.queueFlags, VK_QUEUE_GRAPHICS_BIT);
ASSERT_EQ(family.queueFlags, static_cast<VkQueueFlags>(VK_QUEUE_GRAPHICS_BIT));
ASSERT_EQ(family.queueCount, family_count);
ASSERT_EQ(family.timestampValidBits, 0);
ASSERT_EQ(family.timestampValidBits, 0U);
DeviceCreateInfo dev_create_info;
DeviceQueueCreateInfo queue_info;
@@ -301,14 +313,17 @@ TEST_F(Allocation, InstanceAndDevice) {
// Test making sure the allocation functions are called to allocate and cleanup everything from
// vkCreateInstance, to vkCreateDevicce, and then through their destructors. With special
// allocators used on only the instance and not the device.
TEST_F(Allocation, InstanceButNotDevice) {
TEST(Allocation, InstanceButNotDevice) {
FrameworkEnvironment env{};
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2));
MemoryTracker tracker;
{
auto& driver = env->get_test_icd();
auto& driver = env.get_test_icd();
driver.physical_devices.emplace_back("physical_device_0");
driver.physical_devices[0].add_queue_family_properties({{VK_QUEUE_GRAPHICS_BIT, 1, 0, {1, 1, 1}}, false});
InstWrapper inst{env->vulkan_functions, tracker.get()};
InstWrapper inst{env.vulkan_functions, tracker.get()};
inst.CheckCreate();
uint32_t physical_count = 1;
@@ -322,15 +337,15 @@ TEST_F(Allocation, InstanceButNotDevice) {
uint32_t family_count = 1;
uint32_t returned_family_count = 0;
env->vulkan_functions.vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &returned_family_count, nullptr);
env.vulkan_functions.vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &returned_family_count, nullptr);
ASSERT_EQ(returned_family_count, family_count);
VkQueueFamilyProperties family;
env->vulkan_functions.vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &returned_family_count, &family);
env.vulkan_functions.vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &returned_family_count, &family);
ASSERT_EQ(returned_family_count, family_count);
ASSERT_EQ(family.queueFlags, VK_QUEUE_GRAPHICS_BIT);
ASSERT_EQ(family.queueFlags, static_cast<VkQueueFlags>(VK_QUEUE_GRAPHICS_BIT));
ASSERT_EQ(family.queueCount, family_count);
ASSERT_EQ(family.timestampValidBits, 0);
ASSERT_EQ(family.timestampValidBits, 0U);
DeviceCreateInfo dev_create_info;
DeviceQueueCreateInfo queue_info;
@@ -347,14 +362,17 @@ TEST_F(Allocation, InstanceButNotDevice) {
// Test making sure the allocation functions are called to allocate and cleanup everything from
// vkCreateInstance, to vkCreateDevicce, and then through their destructors. With special
// allocators used on only the device and not the instance.
TEST_F(Allocation, DeviceButNotInstance) {
TEST(Allocation, DeviceButNotInstance) {
FrameworkEnvironment env{};
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2));
MemoryTracker tracker;
{
auto& driver = env->get_test_icd();
auto& driver = env.get_test_icd();
driver.physical_devices.emplace_back("physical_device_0");
driver.physical_devices[0].add_queue_family_properties({{VK_QUEUE_GRAPHICS_BIT, 1, 0, {1, 1, 1}}, false});
InstWrapper inst{env->vulkan_functions};
InstWrapper inst{env.vulkan_functions};
inst.CheckCreate();
uint32_t physical_count = 1;
@@ -368,15 +386,15 @@ TEST_F(Allocation, DeviceButNotInstance) {
uint32_t family_count = 1;
uint32_t returned_family_count = 0;
env->vulkan_functions.vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &returned_family_count, nullptr);
env.vulkan_functions.vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &returned_family_count, nullptr);
ASSERT_EQ(returned_family_count, family_count);
VkQueueFamilyProperties family;
env->vulkan_functions.vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &returned_family_count, &family);
env.vulkan_functions.vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &returned_family_count, &family);
ASSERT_EQ(returned_family_count, family_count);
ASSERT_EQ(family.queueFlags, VK_QUEUE_GRAPHICS_BIT);
ASSERT_EQ(family.queueFlags, static_cast<VkQueueFlags>(VK_QUEUE_GRAPHICS_BIT));
ASSERT_EQ(family.queueCount, family_count);
ASSERT_EQ(family.timestampValidBits, 0);
ASSERT_EQ(family.timestampValidBits, 0U);
DeviceCreateInfo dev_create_info;
DeviceQueueCreateInfo queue_info;
@@ -392,7 +410,10 @@ TEST_F(Allocation, DeviceButNotInstance) {
// Test failure during vkCreateInstance to make sure we don't leak memory if
// one of the out-of-memory conditions trigger.
TEST_F(Allocation, CreateInstanceIntentionalAllocFail) {
TEST(Allocation, CreateInstanceIntentionalAllocFail) {
FrameworkEnvironment env{};
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2));
size_t fail_index = 0;
VkResult result = VK_ERROR_OUT_OF_HOST_MEMORY;
while (result == VK_ERROR_OUT_OF_HOST_MEMORY && fail_index <= 10000) {
@@ -400,9 +421,9 @@ TEST_F(Allocation, CreateInstanceIntentionalAllocFail) {
VkInstance instance;
InstanceCreateInfo inst_create_info{};
result = env->vulkan_functions.vkCreateInstance(inst_create_info.get(), tracker.get(), &instance);
result = env.vulkan_functions.vkCreateInstance(inst_create_info.get(), tracker.get(), &instance);
if (result == VK_SUCCESS) {
env->vulkan_functions.vkDestroyInstance(instance, tracker.get());
env.vulkan_functions.vkDestroyInstance(instance, tracker.get());
}
ASSERT_TRUE(tracker.empty());
fail_index++;
@@ -413,14 +434,17 @@ TEST_F(Allocation, CreateInstanceIntentionalAllocFail) {
// one of the out-of-memory conditions trigger.
// Use 2 physical devices so that anything which copies a list of devices item by item
// may fail.
TEST_F(Allocation, CreateDeviceIntentionalAllocFail) {
auto& driver = env->get_test_icd();
TEST(Allocation, CreateDeviceIntentionalAllocFail) {
FrameworkEnvironment env{};
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2));
auto& driver = env.get_test_icd();
driver.physical_devices.emplace_back("physical_device_0");
driver.physical_devices[0].add_queue_family_properties({{VK_QUEUE_GRAPHICS_BIT, 1, 0, {1, 1, 1}}, false});
driver.physical_devices.emplace_back("physical_device_1");
driver.physical_devices[1].add_queue_family_properties({{VK_QUEUE_GRAPHICS_BIT, 1, 0, {1, 1, 1}}, false});
InstWrapper inst{env->vulkan_functions};
InstWrapper inst{env.vulkan_functions};
inst.CheckCreate();
uint32_t physical_count = 2;
@@ -434,15 +458,15 @@ TEST_F(Allocation, CreateDeviceIntentionalAllocFail) {
uint32_t family_count = 1;
uint32_t returned_family_count = 0;
env->vulkan_functions.vkGetPhysicalDeviceQueueFamilyProperties(physical_devices[0], &returned_family_count, nullptr);
env.vulkan_functions.vkGetPhysicalDeviceQueueFamilyProperties(physical_devices[0], &returned_family_count, nullptr);
ASSERT_EQ(returned_family_count, family_count);
VkQueueFamilyProperties family;
env->vulkan_functions.vkGetPhysicalDeviceQueueFamilyProperties(physical_devices[0], &returned_family_count, &family);
env.vulkan_functions.vkGetPhysicalDeviceQueueFamilyProperties(physical_devices[0], &returned_family_count, &family);
ASSERT_EQ(returned_family_count, family_count);
ASSERT_EQ(family.queueFlags, VK_QUEUE_GRAPHICS_BIT);
ASSERT_EQ(family.queueFlags, static_cast<VkQueueFlags>(VK_QUEUE_GRAPHICS_BIT));
ASSERT_EQ(family.queueCount, family_count);
ASSERT_EQ(family.timestampValidBits, 0);
ASSERT_EQ(family.timestampValidBits, 0U);
size_t fail_index = 0;
VkResult result = VK_ERROR_OUT_OF_HOST_MEMORY;
@@ -467,8 +491,11 @@ TEST_F(Allocation, CreateDeviceIntentionalAllocFail) {
// Test failure during vkCreateInstance and vkCreateDevice to make sure we don't
// leak memory if one of the out-of-memory conditions trigger.
TEST_F(Allocation, CreateInstanceDeviceIntentionalAllocFail) {
auto& driver = env->get_test_icd();
TEST(Allocation, CreateInstanceDeviceIntentionalAllocFail) {
FrameworkEnvironment env{};
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2));
auto& driver = env.get_test_icd();
driver.physical_devices.emplace_back("physical_device_0");
driver.physical_devices[0].add_queue_family_properties({{VK_QUEUE_GRAPHICS_BIT, 1, 0, {1, 1, 1}}, false});
@@ -480,7 +507,7 @@ TEST_F(Allocation, CreateInstanceDeviceIntentionalAllocFail) {
VkInstance instance;
InstanceCreateInfo inst_create_info{};
result = env->vulkan_functions.vkCreateInstance(inst_create_info.get(), tracker.get(), &instance);
result = env.vulkan_functions.vkCreateInstance(inst_create_info.get(), tracker.get(), &instance);
if (result == VK_ERROR_OUT_OF_HOST_MEMORY) {
ASSERT_TRUE(tracker.empty());
continue;
@@ -488,18 +515,18 @@ TEST_F(Allocation, CreateInstanceDeviceIntentionalAllocFail) {
uint32_t physical_count = 1;
uint32_t returned_physical_count = 0;
result = env->vulkan_functions.vkEnumeratePhysicalDevices(instance, &returned_physical_count, nullptr);
result = env.vulkan_functions.vkEnumeratePhysicalDevices(instance, &returned_physical_count, nullptr);
if (result == VK_ERROR_OUT_OF_HOST_MEMORY) {
env->vulkan_functions.vkDestroyInstance(instance, tracker.get());
env.vulkan_functions.vkDestroyInstance(instance, tracker.get());
ASSERT_TRUE(tracker.empty());
continue;
}
ASSERT_EQ(physical_count, returned_physical_count);
VkPhysicalDevice physical_device;
result = env->vulkan_functions.vkEnumeratePhysicalDevices(instance, &returned_physical_count, &physical_device);
result = env.vulkan_functions.vkEnumeratePhysicalDevices(instance, &returned_physical_count, &physical_device);
if (result == VK_ERROR_OUT_OF_HOST_MEMORY) {
env->vulkan_functions.vkDestroyInstance(instance, tracker.get());
env.vulkan_functions.vkDestroyInstance(instance, tracker.get());
ASSERT_TRUE(tracker.empty());
continue;
}
@@ -507,15 +534,15 @@ TEST_F(Allocation, CreateInstanceDeviceIntentionalAllocFail) {
uint32_t family_count = 1;
uint32_t returned_family_count = 0;
env->vulkan_functions.vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &returned_family_count, nullptr);
env.vulkan_functions.vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &returned_family_count, nullptr);
ASSERT_EQ(returned_family_count, family_count);
VkQueueFamilyProperties family;
env->vulkan_functions.vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &returned_family_count, &family);
env.vulkan_functions.vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &returned_family_count, &family);
ASSERT_EQ(returned_family_count, family_count);
ASSERT_EQ(family.queueFlags, VK_QUEUE_GRAPHICS_BIT);
ASSERT_EQ(family.queueFlags, static_cast<VkQueueFlags>(VK_QUEUE_GRAPHICS_BIT));
ASSERT_EQ(family.queueCount, family_count);
ASSERT_EQ(family.timestampValidBits, 0);
ASSERT_EQ(family.timestampValidBits, 0U);
DeviceCreateInfo dev_create_info;
DeviceQueueCreateInfo queue_info;
@@ -523,11 +550,11 @@ TEST_F(Allocation, CreateInstanceDeviceIntentionalAllocFail) {
dev_create_info.add_device_queue(queue_info);
VkDevice device;
result = env->vulkan_functions.vkCreateDevice(physical_device, dev_create_info.get(), tracker.get(), &device);
result = env.vulkan_functions.vkCreateDevice(physical_device, dev_create_info.get(), tracker.get(), &device);
if (result == VK_SUCCESS) {
env->vulkan_functions.vkDestroyDevice(device, tracker.get());
env.vulkan_functions.vkDestroyDevice(device, tracker.get());
}
env->vulkan_functions.vkDestroyInstance(instance, tracker.get());
env.vulkan_functions.vkDestroyInstance(instance, tracker.get());
ASSERT_TRUE(tracker.empty());
}
@@ -559,7 +586,10 @@ TEST(TryLoadWrongBinaries, CreateInstanceIntentionalAllocFail) {
// Test failure during vkCreateInstance and vkCreateDevice to make sure we don't
// leak memory if one of the out-of-memory conditions trigger.
TEST_F(Allocation, EnumeratePhysicalDevicesIntentionalAllocFail) {
TEST(Allocation, EnumeratePhysicalDevicesIntentionalAllocFail) {
FrameworkEnvironment env{};
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2));
size_t fail_index = 0;
bool reached_the_end = false;
uint32_t starting_physical_dev_count = 3;
@@ -567,7 +597,7 @@ TEST_F(Allocation, EnumeratePhysicalDevicesIntentionalAllocFail) {
fail_index++; // applies to the next loop
uint32_t physical_dev_count = starting_physical_dev_count;
VkResult result = VK_ERROR_OUT_OF_HOST_MEMORY;
auto& driver = env->reset_icd();
auto& driver = env.reset_icd();
for (uint32_t i = 0; i < physical_dev_count; i++) {
driver.physical_devices.emplace_back(std::string("physical_device_") + std::to_string(i));
@@ -576,16 +606,16 @@ TEST_F(Allocation, EnumeratePhysicalDevicesIntentionalAllocFail) {
MemoryTracker tracker{MemoryTrackerSettings{false, 0, true, fail_index}};
InstanceCreateInfo inst_create_info;
VkInstance instance;
result = env->vulkan_functions.vkCreateInstance(inst_create_info.get(), tracker.get(), &instance);
result = env.vulkan_functions.vkCreateInstance(inst_create_info.get(), tracker.get(), &instance);
if (result == VK_ERROR_OUT_OF_HOST_MEMORY) {
ASSERT_TRUE(tracker.empty());
continue;
}
uint32_t returned_physical_count = 0;
result = env->vulkan_functions.vkEnumeratePhysicalDevices(instance, &returned_physical_count, nullptr);
result = env.vulkan_functions.vkEnumeratePhysicalDevices(instance, &returned_physical_count, nullptr);
if (result == VK_ERROR_OUT_OF_HOST_MEMORY) {
env->vulkan_functions.vkDestroyInstance(instance, tracker.get());
env.vulkan_functions.vkDestroyInstance(instance, tracker.get());
ASSERT_TRUE(tracker.empty());
continue;
}
@@ -597,23 +627,23 @@ TEST_F(Allocation, EnumeratePhysicalDevicesIntentionalAllocFail) {
}
std::vector<VkPhysicalDevice> physical_devices{physical_dev_count, VK_NULL_HANDLE};
result = env->vulkan_functions.vkEnumeratePhysicalDevices(instance, &returned_physical_count, physical_devices.data());
result = env.vulkan_functions.vkEnumeratePhysicalDevices(instance, &returned_physical_count, physical_devices.data());
if (result == VK_ERROR_OUT_OF_HOST_MEMORY) {
env->vulkan_functions.vkDestroyInstance(instance, tracker.get());
env.vulkan_functions.vkDestroyInstance(instance, tracker.get());
ASSERT_TRUE(tracker.empty());
continue;
}
if (result == VK_INCOMPLETE) {
result = env->vulkan_functions.vkEnumeratePhysicalDevices(instance, &returned_physical_count, nullptr);
result = env.vulkan_functions.vkEnumeratePhysicalDevices(instance, &returned_physical_count, nullptr);
if (result == VK_ERROR_OUT_OF_HOST_MEMORY) {
env->vulkan_functions.vkDestroyInstance(instance, tracker.get());
env.vulkan_functions.vkDestroyInstance(instance, tracker.get());
ASSERT_TRUE(tracker.empty());
continue;
}
physical_devices.resize(returned_physical_count);
result = env->vulkan_functions.vkEnumeratePhysicalDevices(instance, &returned_physical_count, physical_devices.data());
result = env.vulkan_functions.vkEnumeratePhysicalDevices(instance, &returned_physical_count, physical_devices.data());
if (result == VK_ERROR_OUT_OF_HOST_MEMORY) {
env->vulkan_functions.vkDestroyInstance(instance, tracker.get());
env.vulkan_functions.vkDestroyInstance(instance, tracker.get());
ASSERT_TRUE(tracker.empty());
continue;
}
@@ -621,7 +651,7 @@ TEST_F(Allocation, EnumeratePhysicalDevicesIntentionalAllocFail) {
ASSERT_EQ(physical_dev_count, returned_physical_count);
std::cout << "fail count " << fail_index << "\n";
env->vulkan_functions.vkDestroyInstance(instance, tracker.get());
env.vulkan_functions.vkDestroyInstance(instance, tracker.get());
ASSERT_TRUE(tracker.empty());
reached_the_end = true;
}