From 294045071b2360830d76d8788dbd8d9310f94824 Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Thu, 1 Jul 2021 18:26:01 +0000 Subject: [PATCH] Improve driverstore compatibility checker make checker case-insensitive handle HostDriverStore scenarios Related-To: NEO-5182, NEO-6025 Signed-off-by: Mateusz Jablonski --- .../os_interface/windows/wddm20_tests.cpp | 73 ++++++++++++++----- .../windows/driver_info_windows.cpp | 12 ++- 2 files changed, 66 insertions(+), 19 deletions(-) diff --git a/opencl/test/unit_test/os_interface/windows/wddm20_tests.cpp b/opencl/test/unit_test/os_interface/windows/wddm20_tests.cpp index fcc4c749a1..1213cacc29 100644 --- a/opencl/test/unit_test/os_interface/windows/wddm20_tests.cpp +++ b/opencl/test/unit_test/os_interface/windows/wddm20_tests.cpp @@ -1494,28 +1494,31 @@ TEST_F(WddmTest, GivenResidencyLoggingEnabledWhenMakeResidentAndWaitPagingThenEx EXPECT_EQ(MockGdi::pagingFenceReturnValue, logger->startWaitPagingFenceSave); } -TEST(DiscoverDevices, whenDriverInfoHasIncompatibleDriverStoreThenHwDeviceIdIsNotCreated) { - - class MockRegistryReader : public SettingsReader { - public: - std::string getSetting(const char *settingName, const std::string &value) override { - std::string key(settingName); - if (key == "DriverStorePathForComputeRuntime") { - return driverStorePath; - } - return value; +class MockRegistryReaderWithDriverStorePath : public SettingsReader { + public: + MockRegistryReaderWithDriverStorePath(const char *driverStorePathArg) : driverStorePath(driverStorePathArg){}; + std::string getSetting(const char *settingName, const std::string &value) override { + std::string key(settingName); + if (key == "DriverStorePathForComputeRuntime") { + return driverStorePath; + } else if (key == "OpenCLDriverName") { + return driverStorePath; } + return value; + } - bool getSetting(const char *settingName, bool defaultValue) override { return defaultValue; }; - int64_t getSetting(const char *settingName, int64_t defaultValue) override { return defaultValue; }; - int32_t getSetting(const char *settingName, int32_t defaultValue) override { return defaultValue; }; - const char *appSpecificLocation(const std::string &name) override { return name.c_str(); }; + bool getSetting(const char *settingName, bool defaultValue) override { return defaultValue; }; + int64_t getSetting(const char *settingName, int64_t defaultValue) override { return defaultValue; }; + int32_t getSetting(const char *settingName, int32_t defaultValue) override { return defaultValue; }; + const char *appSpecificLocation(const std::string &name) override { return name.c_str(); }; - std::string driverStorePath = "driverStore\\0x8086"; - }; + const std::string driverStorePath; +}; + +TEST(DiscoverDevices, whenDriverInfoHasIncompatibleDriverStoreThenHwDeviceIdIsNotCreated) { VariableBackup createFuncBackup{&DriverInfoWindows::createRegistryReaderFunc}; DriverInfoWindows::createRegistryReaderFunc = [](const std::string &) -> std::unique_ptr { - return std::make_unique(); + return std::make_unique("driverStore\\0x8086"); }; VariableBackup currentLibraryPathBackup(&SysCalls::currentLibraryPath); currentLibraryPathBackup = L"driverStore\\different_driverStore\\myLib.dll"; @@ -1524,6 +1527,42 @@ TEST(DiscoverDevices, whenDriverInfoHasIncompatibleDriverStoreThenHwDeviceIdIsNo EXPECT_TRUE(hwDeviceIds.empty()); } +TEST(DiscoverDevices, givenDifferentCaseInLibPathAndInDriverStorePathWhenDiscoveringDeviceThenHwDeviceIdIsCreated) { + VariableBackup createFuncBackup{&DriverInfoWindows::createRegistryReaderFunc}; + DriverInfoWindows::createRegistryReaderFunc = [](const std::string &) -> std::unique_ptr { + return std::make_unique("\\SystemRoot\\driverStore\\0x8086"); + }; + VariableBackup currentLibraryPathBackup(&SysCalls::currentLibraryPath); + currentLibraryPathBackup = L"\\SyStEmrOOt\\driverstore\\0x8086\\myLib.dll"; + ExecutionEnvironment executionEnvironment; + auto hwDeviceIds = OSInterface::discoverDevices(executionEnvironment); + EXPECT_EQ(1u, hwDeviceIds.size()); +} + +TEST(DiscoverDevices, givenLibFromHostDriverStoreAndRegistryWithDriverStoreWhenDiscoveringDeviceThenHwDeviceIdIsCreated) { + VariableBackup createFuncBackup{&DriverInfoWindows::createRegistryReaderFunc}; + DriverInfoWindows::createRegistryReaderFunc = [](const std::string &) -> std::unique_ptr { + return std::make_unique("\\SystemRoot\\driverStore\\0x8086"); + }; + VariableBackup currentLibraryPathBackup(&SysCalls::currentLibraryPath); + currentLibraryPathBackup = L"\\SystemRoot\\hostdriverStore\\0x8086\\myLib.dll"; + ExecutionEnvironment executionEnvironment; + auto hwDeviceIds = OSInterface::discoverDevices(executionEnvironment); + EXPECT_EQ(1u, hwDeviceIds.size()); +} + +TEST(DiscoverDevices, givenLibFromDriverStoreAndRegistryWithHostDriverStoreWhenDiscoveringDeviceThenHwDeviceIdIsCreated) { + VariableBackup createFuncBackup{&DriverInfoWindows::createRegistryReaderFunc}; + DriverInfoWindows::createRegistryReaderFunc = [](const std::string &) -> std::unique_ptr { + return std::make_unique("\\SystemRoot\\driverStore\\0x8086"); + }; + VariableBackup currentLibraryPathBackup(&SysCalls::currentLibraryPath); + currentLibraryPathBackup = L"\\SystemRoot\\hostdriverStore\\0x8086\\myLib.dll"; + ExecutionEnvironment executionEnvironment; + auto hwDeviceIds = OSInterface::discoverDevices(executionEnvironment); + EXPECT_EQ(1u, hwDeviceIds.size()); +} + TEST(VerifyAdapterType, whenAdapterDoesntSupportRenderThenDontCreateHwDeviceId) { auto gdi = std::make_unique(); auto osEnv = std::make_unique(); diff --git a/shared/source/os_interface/windows/driver_info_windows.cpp b/shared/source/os_interface/windows/driver_info_windows.cpp index e54c74923d..24b8aa83c4 100644 --- a/shared/source/os_interface/windows/driver_info_windows.cpp +++ b/shared/source/os_interface/windows/driver_info_windows.cpp @@ -70,13 +70,21 @@ std::string DriverInfoWindows::getVersion(std::string defaultVersion) { }; bool DriverInfoWindows::isCompatibleDriverStore() const { - auto currentLibraryPath = getCurrentLibraryPath(); + auto toLowerAndUnifyDriverStore = [](std::string &input) -> std::string { + std::transform(input.begin(), input.end(), input.begin(), [](unsigned char c) { return std::tolower(c); }); + auto hostDriverStorePos = input.find("\\hostdriverstore\\"); + if (hostDriverStorePos != std::string::npos) { + input.erase(hostDriverStorePos + 1, 4); + } + return input; + }; + auto currentLibraryPath = toLowerAndUnifyDriverStore(getCurrentLibraryPath()); auto openclDriverName = registryReader.get()->getSetting("OpenCLDriverName", std::string{}); if (openclDriverName.empty()) { return false; } - auto driverStorePath = registryReader.get()->getSetting("DriverStorePathForComputeRuntime", currentLibraryPath); + auto driverStorePath = toLowerAndUnifyDriverStore(registryReader.get()->getSetting("DriverStorePathForComputeRuntime", currentLibraryPath)); return currentLibraryPath.find(driverStorePath.c_str()) == 0u; }