Debian Codegraph @

tests/framework/test_environment.h

raw
1 /*
2 * Copyright (c) 2021-2023 The Khronos Group Inc.
3 * Copyright (c) 2021-2023 Valve Corporation
4 * Copyright (c) 2021-2023 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and/or associated documentation files (the "Materials"), to
8 * deal in the Materials without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Materials, and to permit persons to whom the Materials are
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice(s) and this permission notice shall be included in
14 * all copies or substantial portions of the Materials.
15 *
16 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 *
20 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE
23 * USE OR OTHER DEALINGS IN THE MATERIALS.
24 *
25 * Author: Charles Giessen <[email protected]>
26 */
27
28 /*
29 * The test_environment is what combines the icd, layer, and shim library into a single object that
30 * test fixtures can create and use. Responsible for loading the libraries and establishing the
31 * channels for tests to talk with the icd's and layers.
32 */
33 #pragma once
34
35 // Must include gtest first to guard against Xlib colliding due to redefinitions of "None" and "Bool"
36 #if defined(VK_USE_PLATFORM_XLIB_KHR)
37 #pragma push_macro("None")
38 #pragma push_macro("Bool")
39 #undef None
40 #undef Bool
41 #endif
42
43 #if defined(_WIN32)
44 #if !defined(NOMINMAX)
45 #define NOMINMAX
46 #endif
47 #endif
48
49 #include "gtest/gtest.h"
50
51 #include "util/builder_defines.h"
52 #include "util/dispatch_table.h"
53 #include "util/dynamic_library_wrapper.h"
54 #include "util/env_var_wrapper.h"
55 #include "util/equality_helpers.h"
56 #include "util/folder_manager.h"
57 #include "util/functions.h"
58 #include "util/manifest_builders.h"
59 #include "util/test_defines.h"
60 #include "util/vulkan_object_wrappers.h"
61
62 #include "shim/shim.h"
63
64 #include "icd/test_icd.h"
65
66 #include "layer/test_layer.h"
67
68 #include "generated/vk_result_to_string_helper.h"
69
70 // handle checking
71 template <typename T>
72 void handle_assert_has_value(T const& handle) {
73 ASSERT_TRUE(handle != VK_NULL_HANDLE);
74 }
75 template <typename T>
76 void handle_assert_null(T const& handle) {
77 ASSERT_TRUE(handle == VK_NULL_HANDLE);
78 }
79 template <typename T>
80 void handle_assert_has_values(std::vector<T> const& handles) {
81 for (auto const& handle : handles) {
82 ASSERT_TRUE(handle != VK_NULL_HANDLE);
83 }
84 }
85 template <typename T>
86 void handle_assert_no_values(std::vector<T> const& handles) {
87 for (auto const& handle : handles) {
88 ASSERT_TRUE(handle == VK_NULL_HANDLE);
89 }
90 }
91 template <typename T>
92 void handle_assert_no_values(size_t length, T handles[]) {
93 for (size_t i = 0; i < length; i++) {
94 ASSERT_TRUE(handles[i] == VK_NULL_HANDLE);
95 }
96 }
97 template <typename T>
98 void handle_assert_equal(T const& left, T const& right) {
99 ASSERT_EQ(left, right);
100 }
101 template <typename T>
102 void handle_assert_equal(std::vector<T> const& left, std::vector<T> const& right) {
103 ASSERT_EQ(left.size(), right.size());
104 for (size_t i = 0; i < left.size(); i++) {
105 ASSERT_EQ(left[i], right[i]);
106 }
107 }
108 template <typename T>
109 void handle_assert_equal(size_t count, T left[], T right[]) {
110 for (size_t i = 0; i < count; i++) {
111 ASSERT_EQ(left[i], right[i]);
112 }
113 }
114
115 template <typename T, size_t U>
116 bool check_permutation(std::initializer_list<const char*> expected, std::array<T, U> const& returned) {
117 if (expected.size() != returned.size()) return false;
118 for (uint32_t i = 0; i < expected.size(); i++) {
119 auto found = std::find_if(std::begin(returned), std::end(returned),
120 [&](T elem) { return string_eq(*(expected.begin() + i), elem.layerName); });
121 if (found == std::end(returned)) return false;
122 }
123 return true;
124 }
125 template <typename T>
126 bool check_permutation(std::initializer_list<const char*> expected, std::vector<T> const& returned) {
127 if (expected.size() != returned.size()) return false;
128 for (uint32_t i = 0; i < expected.size(); i++) {
129 auto found = std::find_if(std::begin(returned), std::end(returned),
130 [&](T elem) { return string_eq(*(expected.begin() + i), elem.layerName); });
131 if (found == std::end(returned)) return false;
132 }
133 return true;
134 }
135
136 // InstWrapper & DeviceWrapper - used to make creating instances & devices easier when writing tests
137 struct InstWrapper {
138 InstWrapper(VulkanFunctions& functions, VkAllocationCallbacks* callbacks = nullptr) noexcept;
139 InstWrapper(VulkanFunctions& functions, VkInstance inst, VkAllocationCallbacks* callbacks = nullptr) noexcept;
140 ~InstWrapper() noexcept;
141
142 // Move-only object
143 InstWrapper(InstWrapper const&) = delete;
144 InstWrapper& operator=(InstWrapper const&) = delete;
145 InstWrapper(InstWrapper&& other) noexcept;
146 InstWrapper& operator=(InstWrapper&&) noexcept;
147
148 // Construct this VkInstance using googletest to assert if it succeeded
149 void CheckCreate(VkResult result_to_check = VK_SUCCESS);
150 void CheckCreateWithInfo(InstanceCreateInfo& create_info, VkResult result_to_check = VK_SUCCESS);
151
152 // Convenience
153 operator VkInstance() { return inst; }
154 VulkanFunctions* operator->() { return functions; }
155
156 FromVoidStarFunc load(const char* func_name) { return FromVoidStarFunc(functions->vkGetInstanceProcAddr(inst, func_name)); }
157
158 // Enumerate physical devices using googletest to assert if it succeeded
159 std::vector<VkPhysicalDevice> GetPhysDevs(VkResult result_to_check = VK_SUCCESS); // query all physical devices
160 std::vector<VkPhysicalDevice> GetPhysDevs(uint32_t phys_dev_count,
161 VkResult result_to_check = VK_SUCCESS); // query only phys_dev_count devices
162 // Enumerate a single physical device using googletest to assert if it succeeded
163 VkPhysicalDevice GetPhysDev(VkResult result_to_check = VK_SUCCESS);
164
165 // Get all the list of active layers through vkEnumerateDeviceLayerProperties
166 // Use count to specify the expected count
167 std::vector<VkLayerProperties> GetActiveLayers(VkPhysicalDevice phys_dev, uint32_t count);
168
169 // Get list of device extensions associated with a VkPhysicalDevice
170 // Use count to specify an expected count
171 std::vector<VkExtensionProperties> EnumerateDeviceExtensions(VkPhysicalDevice physical_device, uint32_t count);
172 // Same as EnumerateDeviceExtensions but for a specific layer
173 std::vector<VkExtensionProperties> EnumerateLayerDeviceExtensions(VkPhysicalDevice physical_device, const char* layer_name,
174 uint32_t expected_count);
175
176 VulkanFunctions* functions = nullptr;
177 VkInstance inst = VK_NULL_HANDLE;
178 VkAllocationCallbacks* callbacks = nullptr;
179 InstanceCreateInfo create_info{};
180 };
181
182 struct DeviceWrapper {
183 DeviceWrapper(InstWrapper& inst_wrapper, VkAllocationCallbacks* callbacks = nullptr) noexcept;
184 DeviceWrapper(VulkanFunctions& functions, VkDevice device, VkAllocationCallbacks* callbacks = nullptr) noexcept;
185 ~DeviceWrapper() noexcept;
186
187 // Move-only object
188 DeviceWrapper(DeviceWrapper const&) = delete;
189 DeviceWrapper& operator=(DeviceWrapper const&) = delete;
190 DeviceWrapper(DeviceWrapper&&) noexcept;
191 DeviceWrapper& operator=(DeviceWrapper&&) noexcept;
192
193 // Construct this VkDevice using googletest to assert if it succeeded
194 void CheckCreate(VkPhysicalDevice physical_device, VkResult result_to_check = VK_SUCCESS);
195
196 // Convenience
197 operator VkDevice() { return dev; }
198 operator VkDevice() const { return dev; }
199 VulkanFunctions* operator->() { return functions; }
200
201 FromVoidStarFunc load(const char* func_name) { return FromVoidStarFunc(functions->vkGetDeviceProcAddr(dev, func_name)); }
202
203 VulkanFunctions* functions = nullptr;
204 VkDevice dev = VK_NULL_HANDLE;
205 VkAllocationCallbacks* callbacks = nullptr;
206 DeviceCreateInfo create_info{};
207 };
208
209 template <typename HandleType, typename ParentType, typename DestroyFuncType>
210 struct WrappedHandle {
211 WrappedHandle(HandleType in_handle, ParentType in_parent, DestroyFuncType in_destroy_func,
212 VkAllocationCallbacks* in_callbacks = nullptr)
213 : handle(in_handle), parent(in_parent), destroy_func(in_destroy_func), callbacks(in_callbacks) {}
214 ~WrappedHandle() {
215 if (handle) {
216 destroy_func(parent, handle, callbacks);
217 handle = VK_NULL_HANDLE;
218 }
219 }
220 WrappedHandle(WrappedHandle const&) = delete;
221 WrappedHandle& operator=(WrappedHandle const&) = delete;
222 WrappedHandle(WrappedHandle&& other) noexcept
223 : handle(other.handle), parent(other.parent), destroy_func(other.destroy_func), callbacks(other.callbacks) {
224 other.handle = VK_NULL_HANDLE;
225 }
226 WrappedHandle& operator=(WrappedHandle&& other) noexcept {
227 if (handle != VK_NULL_HANDLE) {
228 destroy_func(parent, handle, callbacks);
229 }
230 handle = other.handle;
231 other.handle = VK_NULL_HANDLE;
232 parent = other.parent;
233 destroy_func = other.destroy_func;
234 callbacks = other.callbacks;
235 return *this;
236 }
237
238 HandleType handle = VK_NULL_HANDLE;
239 ParentType parent = VK_NULL_HANDLE;
240 DestroyFuncType destroy_func = nullptr;
241 VkAllocationCallbacks* callbacks = nullptr;
242 };
243
244 struct DebugUtilsLogger {
245 static VkBool32 VKAPI_PTR
246 DebugUtilsMessengerLoggerCallback([[maybe_unused]] VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
247 [[maybe_unused]] VkDebugUtilsMessageTypeFlagsEXT messageTypes,
248 const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData, void* pUserData) {
249 DebugUtilsLogger* debug = reinterpret_cast<DebugUtilsLogger*>(pUserData);
250 debug->returned_output += pCallbackData->pMessage;
251 debug->returned_output += '\n';
252 return VK_FALSE;
253 }
254 DebugUtilsLogger(VkDebugUtilsMessageSeverityFlagsEXT severity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT |
255 VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT |
256 VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT |
257 VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) {
258 returned_output.reserve(4096); // output can be very noisy, reserving should help prevent many small allocations
259 create_info.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT;
260 create_info.pNext = nullptr;
261 create_info.messageSeverity = severity;
262 create_info.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT |
263 VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT;
264 create_info.pfnUserCallback = DebugUtilsMessengerLoggerCallback;
265 create_info.pUserData = this;
266 }
267
268 // Immoveable object
269 DebugUtilsLogger(DebugUtilsLogger const&) = delete;
270 DebugUtilsLogger& operator=(DebugUtilsLogger const&) = delete;
271 DebugUtilsLogger(DebugUtilsLogger&&) = delete;
272 DebugUtilsLogger& operator=(DebugUtilsLogger&&) = delete;
273 // Find a string in the log output
274 bool find(std::string const& search_text) const { return returned_output.find(search_text) != std::string::npos; }
275 // Find the number of times a string appears in the log output
276 uint32_t count(std::string const& search_text) const {
277 uint32_t occurrences = 0;
278 std::string::size_type position = 0;
279 while ((position = returned_output.find(search_text, position)) != std::string::npos) {
280 ++occurrences;
281 position += search_text.length();
282 }
283 return occurrences;
284 }
285
286 // Look through the event log. If you find a line containing the prefix we're interested in, look for the end of
287 // line character, and then see if the postfix occurs in it as well.
288 bool find_prefix_then_postfix(const char* prefix, const char* postfix) const;
289
290 // Clear the log
291 void clear() { returned_output.clear(); }
292 VkDebugUtilsMessengerCreateInfoEXT* get() noexcept { return &create_info; }
293 VkDebugUtilsMessengerCreateInfoEXT create_info{};
294 std::string returned_output;
295 };
296
297 struct DebugUtilsWrapper {
298 DebugUtilsWrapper() noexcept {}
299 DebugUtilsWrapper(InstWrapper& inst_wrapper,
300 VkDebugUtilsMessageSeverityFlagsEXT severity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT |
301 VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT,
302 VkAllocationCallbacks* callbacks = nullptr)
303 : logger(severity),
304 inst(inst_wrapper.inst),
305 callbacks(callbacks),
306 local_vkCreateDebugUtilsMessengerEXT(
307 FromVoidStarFunc(inst_wrapper.functions->vkGetInstanceProcAddr(inst_wrapper.inst, "vkCreateDebugUtilsMessengerEXT"))),
308 local_vkDestroyDebugUtilsMessengerEXT(FromVoidStarFunc(
309 inst_wrapper.functions->vkGetInstanceProcAddr(inst_wrapper.inst, "vkDestroyDebugUtilsMessengerEXT"))){};
310 ~DebugUtilsWrapper() noexcept {
311 if (messenger) {
312 local_vkDestroyDebugUtilsMessengerEXT(inst, messenger, callbacks);
313 messenger = VK_NULL_HANDLE;
314 }
315 }
316 // Immoveable object
317 DebugUtilsWrapper(DebugUtilsWrapper const&) = delete;
318 DebugUtilsWrapper& operator=(DebugUtilsWrapper const&) = delete;
319 DebugUtilsWrapper(DebugUtilsWrapper&&) = delete;
320 DebugUtilsWrapper& operator=(DebugUtilsWrapper&&) = delete;
321
322 bool find(std::string const& search_text) { return logger.find(search_text); }
323 uint32_t count(std::string const& search_text) { return logger.count(search_text); }
324 VkDebugUtilsMessengerCreateInfoEXT* get() noexcept { return logger.get(); }
325
326 DebugUtilsLogger logger;
327 VkInstance inst = VK_NULL_HANDLE;
328 VkAllocationCallbacks* callbacks = nullptr;
329 PFN_vkCreateDebugUtilsMessengerEXT local_vkCreateDebugUtilsMessengerEXT = nullptr;
330 PFN_vkDestroyDebugUtilsMessengerEXT local_vkDestroyDebugUtilsMessengerEXT = nullptr;
331 VkDebugUtilsMessengerEXT messenger = VK_NULL_HANDLE;
332 };
333
334 VkResult CreateDebugUtilsMessenger(DebugUtilsWrapper& debug_utils);
335
336 // Helper that adds the debug utils extension name and sets the pNext chain up
337 // NOTE: Ignores existing pNext chains
338 void FillDebugUtilsCreateDetails(InstanceCreateInfo& create_info, DebugUtilsLogger& logger);
339 void FillDebugUtilsCreateDetails(InstanceCreateInfo& create_info, DebugUtilsWrapper& wrapper);
340
341 struct LoaderSettingsLayerConfiguration {
342 BUILDER_VALUE(std::string, name)
343 BUILDER_VALUE(std::filesystem::path, path)
344 BUILDER_VALUE(std::string, control)
345 BUILDER_VALUE(bool, treat_as_implicit_manifest)
346 };
347 // Needed for next_permutation
348 inline bool operator==(LoaderSettingsLayerConfiguration const& a, LoaderSettingsLayerConfiguration const& b) {
349 return a.name == b.name && a.path == b.path && a.control == b.control &&
350 a.treat_as_implicit_manifest == b.treat_as_implicit_manifest;
351 }
352 inline bool operator!=(LoaderSettingsLayerConfiguration const& a, LoaderSettingsLayerConfiguration const& b) { return !(a == b); }
353 inline bool operator<(LoaderSettingsLayerConfiguration const& a, LoaderSettingsLayerConfiguration const& b) {
354 return a.name < b.name;
355 }
356 inline bool operator>(LoaderSettingsLayerConfiguration const& a, LoaderSettingsLayerConfiguration const& b) { return (b < a); }
357 inline bool operator<=(LoaderSettingsLayerConfiguration const& a, LoaderSettingsLayerConfiguration const& b) { return !(b < a); }
358 inline bool operator>=(LoaderSettingsLayerConfiguration const& a, LoaderSettingsLayerConfiguration const& b) { return !(a < b); }
359
360 struct LoaderSettingsDriverConfiguration {
361 BUILDER_VALUE(std::filesystem::path, path)
362 };
363
364 using VulkanUUID = std::array<uint8_t, VK_UUID_SIZE>;
365
366 struct LoaderSettingsDeviceConfiguration {
367 BUILDER_VALUE(VulkanUUID, deviceUUID)
368 BUILDER_VALUE(VulkanUUID, driverUUID)
369 BUILDER_VALUE(uint32_t, driverVersion)
370 BUILDER_VALUE(std::string, deviceName)
371 BUILDER_VALUE(std::string, driverName)
372 };
373
374 // Log files and their associated filter
375 struct LoaderLogConfiguration {
376 BUILDER_VECTOR(std::string, destinations, destination)
377 BUILDER_VECTOR(std::string, filters, filter)
378 };
379 struct AppSpecificSettings {
380 BUILDER_VECTOR(std::string, app_keys, app_key)
381 BUILDER_VECTOR(LoaderSettingsLayerConfiguration, layer_configurations, layer_configuration)
382 BUILDER_VECTOR(LoaderSettingsDriverConfiguration, driver_configurations, driver_configuration)
383 BUILDER_VECTOR(LoaderSettingsDeviceConfiguration, device_configurations, device_configuration)
384 BUILDER_VALUE(bool, additional_drivers_use_exclusively)
385 BUILDER_VECTOR(std::string, stderr_log, stderr_log_filter)
386 BUILDER_VECTOR(LoaderLogConfiguration, log_configurations, log_configuration)
387 };
388
389 struct LoaderSettings {
390 BUILDER_VALUE(ManifestVersion, file_format_version)
391 BUILDER_VECTOR(AppSpecificSettings, app_specific_settings, app_specific_setting);
392 };
393
394 struct PlatformShimWrapper {
395 PlatformShimWrapper(fs::FileSystemManager& file_system_manager, const char* log_filter) noexcept;
396 PlatformShimWrapper(PlatformShimWrapper const&) = delete;
397 PlatformShimWrapper& operator=(PlatformShimWrapper const&) = delete;
398
399 // Convenience
400 PlatformShim* operator->() { return platform_shim; }
401
402 LibraryWrapper shim_library;
403 PlatformShim* platform_shim = nullptr;
404 EnvVarWrapper loader_logging;
405 };
406
407 template <typename BinaryObject, typename GetTestBinaryFunc, typename GetNewTestBinaryFunc>
408 struct TestBinaryHandle {
409 TestBinaryHandle() noexcept {}
410 TestBinaryHandle(std::filesystem::path const& binary_path) noexcept;
411
412 BinaryObject& get_test_binary() noexcept {
413 assert(proc_addr_get_test_binary != NULL && "symbol must be loaded before use");
414 return *proc_addr_get_test_binary();
415 }
416 BinaryObject& reset() noexcept {
417 assert(proc_addr_reset_binary != NULL && "symbol must be loaded before use");
418 return *proc_addr_reset_binary();
419 }
420 std::filesystem::path get_full_path() noexcept { return library.get_path(); }
421 std::filesystem::path get_manifest_path() noexcept { return manifest_path; }
422 std::filesystem::path get_shimmed_manifest_path() noexcept { return shimmed_manifest_path; }
423
424 // Must use statically
425 LibraryWrapper library;
426 GetTestBinaryFunc proc_addr_get_test_binary = nullptr;
427 GetNewTestBinaryFunc proc_addr_reset_binary = nullptr;
428 std::filesystem::path
429 manifest_path; // path to the manifest file is on the actual filesystem (aka <build_folder>/tests/framework/<...>)
430 std::filesystem::path
431 shimmed_manifest_path; // path to where the loader will find the manifest file (eg /usr/local/share/vulkan/<...>)
432 };
433
434 using TestICDHandle = TestBinaryHandle<TestICD, GetTestICDFunc, GetNewTestICDFunc>;
435 using TestLayerHandle = TestBinaryHandle<TestLayer, GetTestLayerFunc, GetNewTestLayerFunc>;
436
437 struct ManifestOptions {
438 BUILDER_VALUE(std::filesystem::path, json_name);
439 BUILDER_VALUE_WITH_DEFAULT(ManifestDiscoveryType, discovery_type, ManifestDiscoveryType::generic);
440 BUILDER_VALUE(bool, is_fake);
441 // If discovery type is env-var, is_dir controls whether to use the path to the file or folder the manifest is in
442 BUILDER_VALUE(bool, is_dir);
443 BUILDER_VALUE_WITH_DEFAULT(LibraryPathType, library_path_type, LibraryPathType::absolute);
444 };
445
446 struct FrameworkSettings {
447 BUILDER_VALUE_WITH_DEFAULT(const char*, log_filter, "all");
448 BUILDER_VALUE_WITH_DEFAULT(bool, run_as_if_with_elevated_privleges, false);
449
450 #if TESTING_COMMON_UNIX_PLATFORMS
451 BUILDER_VALUE_WITH_DEFAULT(std::string, home_env_var, "/home/fake_home");
452 #if !defined(__APPLE__)
453 BUILDER_VALUE(std::string, xdg_config_home_env_var);
454 BUILDER_VALUE(std::string, xdg_config_dirs_env_var);
455 BUILDER_VALUE(std::string, xdg_data_home_env_var);
456 BUILDER_VALUE(std::string, xdg_data_dirs_env_var);
457 #endif
458 #endif
459 };
460
461 struct FrameworkEnvironment {
462 FrameworkEnvironment() noexcept; // default is to enable VK_LOADER_DEBUG=all and enable the default search paths
463 FrameworkEnvironment(const FrameworkSettings& settings) noexcept;
464 ~FrameworkEnvironment();
465 // Delete copy constructors - this class should never move after being created
466 FrameworkEnvironment(const FrameworkEnvironment&) = delete;
467 FrameworkEnvironment& operator=(const FrameworkEnvironment&) = delete;
468
469 TestICD& add_icd(std::filesystem::path const& path, ManifestOptions args = ManifestOptions{},
470 ManifestICD manifest = ManifestICD{}) noexcept;
471
472 void add_implicit_layer(ManifestOptions args, ManifestLayer layer_manifest) noexcept;
473 void add_explicit_layer(ManifestOptions args, ManifestLayer layer_manifest) noexcept;
474
475 // Resets the current settings with the values contained in loader_settings.
476 // Write_to_secure_location determines whether to write to the secure or unsecure settings folder.
477 void write_settings_file(std::string const& file_contents, bool write_to_secure_location);
478
479 // Apply any changes made to FrameworkEnvironment's loader_settings member.
480 // By default writes to the secure settings location
481 void update_loader_settings(const LoaderSettings& loader_settings, bool write_to_secure_location = true) noexcept;
482
483 void remove_loader_settings();
484
485 // Creates a file called `file_name` for the given `category` in the given `location` with `source_string` as the contents
486 void write_file_from_string(std::string const& source_string, ManifestCategory category, ManifestLocation location,
487 std::string const& file_name);
488 // Creates a file called `file_name` for the given `category` in the given `location` with contents copied from `source_file`
489 void write_file_from_source(const char* source_file, ManifestCategory category, ManifestLocation location,
490 std::string const& file_name);
491
492 TestICD& get_test_icd(size_t index = 0) noexcept;
493 TestICD& reset_icd(size_t index = 0) noexcept;
494 std::filesystem::path get_test_icd_path(size_t index = 0) noexcept;
495 std::filesystem::path get_icd_manifest_path(size_t index = 0) noexcept;
496 std::filesystem::path get_shimmed_icd_manifest_path(size_t index = 0) noexcept;
497
498 TestLayer& get_test_layer(size_t index = 0) noexcept;
499 TestLayer& reset_layer(size_t index = 0) noexcept;
500 std::filesystem::path get_test_layer_path(size_t index = 0) noexcept;
501 std::filesystem::path get_layer_manifest_path(size_t index = 0) noexcept;
502 std::filesystem::path get_shimmed_layer_manifest_path(size_t index = 0) noexcept;
503
504 fs::Folder& get_folder(ManifestLocation location) noexcept;
505 fs::Folder const& get_folder(ManifestLocation location) const noexcept;
506 #if defined(__APPLE__)
507 // Set the path of the app bundle to the appropriate test framework bundle
508 void setup_macos_bundle() noexcept;
509 #endif
510
511 void add_symlink(ManifestLocation location, std::filesystem::path const& target, std::filesystem::path const& link_name);
512
513 FrameworkSettings settings;
514
515 fs::FileSystemManager file_system_manager;
516
517 // Query the global extensions
518 // Optional: use layer_name to query the extensions of a specific layer
519 std::vector<VkExtensionProperties> GetInstanceExtensions(uint32_t count, const char* layer_name = nullptr);
520 // Query the available layers
521 std::vector<VkLayerProperties> GetLayerProperties(uint32_t count);
522
523 PlatformShimWrapper platform_shim;
524
525 std::vector<TestICDHandle> icds;
526 std::vector<TestLayerHandle> layers;
527
528 DebugUtilsLogger debug_log;
529 VulkanFunctions vulkan_functions;
530
531 EnvVarWrapper env_var_vk_icd_filenames{"VK_DRIVER_FILES"};
532 EnvVarWrapper add_env_var_vk_icd_filenames{"VK_ADD_DRIVER_FILES"};
533 EnvVarWrapper env_var_vk_layer_paths{"VK_LAYER_PATH"};
534 EnvVarWrapper add_env_var_vk_layer_paths{"VK_ADD_LAYER_PATH"};
535 EnvVarWrapper env_var_vk_implicit_layer_paths{"VK_IMPLICIT_LAYER_PATH"};
536 EnvVarWrapper add_env_var_vk_implicit_layer_paths{"VK_ADD_IMPLICIT_LAYER_PATH"};
537 EnvVarWrapper env_var_vk_loader_device_id_filter{"VK_LOADER_DEVICE_ID_FILTER"};
538 EnvVarWrapper env_var_vk_loader_vendor_id_filter{"VK_LOADER_VENDOR_ID_FILTER"};
539 EnvVarWrapper env_var_vk_loader_driver_id_filter{"VK_LOADER_DRIVER_ID_FILTER"};
540
541 #if TESTING_COMMON_UNIX_PLATFORMS
542 EnvVarWrapper env_var_home{"HOME", "/home/fake_home"};
543 #if !defined(__APPLE__)
544 EnvVarWrapper env_var_xdg_config_home{"XDG_CONFIG_HOME"};
545 EnvVarWrapper env_var_xdg_config_dirs{"XDG_CONFIG_DIRS"};
546 EnvVarWrapper env_var_xdg_data_home{"XDG_DATA_HOME"};
547 EnvVarWrapper env_var_xdg_data_dirs{"XDG_DATA_DIRS"};
548 #endif
549 std::string secure_manifest_base_location;
550 std::string unsecure_manifest_base_location;
551 #endif
552
553 LoaderSettings loader_settings; // the current settings written to disk
554 private:
555 uint32_t created_layer_count = 0;
556 void add_layer_impl(ManifestOptions args, ManifestLayer manifest, ManifestCategory category);
557
558 static ManifestLocation map_discovery_type_to_location(ManifestDiscoveryType type, ManifestCategory category);
559 };
560
561 // Create a surface using a platform specific API
562 // api_selection: optionally provide a VK_USE_PLATFORM_XXX string to select which API to create a surface with.
563 // defaults to Metal on macOS and XCB on linux if not provided
564 // Returns an VkResult with the result of surface creation
565 // returns VK_ERROR_EXTENSION_NOT_PRESENT if it fails to load the surface creation function
566 VkResult create_surface(InstWrapper& inst, VkSurfaceKHR& out_surface, const char* api_selection = nullptr);
567 // Alternate parameter list for allocation callback tests
568 VkResult create_surface(VulkanFunctions* functions, VkInstance inst, VkSurfaceKHR& surface, const char* api_selection = nullptr);
569
570 VkResult create_debug_callback(InstWrapper& inst, const VkDebugReportCallbackCreateInfoEXT& create_info,
571 VkDebugReportCallbackEXT& callback);