Cleanup how tests create PhysicalDeviceGroup vectors
authorCharles Giessen <charles@lunarg.com>
Thu, 20 Jul 2023 18:25:12 +0000 (12:25 -0600)
committerCharles Giessen <46324611+charles-lunarg@users.noreply.github.com>
Mon, 24 Jul 2023 22:32:05 +0000 (16:32 -0600)
Makes use of the vectors initialization constructor to remove iterating over
the elements of the vector to set the sType manually.

Also zero's out the VkPhysicalDevice array in the TestICD so that non-filled
in elements have a value of zero instead of being uninitialized.

tests/framework/icd/test_icd.cpp
tests/framework/layer/test_layer.cpp
tests/loader_layer_tests.cpp

index 98bcb8f..f620f1d 100644 (file)
@@ -267,6 +267,9 @@ test_vkEnumeratePhysicalDeviceGroups([[maybe_unused]] VkInstance instance, uint3
                 pPhysicalDeviceGroupProperties[device_group].physicalDeviceCount = 1;
                 pPhysicalDeviceGroupProperties[device_group].physicalDevices[0] =
                     icd.physical_devices[device_group].vk_physical_device.handle;
+                for (size_t i = 1; i < VK_MAX_DEVICE_GROUP_SIZE; i++) {
+                    pPhysicalDeviceGroupProperties[device_group].physicalDevices[i] = {};
+                }
             }
         } else {
             group_count = static_cast<uint32_t>(icd.physical_device_groups.size());
@@ -284,6 +287,9 @@ test_vkEnumeratePhysicalDeviceGroups([[maybe_unused]] VkInstance instance, uint3
                     pPhysicalDeviceGroupProperties[device_group].physicalDevices[i] =
                         icd.physical_device_groups[device_group].physical_device_handles[i]->vk_physical_device.handle;
                 }
+                for (size_t i = handles_written; i < VK_MAX_DEVICE_GROUP_SIZE; i++) {
+                    pPhysicalDeviceGroupProperties[device_group].physicalDevices[i] = {};
+                }
                 pPhysicalDeviceGroupProperties[device_group].physicalDeviceCount = handles_written;
             }
         }
index 49a8d11..72d5162 100644 (file)
@@ -457,10 +457,8 @@ VKAPI_ATTR VkResult VKAPI_CALL test_vkEnumeratePhysicalDeviceGroups(
             //       underneath us when using this test.
             uint32_t icd_group_count = 0;
             layer.instance_dispatch_table.EnumeratePhysicalDeviceGroups(instance, &icd_group_count, nullptr);
-            std::vector<VkPhysicalDeviceGroupProperties> tmp_vector(icd_group_count);
-            for (uint32_t group = 0; group < icd_group_count; ++group) {
-                tmp_vector[group].sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GROUP_PROPERTIES;
-            }
+            std::vector<VkPhysicalDeviceGroupProperties> tmp_vector(icd_group_count,
+                                                                    {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GROUP_PROPERTIES});
             layer.instance_dispatch_table.EnumeratePhysicalDeviceGroups(instance, &icd_group_count, tmp_vector.data());
             layer.complete_physical_device_groups.clear();
 
index 28281de..10ffee2 100644 (file)
@@ -4643,18 +4643,16 @@ TEST(LayerPhysDeviceMod, AddPhysicalDeviceGroups) {
     ASSERT_EQ(VK_SUCCESS, inst->vkEnumeratePhysicalDeviceGroups(inst, &grp_count, nullptr));
     ASSERT_GT(grp_count, icd_groups);
 
-    auto not_exp_phys_dev_groups = std::vector<VkPhysicalDeviceGroupProperties>(icd_groups);
-    for (uint32_t group = 0; group < icd_groups; ++group) {
-        not_exp_phys_dev_groups[group].sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GROUP_PROPERTIES;
-    }
+    auto not_exp_phys_dev_groups =
+        std::vector<VkPhysicalDeviceGroupProperties>(icd_groups, {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GROUP_PROPERTIES});
+
     uint32_t returned_group_count = icd_groups;
     ASSERT_EQ(VK_INCOMPLETE, inst->vkEnumeratePhysicalDeviceGroups(inst, &returned_group_count, not_exp_phys_dev_groups.data()));
     ASSERT_EQ(icd_groups, returned_group_count);
 
-    auto phys_dev_groups = std::vector<VkPhysicalDeviceGroupProperties>(grp_count);
-    for (uint32_t group = 0; group < grp_count; ++group) {
-        phys_dev_groups[group].sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GROUP_PROPERTIES;
-    }
+    auto phys_dev_groups =
+        std::vector<VkPhysicalDeviceGroupProperties>(grp_count, {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GROUP_PROPERTIES});
+
     returned_group_count = grp_count;
     ASSERT_EQ(VK_SUCCESS, inst->vkEnumeratePhysicalDeviceGroups(inst, &returned_group_count, phys_dev_groups.data()));
     ASSERT_EQ(grp_count, returned_group_count);
@@ -4731,10 +4729,9 @@ TEST(LayerPhysDeviceMod, RemovePhysicalDeviceGroups) {
     ASSERT_EQ(VK_SUCCESS, inst->vkEnumeratePhysicalDeviceGroups(inst, &grp_count, nullptr));
     ASSERT_LT(grp_count, icd_groups);
 
-    auto phys_dev_groups = std::vector<VkPhysicalDeviceGroupProperties>(grp_count);
-    for (uint32_t group = 0; group < grp_count; ++group) {
-        phys_dev_groups[group].sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GROUP_PROPERTIES;
-    }
+    auto phys_dev_groups =
+        std::vector<VkPhysicalDeviceGroupProperties>(grp_count, {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GROUP_PROPERTIES});
+
     uint32_t returned_group_count = grp_count;
     ASSERT_EQ(VK_SUCCESS, inst->vkEnumeratePhysicalDeviceGroups(inst, &returned_group_count, phys_dev_groups.data()));
     ASSERT_EQ(grp_count, returned_group_count);
@@ -4784,10 +4781,9 @@ TEST(LayerPhysDeviceMod, ReorderPhysicalDeviceGroups) {
     ASSERT_EQ(VK_SUCCESS, inst->vkEnumeratePhysicalDeviceGroups(inst, &grp_count, nullptr));
     ASSERT_EQ(grp_count, icd_groups);
 
-    auto phys_dev_groups = std::vector<VkPhysicalDeviceGroupProperties>(grp_count);
-    for (uint32_t group = 0; group < grp_count; ++group) {
-        phys_dev_groups[group].sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GROUP_PROPERTIES;
-    }
+    auto phys_dev_groups =
+        std::vector<VkPhysicalDeviceGroupProperties>(grp_count, {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GROUP_PROPERTIES});
+
     uint32_t returned_group_count = grp_count;
     ASSERT_EQ(VK_SUCCESS, inst->vkEnumeratePhysicalDeviceGroups(inst, &returned_group_count, phys_dev_groups.data()));
     ASSERT_EQ(grp_count, returned_group_count);
@@ -4837,10 +4833,9 @@ TEST(LayerPhysDeviceMod, AddRemoveAndReorderPhysicalDeviceGroups) {
     ASSERT_EQ(VK_SUCCESS, inst->vkEnumeratePhysicalDeviceGroups(inst, &grp_count, nullptr));
     ASSERT_GT(grp_count, icd_groups);
 
-    auto phys_dev_groups = std::vector<VkPhysicalDeviceGroupProperties>(grp_count);
-    for (uint32_t group = 0; group < grp_count; ++group) {
-        phys_dev_groups[group].sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GROUP_PROPERTIES;
-    }
+    auto phys_dev_groups =
+        std::vector<VkPhysicalDeviceGroupProperties>(grp_count, {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GROUP_PROPERTIES});
+
     uint32_t returned_group_count = grp_count;
     ASSERT_EQ(VK_SUCCESS, inst->vkEnumeratePhysicalDeviceGroups(inst, &returned_group_count, phys_dev_groups.data()));
     ASSERT_EQ(grp_count, returned_group_count);