Skip to content

Commit b77d86a

Browse files
Cleanup add_layer_impl and add_icd in tests
1 parent 4c138ad commit b77d86a

File tree

2 files changed

+129
-129
lines changed

2 files changed

+129
-129
lines changed

tests/framework/test_environment.cpp

Lines changed: 127 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@
2828
#include "test_environment.h"
2929

3030
#include <array>
31+
#include <filesystem>
3132
#include <fstream>
3233
#include <string>
3334
#include <utility>
3435

3536
#include "json_writer.h"
37+
#include "test_defines.h"
3638

3739
InstWrapper::InstWrapper(VulkanFunctions& functions, VkAllocationCallbacks* callbacks) noexcept
3840
: functions(&functions), callbacks(callbacks) {}
@@ -335,46 +337,97 @@ FrameworkEnvironment::~FrameworkEnvironment() {
335337
platform_shim->is_during_destruction = true;
336338
}
337339

338-
TestICD& FrameworkEnvironment::add_icd(std::filesystem::path const& path, ManifestOptions args, ManifestICD manifest) noexcept {
339-
manifest.set_lib_path(path);
340-
341-
if (args.json_name.empty()) {
342-
args.json_name = "test_icd_" + std::to_string(icds.size()) + ".json";
343-
}
344-
345-
size_t cur_icd_index = icds.size();
346-
fs::Folder* fs_ptr = &get_folder(ManifestLocation::driver);
347-
switch (args.discovery_type) {
340+
ManifestLocation FrameworkEnvironment::map_discovery_type_to_location(ManifestDiscoveryType discovery_type,
341+
ManifestCategory category) {
342+
switch (discovery_type) {
348343
case (ManifestDiscoveryType::env_var):
344+
switch (category) {
345+
case (ManifestCategory::explicit_layer):
346+
return ManifestLocation::explicit_layer_env_var;
347+
case (ManifestCategory::implicit_layer):
348+
return ManifestLocation::implicit_layer_env_var;
349+
case (ManifestCategory::icd):
350+
return ManifestLocation::driver_env_var;
351+
default:
352+
return ManifestLocation::null;
353+
}
349354
case (ManifestDiscoveryType::add_env_var):
350-
fs_ptr = &get_folder(ManifestLocation::driver_env_var);
351-
break;
355+
switch (category) {
356+
case (ManifestCategory::explicit_layer):
357+
return ManifestLocation::explicit_layer_add_env_var;
358+
case (ManifestCategory::implicit_layer):
359+
return ManifestLocation::implicit_layer_add_env_var;
360+
case (ManifestCategory::icd):
361+
return ManifestLocation::driver_env_var;
362+
default:
363+
return ManifestLocation::null;
364+
}
352365
#if defined(WIN32)
353366
case (ManifestDiscoveryType::windows_app_package):
354-
fs_ptr = &get_folder(ManifestLocation::windows_app_package);
355-
break;
367+
return ManifestLocation::windows_app_package;
356368
#endif
357369
case (ManifestDiscoveryType::override_folder):
358-
fs_ptr = &get_folder(ManifestLocation::override_layer);
359-
break;
370+
return ManifestLocation::override_layer;
360371
#if defined(__APPLE__)
361372
case (ManifestDiscoveryType::macos_bundle):
362-
fs_ptr = &get_folder(ManifestLocation::macos_bundle);
363-
break;
373+
return ManifestLocation::macos_bundle;
364374
#endif
365375
case (ManifestDiscoveryType::unsecured_generic):
366-
fs_ptr = &get_folder(ManifestLocation::unsecured_driver);
367-
break;
376+
switch (category) {
377+
case (ManifestCategory::explicit_layer):
378+
return ManifestLocation::unsecured_explicit_layer;
379+
case (ManifestCategory::implicit_layer):
380+
return ManifestLocation::unsecured_implicit_layer;
381+
case (ManifestCategory::icd):
382+
return ManifestLocation::unsecured_driver;
383+
case (ManifestCategory::settings):
384+
return ManifestLocation::unsecured_settings;
385+
default:
386+
return ManifestLocation::null;
387+
}
368388
case (ManifestDiscoveryType::null_dir):
369389
case (ManifestDiscoveryType::none):
370-
fs_ptr = &get_folder(ManifestLocation::null);
371-
break;
390+
return ManifestLocation::null;
391+
default:
372392
case (ManifestDiscoveryType::generic):
373-
fs_ptr = &get_folder(ManifestLocation::driver);
374-
break;
393+
switch (category) {
394+
case (ManifestCategory::explicit_layer):
395+
return ManifestLocation::explicit_layer;
396+
case (ManifestCategory::implicit_layer):
397+
return ManifestLocation::implicit_layer;
398+
case (ManifestCategory::icd):
399+
return ManifestLocation::driver;
400+
case (ManifestCategory::settings):
401+
return ManifestLocation::settings_location;
402+
default:
403+
return ManifestLocation::null;
404+
}
375405
}
376-
auto& folder = *fs_ptr;
406+
}
377407

408+
TestICD& FrameworkEnvironment::add_icd(std::filesystem::path const& path, ManifestOptions args, ManifestICD manifest) noexcept {
409+
manifest.set_lib_path(path);
410+
411+
if (args.json_name.empty()) {
412+
args.json_name = "test_icd_" + std::to_string(icds.size()) + ".json";
413+
}
414+
415+
size_t cur_icd_index = icds.size();
416+
auto& folder = get_folder(map_discovery_type_to_location(args.discovery_type, ManifestCategory::icd));
417+
418+
if (args.discovery_type == ManifestDiscoveryType::env_var) {
419+
if (args.is_dir) {
420+
env_var_vk_icd_filenames.add_to_list(folder.location());
421+
} else {
422+
env_var_vk_icd_filenames.add_to_list(folder.location() / args.json_name);
423+
}
424+
} else if (args.discovery_type == ManifestDiscoveryType::add_env_var) {
425+
if (args.is_dir) {
426+
add_env_var_vk_icd_filenames.add_to_list(folder.location());
427+
} else {
428+
add_env_var_vk_icd_filenames.add_to_list(folder.location() / args.json_name);
429+
}
430+
}
378431
if (!args.is_fake) {
379432
std::filesystem::path new_lib_name = manifest.lib_path.stem();
380433
new_lib_name += "_";
@@ -406,53 +459,29 @@ TestICD& FrameworkEnvironment::add_icd(std::filesystem::path const& path, Manife
406459
if (args.discovery_type != ManifestDiscoveryType::none) {
407460
icds.back().manifest_path = folder.write_manifest(args.json_name, manifest.get_manifest_str());
408461
icds.back().shimmed_manifest_path = icds.back().manifest_path;
409-
switch (args.discovery_type) {
410-
case (ManifestDiscoveryType::generic):
411-
#if defined(WIN32)
412-
platform_shim->add_manifest_to_registry(ManifestCategory::icd, icds.back().manifest_path);
413-
#elif TESTING_COMMON_UNIX_PLATFORMS
414-
icds.back().shimmed_manifest_path =
415-
file_system_manager.get_path_redirect_by_manifest_location(ManifestLocation::driver) / args.json_name;
416-
#endif
417-
break;
418-
case (ManifestDiscoveryType::unsecured_generic):
419-
#if defined(WIN32)
420-
platform_shim->add_unsecured_manifest_to_registry(ManifestCategory::icd, icds.back().manifest_path);
421-
#elif TESTING_COMMON_UNIX_PLATFORMS
422-
icds.back().shimmed_manifest_path =
423-
file_system_manager.get_path_redirect_by_manifest_location(ManifestLocation::unsecured_driver) / args.json_name;
424-
#endif
425-
break;
426-
case (ManifestDiscoveryType::env_var):
427-
if (args.is_dir) {
428-
env_var_vk_icd_filenames.add_to_list(folder.location());
429-
} else {
430-
env_var_vk_icd_filenames.add_to_list(folder.location() / args.json_name);
431-
}
432-
break;
433-
case (ManifestDiscoveryType::add_env_var):
434-
if (args.is_dir) {
435-
add_env_var_vk_icd_filenames.add_to_list(folder.location());
436-
} else {
437-
add_env_var_vk_icd_filenames.add_to_list(folder.location() / args.json_name);
438-
}
439-
break;
440-
break;
441462

442463
#if defined(WIN32)
443-
case (ManifestDiscoveryType::windows_app_package):
444-
platform_shim->set_app_package_path(folder.location());
445-
break;
446-
#endif
447-
#if defined(__APPLE__)
448-
case (ManifestDiscoveryType::macos_bundle): // macos_bundle contents are always discoverable by the loader
464+
// only add the manifest to the registry if its a generic location (as if it was installed) - both system and user local
465+
if (args.discovery_type == ManifestDiscoveryType::generic) {
466+
platform_shim->add_manifest_to_registry(ManifestCategory::icd, icds.back().manifest_path);
467+
}
468+
if (args.discovery_type == ManifestDiscoveryType::unsecured_generic) {
469+
platform_shim->add_unsecured_manifest_to_registry(ManifestCategory::icd, icds.back().manifest_path);
470+
}
471+
if (args.discovery_type == ManifestDiscoveryType::windows_app_package) {
472+
platform_shim->set_app_package_path(folder.location());
473+
}
449474
#endif
450-
case (ManifestDiscoveryType::override_folder): // should be found through override layer/settings file, not 'normal'
451-
// search paths
452-
case (ManifestDiscoveryType::null_dir):
453-
case (ManifestDiscoveryType::none):
454-
break;
475+
#if TESTING_COMMON_UNIX_PLATFORMS
476+
if (args.discovery_type == ManifestDiscoveryType::generic ||
477+
args.discovery_type == ManifestDiscoveryType::unsecured_generic) {
478+
icds.back().shimmed_manifest_path =
479+
file_system_manager.get_path_redirect_by_manifest_location(
480+
args.discovery_type == ManifestDiscoveryType::unsecured_generic ? ManifestLocation::driver
481+
: ManifestLocation::unsecured_driver) /
482+
args.json_name;
455483
}
484+
#endif
456485
}
457486
return icds.back().get_test_binary();
458487
}
@@ -470,63 +499,26 @@ void FrameworkEnvironment::add_layer_impl(ManifestOptions args, ManifestLayer ma
470499
created_layer_count++;
471500
}
472501

473-
fs::Folder* fs_ptr = &get_folder(ManifestLocation::explicit_layer);
474-
EnvVarWrapper* env_var_to_use = nullptr;
475-
switch (args.discovery_type) {
476-
case (ManifestDiscoveryType::generic):
477-
if (category == ManifestCategory::implicit_layer) fs_ptr = &get_folder(ManifestLocation::implicit_layer);
478-
break;
479-
case (ManifestDiscoveryType::env_var):
480-
if (category == ManifestCategory::explicit_layer) {
481-
fs_ptr = &get_folder(ManifestLocation::explicit_layer_env_var);
482-
env_var_to_use = &env_var_vk_layer_paths;
483-
} else if (category == ManifestCategory::implicit_layer) {
484-
fs_ptr = &get_folder(ManifestLocation::implicit_layer_env_var);
485-
env_var_to_use = &env_var_vk_implicit_layer_paths;
486-
}
487-
if (args.is_dir) {
488-
env_var_to_use->add_to_list(fs_ptr->location());
489-
} else {
490-
env_var_to_use->add_to_list(fs_ptr->location() / args.json_name);
491-
}
492-
break;
493-
case (ManifestDiscoveryType::add_env_var):
494-
if (category == ManifestCategory::explicit_layer) {
495-
fs_ptr = &get_folder(ManifestLocation::explicit_layer_add_env_var);
496-
env_var_to_use = &add_env_var_vk_layer_paths;
497-
} else if (category == ManifestCategory::implicit_layer) {
498-
fs_ptr = &get_folder(ManifestLocation::implicit_layer_add_env_var);
499-
env_var_to_use = &add_env_var_vk_implicit_layer_paths;
500-
}
501-
if (args.is_dir) {
502-
env_var_to_use->add_to_list(fs_ptr->location());
503-
} else {
504-
env_var_to_use->add_to_list(fs_ptr->location() / args.json_name);
505-
}
506-
break;
507-
case (ManifestDiscoveryType::override_folder):
508-
fs_ptr = &get_folder(ManifestLocation::override_layer);
509-
break;
510-
#if defined(__APPLE__)
511-
case (ManifestDiscoveryType::macos_bundle):
512-
fs_ptr = &(get_folder(ManifestLocation::macos_bundle));
513-
break;
514-
#endif
515-
case (ManifestDiscoveryType::unsecured_generic):
516-
fs_ptr = &(get_folder(category == ManifestCategory::implicit_layer ? ManifestLocation::unsecured_implicit_layer
517-
: ManifestLocation::unsecured_explicit_layer));
518-
break;
519-
#if defined(WIN32)
520-
case (ManifestDiscoveryType::windows_app_package):
521-
fs_ptr = &(get_folder(ManifestLocation::windows_app_package));
522-
break;
523-
#endif
524-
case (ManifestDiscoveryType::none):
525-
case (ManifestDiscoveryType::null_dir):
526-
fs_ptr = &(get_folder(ManifestLocation::null));
527-
break;
502+
auto& folder = get_folder(map_discovery_type_to_location(args.discovery_type, category));
503+
504+
if (args.discovery_type == ManifestDiscoveryType::env_var || args.discovery_type == ManifestDiscoveryType::add_env_var) {
505+
std::filesystem::path path_to_add = folder.location();
506+
if (!args.is_dir) {
507+
path_to_add /= args.json_name;
508+
}
509+
510+
EnvVarWrapper* env_var_to_use = nullptr;
511+
if (args.discovery_type == ManifestDiscoveryType::env_var && category == ManifestCategory::explicit_layer) {
512+
env_var_vk_layer_paths.add_to_list(path_to_add);
513+
} else if (args.discovery_type == ManifestDiscoveryType::env_var && category == ManifestCategory::implicit_layer) {
514+
env_var_vk_implicit_layer_paths.add_to_list(path_to_add);
515+
} else if (args.discovery_type == ManifestDiscoveryType::add_env_var && category == ManifestCategory::explicit_layer) {
516+
add_env_var_vk_layer_paths.add_to_list(path_to_add);
517+
} else if (args.discovery_type == ManifestDiscoveryType::add_env_var && category == ManifestCategory::implicit_layer) {
518+
add_env_var_vk_implicit_layer_paths.add_to_list(path_to_add);
519+
}
528520
}
529-
auto& folder = *fs_ptr;
521+
530522
size_t new_layers_start = layers.size();
531523
for (auto& layer : manifest.layers) {
532524
if (!layer.lib_path.empty()) {
@@ -584,12 +576,18 @@ void FrameworkEnvironment::add_layer_impl(ManifestOptions args, ManifestLayer ma
584576
layers.at(i).manifest_path = layer_manifest_loc;
585577
layers.at(i).shimmed_manifest_path = layer_manifest_loc;
586578
#if TESTING_COMMON_UNIX_PLATFORMS
587-
if (args.discovery_type == ManifestDiscoveryType::generic) {
579+
if (args.discovery_type == ManifestDiscoveryType::generic ||
580+
args.discovery_type == ManifestDiscoveryType::unsecured_generic) {
581+
ManifestLocation location = ManifestLocation::null;
582+
if (args.discovery_type == ManifestDiscoveryType::generic) {
583+
location = (category == ManifestCategory::explicit_layer ? ManifestLocation::explicit_layer
584+
: ManifestLocation::implicit_layer);
585+
} else if (args.discovery_type == ManifestDiscoveryType::unsecured_generic) {
586+
location = (category == ManifestCategory::explicit_layer ? ManifestLocation::unsecured_explicit_layer
587+
: ManifestLocation::unsecured_implicit_layer);
588+
}
588589
layers.at(i).shimmed_manifest_path =
589-
((category == ManifestCategory::implicit_layer)
590-
? file_system_manager.get_path_redirect_by_manifest_location(ManifestLocation::implicit_layer)
591-
: file_system_manager.get_path_redirect_by_manifest_location(ManifestLocation::explicit_layer)) /
592-
args.json_name;
590+
file_system_manager.get_path_redirect_by_manifest_location(location) / args.json_name;
593591
}
594592
#endif
595593
}

tests/framework/test_environment.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,8 @@ struct FrameworkEnvironment {
554554
private:
555555
uint32_t created_layer_count = 0;
556556
void add_layer_impl(ManifestOptions args, ManifestLayer manifest, ManifestCategory category);
557+
558+
static ManifestLocation map_discovery_type_to_location(ManifestDiscoveryType type, ManifestCategory category);
557559
};
558560

559561
// Create a surface using a platform specific API

0 commit comments

Comments
 (0)