Skip to content

Commit 2940450

Browse files
Improve driverstore compatibility checker
make checker case-insensitive handle HostDriverStore scenarios Related-To: NEO-5182, NEO-6025 Signed-off-by: Mateusz Jablonski <[email protected]>
1 parent bcf93a6 commit 2940450

File tree

2 files changed

+66
-19
lines changed

2 files changed

+66
-19
lines changed

opencl/test/unit_test/os_interface/windows/wddm20_tests.cpp

Lines changed: 56 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,28 +1494,31 @@ TEST_F(WddmTest, GivenResidencyLoggingEnabledWhenMakeResidentAndWaitPagingThenEx
14941494
EXPECT_EQ(MockGdi::pagingFenceReturnValue, logger->startWaitPagingFenceSave);
14951495
}
14961496

1497-
TEST(DiscoverDevices, whenDriverInfoHasIncompatibleDriverStoreThenHwDeviceIdIsNotCreated) {
1498-
1499-
class MockRegistryReader : public SettingsReader {
1500-
public:
1501-
std::string getSetting(const char *settingName, const std::string &value) override {
1502-
std::string key(settingName);
1503-
if (key == "DriverStorePathForComputeRuntime") {
1504-
return driverStorePath;
1505-
}
1506-
return value;
1497+
class MockRegistryReaderWithDriverStorePath : public SettingsReader {
1498+
public:
1499+
MockRegistryReaderWithDriverStorePath(const char *driverStorePathArg) : driverStorePath(driverStorePathArg){};
1500+
std::string getSetting(const char *settingName, const std::string &value) override {
1501+
std::string key(settingName);
1502+
if (key == "DriverStorePathForComputeRuntime") {
1503+
return driverStorePath;
1504+
} else if (key == "OpenCLDriverName") {
1505+
return driverStorePath;
15071506
}
1507+
return value;
1508+
}
15081509

1509-
bool getSetting(const char *settingName, bool defaultValue) override { return defaultValue; };
1510-
int64_t getSetting(const char *settingName, int64_t defaultValue) override { return defaultValue; };
1511-
int32_t getSetting(const char *settingName, int32_t defaultValue) override { return defaultValue; };
1512-
const char *appSpecificLocation(const std::string &name) override { return name.c_str(); };
1510+
bool getSetting(const char *settingName, bool defaultValue) override { return defaultValue; };
1511+
int64_t getSetting(const char *settingName, int64_t defaultValue) override { return defaultValue; };
1512+
int32_t getSetting(const char *settingName, int32_t defaultValue) override { return defaultValue; };
1513+
const char *appSpecificLocation(const std::string &name) override { return name.c_str(); };
15131514

1514-
std::string driverStorePath = "driverStore\\0x8086";
1515-
};
1515+
const std::string driverStorePath;
1516+
};
1517+
1518+
TEST(DiscoverDevices, whenDriverInfoHasIncompatibleDriverStoreThenHwDeviceIdIsNotCreated) {
15161519
VariableBackup<decltype(DriverInfoWindows::createRegistryReaderFunc)> createFuncBackup{&DriverInfoWindows::createRegistryReaderFunc};
15171520
DriverInfoWindows::createRegistryReaderFunc = [](const std::string &) -> std::unique_ptr<SettingsReader> {
1518-
return std::make_unique<MockRegistryReader>();
1521+
return std::make_unique<MockRegistryReaderWithDriverStorePath>("driverStore\\0x8086");
15191522
};
15201523
VariableBackup<const wchar_t *> currentLibraryPathBackup(&SysCalls::currentLibraryPath);
15211524
currentLibraryPathBackup = L"driverStore\\different_driverStore\\myLib.dll";
@@ -1524,6 +1527,42 @@ TEST(DiscoverDevices, whenDriverInfoHasIncompatibleDriverStoreThenHwDeviceIdIsNo
15241527
EXPECT_TRUE(hwDeviceIds.empty());
15251528
}
15261529

1530+
TEST(DiscoverDevices, givenDifferentCaseInLibPathAndInDriverStorePathWhenDiscoveringDeviceThenHwDeviceIdIsCreated) {
1531+
VariableBackup<decltype(DriverInfoWindows::createRegistryReaderFunc)> createFuncBackup{&DriverInfoWindows::createRegistryReaderFunc};
1532+
DriverInfoWindows::createRegistryReaderFunc = [](const std::string &) -> std::unique_ptr<SettingsReader> {
1533+
return std::make_unique<MockRegistryReaderWithDriverStorePath>("\\SystemRoot\\driverStore\\0x8086");
1534+
};
1535+
VariableBackup<const wchar_t *> currentLibraryPathBackup(&SysCalls::currentLibraryPath);
1536+
currentLibraryPathBackup = L"\\SyStEmrOOt\\driverstore\\0x8086\\myLib.dll";
1537+
ExecutionEnvironment executionEnvironment;
1538+
auto hwDeviceIds = OSInterface::discoverDevices(executionEnvironment);
1539+
EXPECT_EQ(1u, hwDeviceIds.size());
1540+
}
1541+
1542+
TEST(DiscoverDevices, givenLibFromHostDriverStoreAndRegistryWithDriverStoreWhenDiscoveringDeviceThenHwDeviceIdIsCreated) {
1543+
VariableBackup<decltype(DriverInfoWindows::createRegistryReaderFunc)> createFuncBackup{&DriverInfoWindows::createRegistryReaderFunc};
1544+
DriverInfoWindows::createRegistryReaderFunc = [](const std::string &) -> std::unique_ptr<SettingsReader> {
1545+
return std::make_unique<MockRegistryReaderWithDriverStorePath>("\\SystemRoot\\driverStore\\0x8086");
1546+
};
1547+
VariableBackup<const wchar_t *> currentLibraryPathBackup(&SysCalls::currentLibraryPath);
1548+
currentLibraryPathBackup = L"\\SystemRoot\\hostdriverStore\\0x8086\\myLib.dll";
1549+
ExecutionEnvironment executionEnvironment;
1550+
auto hwDeviceIds = OSInterface::discoverDevices(executionEnvironment);
1551+
EXPECT_EQ(1u, hwDeviceIds.size());
1552+
}
1553+
1554+
TEST(DiscoverDevices, givenLibFromDriverStoreAndRegistryWithHostDriverStoreWhenDiscoveringDeviceThenHwDeviceIdIsCreated) {
1555+
VariableBackup<decltype(DriverInfoWindows::createRegistryReaderFunc)> createFuncBackup{&DriverInfoWindows::createRegistryReaderFunc};
1556+
DriverInfoWindows::createRegistryReaderFunc = [](const std::string &) -> std::unique_ptr<SettingsReader> {
1557+
return std::make_unique<MockRegistryReaderWithDriverStorePath>("\\SystemRoot\\driverStore\\0x8086");
1558+
};
1559+
VariableBackup<const wchar_t *> currentLibraryPathBackup(&SysCalls::currentLibraryPath);
1560+
currentLibraryPathBackup = L"\\SystemRoot\\hostdriverStore\\0x8086\\myLib.dll";
1561+
ExecutionEnvironment executionEnvironment;
1562+
auto hwDeviceIds = OSInterface::discoverDevices(executionEnvironment);
1563+
EXPECT_EQ(1u, hwDeviceIds.size());
1564+
}
1565+
15271566
TEST(VerifyAdapterType, whenAdapterDoesntSupportRenderThenDontCreateHwDeviceId) {
15281567
auto gdi = std::make_unique<MockGdi>();
15291568
auto osEnv = std::make_unique<OsEnvironmentWin>();

shared/source/os_interface/windows/driver_info_windows.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,21 @@ std::string DriverInfoWindows::getVersion(std::string defaultVersion) {
7070
};
7171

7272
bool DriverInfoWindows::isCompatibleDriverStore() const {
73-
auto currentLibraryPath = getCurrentLibraryPath();
73+
auto toLowerAndUnifyDriverStore = [](std::string &input) -> std::string {
74+
std::transform(input.begin(), input.end(), input.begin(), [](unsigned char c) { return std::tolower(c); });
75+
auto hostDriverStorePos = input.find("\\hostdriverstore\\");
76+
if (hostDriverStorePos != std::string::npos) {
77+
input.erase(hostDriverStorePos + 1, 4);
78+
}
79+
return input;
80+
};
81+
auto currentLibraryPath = toLowerAndUnifyDriverStore(getCurrentLibraryPath());
7482
auto openclDriverName = registryReader.get()->getSetting("OpenCLDriverName", std::string{});
7583
if (openclDriverName.empty()) {
7684
return false;
7785
}
7886

79-
auto driverStorePath = registryReader.get()->getSetting("DriverStorePathForComputeRuntime", currentLibraryPath);
87+
auto driverStorePath = toLowerAndUnifyDriverStore(registryReader.get()->getSetting("DriverStorePathForComputeRuntime", currentLibraryPath));
8088
return currentLibraryPath.find(driverStorePath.c_str()) == 0u;
8189
}
8290

0 commit comments

Comments
 (0)