Skip to content

Commit 154917a

Browse files
Add ULTs for DriverInfoWindows
Change-Id: Id2b4456bdc33e625569eaef6e197101ba63cea7b
1 parent 1251ccc commit 154917a

File tree

4 files changed

+74
-15
lines changed

4 files changed

+74
-15
lines changed

unit_tests/os_interface/windows/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ set(IGDRCL_SRCS_tests_os_interface_windows
2727
${CMAKE_CURRENT_SOURCE_DIR}/os_time_win_tests.cpp
2828
${CMAKE_CURRENT_SOURCE_DIR}/performance_counters_win_tests.cpp
2929
${CMAKE_CURRENT_SOURCE_DIR}/registry_reader_tests.cpp
30+
${CMAKE_CURRENT_SOURCE_DIR}/registry_reader_tests.h
3031
${CMAKE_CURRENT_SOURCE_DIR}/self_lib_win.cpp
3132
${CMAKE_CURRENT_SOURCE_DIR}/wddm_address_space_tests.cpp
3233
${CMAKE_CURRENT_SOURCE_DIR}/wddm_fixture.h

unit_tests/os_interface/windows/driver_info_tests.cpp

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
#include "runtime/os_interface/windows/os_interface.h"
1212
#include "runtime/memory_manager/os_agnostic_memory_manager.h"
1313
#include "runtime/helpers/options.h"
14+
#include "unit_tests/libult/create_command_stream.h"
1415
#include "unit_tests/mocks/mock_device.h"
1516
#include "unit_tests/mocks/mock_csr.h"
1617
#include "unit_tests/mocks/mock_wddm.h"
17-
#include "unit_tests/libult/create_command_stream.h"
18+
#include "unit_tests/os_interface/windows/registry_reader_tests.h"
1819
#include "gtest/gtest.h"
20+
#include <memory>
1921

2022
namespace OCLRT {
2123

@@ -107,5 +109,52 @@ TEST(DriverInfo, GivenDriverInfoWhenThenReturnNonNullptr) {
107109

108110
EXPECT_STREQ(defaultVersion.c_str(), driverVersion.c_str());
109111
EXPECT_TRUE(registryReaderMock->properVersionKey);
110-
}
112+
};
113+
114+
TEST(DriverInfo, givenInitializedOsInterfaceWhenCreateDriverInfoThenReturnDriverInfoWindowsNotNullptr) {
115+
116+
std::unique_ptr<OSInterface> osInterface(new OSInterface());
117+
osInterface->get()->setWddm(Wddm::createWddm());
118+
EXPECT_NE(nullptr, osInterface->get()->getWddm());
119+
120+
std::unique_ptr<DriverInfo> driverInfo(DriverInfo::create(osInterface.get()));
121+
122+
EXPECT_NE(nullptr, driverInfo);
123+
};
124+
125+
TEST(DriverInfo, givenNotInitializedOsInterfaceWhenCreateDriverInfoThenReturnDriverInfoWindowsNullptr) {
126+
127+
std::unique_ptr<OSInterface> osInterface;
128+
129+
std::unique_ptr<DriverInfo> driverInfo(DriverInfo::create(osInterface.get()));
130+
131+
EXPECT_EQ(nullptr, driverInfo);
132+
};
133+
134+
class MockDriverInfoWindows : public DriverInfoWindows {
135+
136+
public:
137+
const char *getRegistryReaderRegKey() {
138+
return reader->getRegKey();
139+
}
140+
TestedRegistryReader *reader;
141+
142+
static MockDriverInfoWindows *create(std::string path) {
143+
144+
auto result = new MockDriverInfoWindows();
145+
result->reader = new TestedRegistryReader(path);
146+
result->setRegistryReader(result->reader);
147+
148+
return result;
149+
};
150+
};
151+
152+
TEST(DriverInfo, givenInitializedOsInterfaceWhenCreateDriverInfoWindowsThenSetRegistryReaderWithExpectRegKey) {
153+
std::string path = "";
154+
std::unique_ptr<MockDriverInfoWindows> driverInfo(MockDriverInfoWindows::create(path));
155+
std::unique_ptr<TestedRegistryReader> reader(new TestedRegistryReader(path));
156+
EXPECT_NE(nullptr, reader);
157+
EXPECT_STREQ(driverInfo->getRegistryReaderRegKey(), reader->getRegKey());
158+
};
159+
111160
} // namespace OCLRT

unit_tests/os_interface/windows/registry_reader_tests.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,11 @@
66
*/
77

88
#include "runtime/os_interface/windows/registry_reader.h"
9+
#include "unit_tests/os_interface/windows/registry_reader_tests.h"
910
#include "test.h"
1011

1112
using namespace OCLRT;
1213

13-
class TestedRegistryReader : public RegistryReader {
14-
public:
15-
TestedRegistryReader(bool userScope) : RegistryReader(userScope){};
16-
TestedRegistryReader(std::string regKey) : RegistryReader(regKey){};
17-
HKEY getHkeyType() const {
18-
return igdrclHkeyType;
19-
}
20-
using RegistryReader::getSetting;
21-
const char *getRegKey() const {
22-
return registryReadRootKey.c_str();
23-
}
24-
};
25-
2614
using RegistryReaderTest = ::testing::Test;
2715

2816
TEST_F(RegistryReaderTest, givenRegistryReaderWhenItIsCreatedWithUserScopeSetToFalseThenItsHkeyTypeIsInitializedToHkeyLocalMachine) {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright (C) 2018 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
using namespace OCLRT;
9+
10+
class TestedRegistryReader : public RegistryReader {
11+
public:
12+
TestedRegistryReader(bool userScope) : RegistryReader(userScope){};
13+
TestedRegistryReader(std::string regKey) : RegistryReader(regKey){};
14+
HKEY getHkeyType() const {
15+
return igdrclHkeyType;
16+
}
17+
using RegistryReader::getSetting;
18+
const char *getRegKey() const {
19+
return registryReadRootKey.c_str();
20+
}
21+
};

0 commit comments

Comments
 (0)