Pass full registry path to DriverInfoWindows constructor

Related-To: NEO-4457
Change-Id: I6b417b3a571349947bbbfc94b10c478b8793c2de
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2020-03-16 10:11:27 +01:00
committed by sys_ocldev
parent e55d4bf234
commit 2dbee6d7c1
3 changed files with 25 additions and 6 deletions

View File

@ -15,6 +15,8 @@
namespace NEO {
DriverInfoWindows::DriverInfoWindows(std::string &&fullPath) : path(DriverInfoWindows::trimRegistryKey(fullPath)) {}
DriverInfo *DriverInfo::create(OSInterface *osInterface) {
if (osInterface) {
auto wddm = osInterface->get()->getWddm();
@ -22,11 +24,10 @@ DriverInfo *DriverInfo::create(OSInterface *osInterface) {
std::string path(wddm->getDeviceRegistryPath());
auto result = new DriverInfoWindows();
path = result->trimRegistryKey(path);
auto driverInfo = new DriverInfoWindows(std::move(path));
result->setRegistryReader(new RegistryReader(false, path));
return result;
driverInfo->setRegistryReader(new RegistryReader(false, driverInfo->getRegistryPath()));
return driverInfo;
}
return nullptr;
@ -52,4 +53,9 @@ std::string DriverInfoWindows::getDeviceName(std::string defaultName) {
std::string DriverInfoWindows::getVersion(std::string defaultVersion) {
return registryReader.get()->getSetting("DriverVersion", defaultVersion);
};
const std::string &DriverInfoWindows::getRegistryPath() const {
return path;
}
} // namespace NEO

View File

@ -18,13 +18,16 @@ class SettingsReader;
class DriverInfoWindows : public DriverInfo {
public:
DriverInfoWindows(std::string &&path);
std::string getDeviceName(std::string defaultName);
std::string getVersion(std::string defaultVersion);
void setRegistryReader(SettingsReader *reader);
std::string trimRegistryKey(std::string key);
const std::string &getRegistryPath() const;
protected:
static std::string trimRegistryKey(std::string key);
const std::string path;
std::unique_ptr<SettingsReader> registryReader;
};

View File

@ -99,7 +99,7 @@ class RegistryReaderMock : public SettingsReader {
};
TEST(DriverInfo, GivenDriverInfoWhenThenReturnNonNullptr) {
DriverInfoWindows driverInfo;
DriverInfoWindows driverInfo("");
RegistryReaderMock *registryReaderMock = new RegistryReaderMock();
driverInfo.setRegistryReader(registryReaderMock);
@ -119,6 +119,15 @@ TEST(DriverInfo, GivenDriverInfoWhenThenReturnNonNullptr) {
EXPECT_TRUE(registryReaderMock->properVersionKey);
};
TEST(DriverInfo, givenFullPathToRegistryWhenCreatingDriverInfoWindowsThenTheRegistryPathIsTrimmed) {
std::string registryPath = "Path\\In\\Registry";
std::string fullRegistryPath = "\\REGISTRY\\MACHINE\\" + registryPath;
std::string expectedTrimmedRegistryPath = registryPath;
DriverInfoWindows driverInfo(std::move(fullRegistryPath));
EXPECT_STREQ(expectedTrimmedRegistryPath.c_str(), driverInfo.getRegistryPath().c_str());
};
TEST(DriverInfo, givenInitializedOsInterfaceWhenCreateDriverInfoThenReturnDriverInfoWindowsNotNullptr) {
MockExecutionEnvironment executionEnvironment;
@ -144,6 +153,7 @@ TEST(DriverInfo, givenNotInitializedOsInterfaceWhenCreateDriverInfoThenReturnDri
class MockDriverInfoWindows : public DriverInfoWindows {
public:
MockDriverInfoWindows() : DriverInfoWindows("") {}
const char *getRegistryReaderRegKey() {
return reader->getRegKey();
}