Skip to content

Refactor test framework to detect invalid handles and support multiple instances#1922

Merged
charles-lunarg merged 8 commits into
KhronosGroup:mainfrom
charles-lunarg:test_framework_detect_invalid_handles
Jun 7, 2026
Merged

Refactor test framework to detect invalid handles and support multiple instances#1922
charles-lunarg merged 8 commits into
KhronosGroup:mainfrom
charles-lunarg:test_framework_detect_invalid_handles

Conversation

@charles-lunarg

Copy link
Copy Markdown
Collaborator

The test framework was originally written with some rather limiting assumptions, such as:

  • Each driver could only have 1 instance created from it at a time.
  • Physical Device handles were attached to a struct defining the properties/features/extensions of that physical device, and were re-used between different instances.
  • Assuming the handles passed into the driver are correct and return whatever the mock values are, not checking if they correspond to the handle passed in.
  • Test_layer's fake physical devices weren't dispatchable.

These all proved to be a problem with the attempted rewrite to not wrap physical device handles. While that rewrite is not finalized, breaking out these changes makes sure that if the rewrite fails, then these useful changes aren't lost.

Removed unused headers, added static to internal globals (fixed errors in
ASAN on macOS), fixed compiler warnings.
The handles given out by the test layer are not actually valid Vulkan
dispatchable handles.
Prior to this, the mock ICD did not track which instance enumerated
which physical devices, which is invalid according to the spec. Not
only that, it meant that if the loader didn't wrap the physical device
handle, multiple instances would share the same physical device
dispatchable handle and overwrite the dispatch handle.

This is accomplished by splitting the 'info', extensions, properties,
limits, etc, from the 'state', the dispatchable handles enumerated
per instance. To improve performance, maps of the instance, physical
device, and device handles with structs containing details of the
objects. These details also include child objects and pointers to the
'state' (currently, only PhysicalDevice is separate from the TestICD).
There is non-trivial logic keeping the vector of PhysicalDevice's and
the created state structs up to date with eachother, as order of the
PhysicalDevice vector is the order their associated state objects are
returned in vkEnumeratePhysicalDevices.
With the refactor of the previous commit, the PhysicalDevice struct is
no longer move-only, which removes the need for calling .finish().
Make sure each and every call to the driver only gives handles valid to
the driver. Also turns ERROR_INITIALIZATION_FAILED return codes into
hard aborts, to make sure the issue is detected.
@ci-tester-lunarg

Copy link
Copy Markdown

CI Vulkan-Loader build queued with queue ID 763052.

@ci-tester-lunarg

Copy link
Copy Markdown

CI Vulkan-Loader build queued with queue ID 763069.

@ci-tester-lunarg

Copy link
Copy Markdown

CI Vulkan-Loader build # 3515 running.

@ci-tester-lunarg

Copy link
Copy Markdown

CI Vulkan-Loader build # 3515 failed.

Add an internal function to the test_icd which validates that the passed
in physical device is one from the driver.
@charles-lunarg charles-lunarg force-pushed the test_framework_detect_invalid_handles branch from 070def6 to 7ebb4c4 Compare June 7, 2026 22:48
@ci-tester-lunarg

Copy link
Copy Markdown

CI Vulkan-Loader build queued with queue ID 763137.

@ci-tester-lunarg

Copy link
Copy Markdown

CI Vulkan-Loader build # 3516 running.

@ci-tester-lunarg

Copy link
Copy Markdown

CI Vulkan-Loader build queued with queue ID 763167.

@ci-tester-lunarg

Copy link
Copy Markdown

CI Vulkan-Loader build # 3517 running.

@ci-tester-lunarg

Copy link
Copy Markdown

CI Vulkan-Loader build # 3517 passed.

@charles-lunarg charles-lunarg merged commit 4b9fa87 into KhronosGroup:main Jun 7, 2026
46 checks passed
@charles-lunarg charles-lunarg deleted the test_framework_detect_invalid_handles branch June 7, 2026 23:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants