Skip to content

Commit 5bcc1f2

Browse files
Cleanup test layer creation
Move the ManifestLayer out of the TestLayerDetails, as well as drop TestLayerDetails in favor of BinaryCreateArgs, since its the same as for test ICD creation. This makes configuring test layer creation simpler since everything isn't bound to one type. Also dropped the json name from most layers in the tests because that isn't an active part of the test. Simplifies test creation to not need to specify a json file name when it doesn't matter for the purpose of the test. Tests which do care (eg, ones which inspect the log) still can set a name and it is respected. Otherwise, layers will use "test_layer_x.json" as the default name, where x is a number used to distinguish created layers.
1 parent dbb1b37 commit 5bcc1f2

13 files changed

+1528
-1829
lines changed

tests/framework/test_environment.cpp

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#include <array>
3131
#include <fstream>
32+
#include <string>
3233
#include <utility>
3334

3435
#include "json_writer.h"
@@ -462,23 +463,22 @@ TestICD& FrameworkEnvironment::add_icd(std::filesystem::path const& path, Manife
462463
return icds.back().get_test_binary();
463464
}
464465

465-
void FrameworkEnvironment::add_implicit_layer(ManifestLayer layer_manifest, const std::string& json_name) noexcept {
466-
add_layer_impl(TestLayerDetails{layer_manifest, json_name}, ManifestCategory::implicit_layer);
466+
void FrameworkEnvironment::add_implicit_layer(ManifestOptions args, ManifestLayer layer_manifest) noexcept {
467+
add_layer_impl(args, layer_manifest, ManifestCategory::implicit_layer);
467468
}
468-
void FrameworkEnvironment::add_explicit_layer(ManifestLayer layer_manifest, const std::string& json_name) noexcept {
469-
add_layer_impl(TestLayerDetails{layer_manifest, json_name}, ManifestCategory::explicit_layer);
470-
}
471-
void FrameworkEnvironment::add_implicit_layer(TestLayerDetails layer_details) noexcept {
472-
add_layer_impl(layer_details, ManifestCategory::implicit_layer);
473-
}
474-
void FrameworkEnvironment::add_explicit_layer(TestLayerDetails layer_details) noexcept {
475-
add_layer_impl(layer_details, ManifestCategory::explicit_layer);
469+
void FrameworkEnvironment::add_explicit_layer(ManifestOptions args, ManifestLayer layer_manifest) noexcept {
470+
add_layer_impl(args, layer_manifest, ManifestCategory::explicit_layer);
476471
}
477472

478-
void FrameworkEnvironment::add_layer_impl(TestLayerDetails layer_details, ManifestCategory category) {
473+
void FrameworkEnvironment::add_layer_impl(ManifestOptions args, ManifestLayer manifest, ManifestCategory category) {
474+
if (args.json_name.empty()) {
475+
args.json_name = "test_layer_" + std::to_string(created_layer_count) + ".json";
476+
created_layer_count++;
477+
}
478+
479479
fs::Folder* fs_ptr = &get_folder(ManifestLocation::explicit_layer);
480480
EnvVarWrapper* env_var_to_use = nullptr;
481-
switch (layer_details.discovery_type) {
481+
switch (args.discovery_type) {
482482
case (ManifestDiscoveryType::generic):
483483
if (category == ManifestCategory::implicit_layer) fs_ptr = &get_folder(ManifestLocation::implicit_layer);
484484
break;
@@ -490,10 +490,10 @@ void FrameworkEnvironment::add_layer_impl(TestLayerDetails layer_details, Manife
490490
fs_ptr = &get_folder(ManifestLocation::implicit_layer_env_var);
491491
env_var_to_use = &env_var_vk_implicit_layer_paths;
492492
}
493-
if (layer_details.is_dir) {
493+
if (args.is_dir) {
494494
env_var_to_use->add_to_list(fs_ptr->location());
495495
} else {
496-
env_var_to_use->add_to_list(fs_ptr->location() / layer_details.json_name);
496+
env_var_to_use->add_to_list(fs_ptr->location() / args.json_name);
497497
}
498498
break;
499499
case (ManifestDiscoveryType::add_env_var):
@@ -504,10 +504,10 @@ void FrameworkEnvironment::add_layer_impl(TestLayerDetails layer_details, Manife
504504
fs_ptr = &get_folder(ManifestLocation::implicit_layer_add_env_var);
505505
env_var_to_use = &add_env_var_vk_implicit_layer_paths;
506506
}
507-
if (layer_details.is_dir) {
507+
if (args.is_dir) {
508508
env_var_to_use->add_to_list(fs_ptr->location());
509509
} else {
510-
env_var_to_use->add_to_list(fs_ptr->location() / layer_details.json_name);
510+
env_var_to_use->add_to_list(fs_ptr->location() / args.json_name);
511511
}
512512
break;
513513
case (ManifestDiscoveryType::override_folder):
@@ -534,7 +534,7 @@ void FrameworkEnvironment::add_layer_impl(TestLayerDetails layer_details, Manife
534534
}
535535
auto& folder = *fs_ptr;
536536
size_t new_layers_start = layers.size();
537-
for (auto& layer : layer_details.layer_manifest.layers) {
537+
for (auto& layer : manifest.layers) {
538538
if (!layer.lib_path.empty()) {
539539
std::filesystem::path new_lib_path = layer.lib_path.stem();
540540
new_lib_path += "_";
@@ -544,59 +544,58 @@ void FrameworkEnvironment::add_layer_impl(TestLayerDetails layer_details, Manife
544544
auto new_layer_location = folder.copy_file(layer.lib_path, new_lib_path);
545545

546546
#if TESTING_COMMON_UNIX_PLATFORMS
547-
if (layer_details.library_path_type == LibraryPathType::default_search_paths) {
547+
if (args.library_path_type == LibraryPathType::default_search_paths) {
548548
platform_shim->add_system_library(new_lib_path, new_layer_location);
549549
}
550550
#endif
551551
#if defined(WIN32)
552-
if (layer_details.library_path_type == LibraryPathType::default_search_paths) {
552+
if (args.library_path_type == LibraryPathType::default_search_paths) {
553553
SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_USER_DIRS);
554554
AddDllDirectory(new_layer_location.parent_path().native().c_str());
555555
}
556556
#endif
557557

558558
// Don't load the layer binary if using any of the wrap objects layers, since it doesn't export the same interface
559559
// functions
560-
if (!layer_details.is_fake &&
561-
layer.lib_path.stem().string().find(std::filesystem::path(TEST_LAYER_WRAP_OBJECTS).stem().string()) ==
562-
std::string::npos) {
560+
if (!args.is_fake && layer.lib_path.stem().string().find(
561+
std::filesystem::path(TEST_LAYER_WRAP_OBJECTS).stem().string()) == std::string::npos) {
563562
layers.push_back(TestLayerHandle(new_layer_location));
564563
layers.back().reset();
565564
}
566-
if (layer_details.library_path_type == LibraryPathType::relative) {
565+
if (args.library_path_type == LibraryPathType::relative) {
567566
layer.lib_path = std::filesystem::path(".") / new_lib_path;
568-
} else if (layer_details.library_path_type == LibraryPathType::default_search_paths) {
567+
} else if (args.library_path_type == LibraryPathType::default_search_paths) {
569568
layer.lib_path = new_lib_path;
570569
} else {
571570
layer.lib_path = new_layer_location;
572571
}
573572
}
574573
}
575-
if (layer_details.discovery_type != ManifestDiscoveryType::none) {
574+
if (args.discovery_type != ManifestDiscoveryType::none) {
576575
// Write a manifest file to a folder as long as the discovery type isn't none
577-
auto layer_manifest_loc = folder.write_manifest(layer_details.json_name, layer_details.layer_manifest.get_manifest_str());
576+
auto layer_manifest_loc = folder.write_manifest(args.json_name, manifest.get_manifest_str());
578577
#if defined(WIN32)
579578
// only add the manifest to the registry if its a generic location (as if it was installed) - both system and user local
580-
if (layer_details.discovery_type == ManifestDiscoveryType::generic) {
579+
if (args.discovery_type == ManifestDiscoveryType::generic) {
581580
platform_shim->add_manifest_to_registry(category, layer_manifest_loc);
582581
}
583-
if (layer_details.discovery_type == ManifestDiscoveryType::unsecured_generic) {
582+
if (args.discovery_type == ManifestDiscoveryType::unsecured_generic) {
584583
platform_shim->add_unsecured_manifest_to_registry(category, layer_manifest_loc);
585584
}
586-
if (layer_details.discovery_type == ManifestDiscoveryType::windows_app_package) {
585+
if (args.discovery_type == ManifestDiscoveryType::windows_app_package) {
587586
platform_shim->set_app_package_path(folder.location());
588587
}
589588
#endif
590589
for (size_t i = new_layers_start; i < layers.size(); i++) {
591590
layers.at(i).manifest_path = layer_manifest_loc;
592591
layers.at(i).shimmed_manifest_path = layer_manifest_loc;
593592
#if TESTING_COMMON_UNIX_PLATFORMS
594-
if (layer_details.discovery_type == ManifestDiscoveryType::generic) {
593+
if (args.discovery_type == ManifestDiscoveryType::generic) {
595594
layers.at(i).shimmed_manifest_path =
596595
((category == ManifestCategory::implicit_layer)
597596
? file_system_manager.get_path_redirect_by_manifest_location(ManifestLocation::implicit_layer)
598597
: file_system_manager.get_path_redirect_by_manifest_location(ManifestLocation::explicit_layer)) /
599-
layer_details.json_name;
598+
args.json_name;
600599
}
601600
#endif
602601
}

tests/framework/test_environment.h

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -447,18 +447,6 @@ struct ManifestOptions {
447447
BUILDER_VALUE_WITH_DEFAULT(LibraryPathType, library_path_type, LibraryPathType::absolute);
448448
};
449449

450-
struct TestLayerDetails {
451-
TestLayerDetails(ManifestLayer layer_manifest, const std::string& json_name) noexcept
452-
: layer_manifest(layer_manifest), json_name(json_name) {}
453-
BUILDER_VALUE(ManifestLayer, layer_manifest);
454-
BUILDER_VALUE_WITH_DEFAULT(std::string, json_name, "test_layer");
455-
BUILDER_VALUE_WITH_DEFAULT(ManifestDiscoveryType, discovery_type, ManifestDiscoveryType::generic);
456-
BUILDER_VALUE(bool, is_fake);
457-
// If discovery type is env-var, is_dir controls whether to use the path to the file or folder the manifest is in
458-
BUILDER_VALUE_WITH_DEFAULT(bool, is_dir, true);
459-
BUILDER_VALUE_WITH_DEFAULT(LibraryPathType, library_path_type, LibraryPathType::absolute);
460-
};
461-
462450
struct FrameworkSettings {
463451
BUILDER_VALUE_WITH_DEFAULT(const char*, log_filter, "all");
464452
BUILDER_VALUE_WITH_DEFAULT(bool, run_as_if_with_elevated_privleges, false);
@@ -485,10 +473,8 @@ struct FrameworkEnvironment {
485473
TestICD& add_icd(std::filesystem::path const& path, ManifestOptions args = ManifestOptions{},
486474
ManifestICD manifest = ManifestICD{}) noexcept;
487475

488-
void add_implicit_layer(ManifestLayer layer_manifest, const std::string& json_name) noexcept;
489-
void add_implicit_layer(TestLayerDetails layer_details) noexcept;
490-
void add_explicit_layer(ManifestLayer layer_manifest, const std::string& json_name) noexcept;
491-
void add_explicit_layer(TestLayerDetails layer_details) noexcept;
476+
void add_implicit_layer(ManifestOptions args, ManifestLayer layer_manifest) noexcept;
477+
void add_explicit_layer(ManifestOptions args, ManifestLayer layer_manifest) noexcept;
492478

493479
// Resets the current settings with the values contained in loader_settings.
494480
// Write_to_secure_location determines whether to write to the secure or unsecure settings folder.
@@ -570,7 +556,8 @@ struct FrameworkEnvironment {
570556

571557
LoaderSettings loader_settings; // the current settings written to disk
572558
private:
573-
void add_layer_impl(TestLayerDetails layer_details, ManifestCategory category);
559+
uint32_t created_layer_count = 0;
560+
void add_layer_impl(ManifestOptions args, ManifestLayer manifest, ManifestCategory category);
574561
};
575562

576563
// Create a surface using a platform specific API

0 commit comments

Comments
 (0)