2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2018-09-18 15:11:08 +08:00
|
|
|
* Copyright (C) 2017-2018 Intel Corporation
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
#include "runtime/os_interface/windows/driver_info.h"
|
|
|
|
#include "runtime/os_interface/windows/registry_reader.h"
|
|
|
|
#include "runtime/os_interface/windows/os_interface.h"
|
|
|
|
#include "runtime/memory_manager/os_agnostic_memory_manager.h"
|
|
|
|
#include "runtime/helpers/options.h"
|
|
|
|
#include "unit_tests/mocks/mock_device.h"
|
|
|
|
#include "unit_tests/mocks/mock_csr.h"
|
2018-08-14 17:05:17 +08:00
|
|
|
#include "unit_tests/mocks/mock_wddm.h"
|
2018-02-14 20:48:31 +08:00
|
|
|
#include "unit_tests/libult/create_command_stream.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
namespace OCLRT {
|
|
|
|
|
|
|
|
extern CommandStreamReceiverCreateFunc commandStreamReceiverFactory[2 * IGFX_MAX_CORE];
|
|
|
|
|
2018-08-08 19:49:09 +08:00
|
|
|
CommandStreamReceiver *createMockCommandStreamReceiver(const HardwareInfo &hwInfoIn, bool withAubDump, ExecutionEnvironment &executionEnvironment);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
class DriverInfoDeviceTest : public ::testing::Test {
|
|
|
|
public:
|
|
|
|
void SetUp() {
|
|
|
|
hwInfo = platformDevices[0];
|
|
|
|
commandStreamReceiverCreateFunc = commandStreamReceiverFactory[hwInfo->pPlatform->eRenderCoreFamily];
|
|
|
|
commandStreamReceiverFactory[hwInfo->pPlatform->eRenderCoreFamily] = createMockCommandStreamReceiver;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TearDown() {
|
|
|
|
commandStreamReceiverFactory[hwInfo->pPlatform->eRenderCoreFamily] = commandStreamReceiverCreateFunc;
|
|
|
|
}
|
|
|
|
|
|
|
|
CommandStreamReceiverCreateFunc commandStreamReceiverCreateFunc;
|
|
|
|
const HardwareInfo *hwInfo;
|
|
|
|
};
|
|
|
|
|
2018-08-08 19:49:09 +08:00
|
|
|
CommandStreamReceiver *createMockCommandStreamReceiver(const HardwareInfo &hwInfoIn, bool withAubDump, ExecutionEnvironment &executionEnvironment) {
|
2018-10-11 17:19:49 +08:00
|
|
|
auto csr = new MockCommandStreamReceiver(executionEnvironment);
|
2017-12-21 07:45:38 +08:00
|
|
|
OSInterface *osInterface = new OSInterface();
|
2018-08-10 17:07:17 +08:00
|
|
|
executionEnvironment.osInterface.reset(osInterface);
|
2018-08-27 21:48:29 +08:00
|
|
|
auto wddm = new WddmMock();
|
|
|
|
wddm->init();
|
|
|
|
osInterface->get()->setWddm(wddm);
|
2017-12-21 07:45:38 +08:00
|
|
|
csr->setOSInterface(osInterface);
|
|
|
|
return csr;
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DriverInfoDeviceTest, GivenDeviceCreatedWhenCorrectOSInterfaceThenCreateDriverInfo) {
|
|
|
|
overrideCommandStreamReceiverCreation = true;
|
2018-07-03 16:00:12 +08:00
|
|
|
auto device = MockDevice::createWithNewExecutionEnvironment<MockDevice>(hwInfo);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
EXPECT_TRUE(device->hasDriverInfo());
|
|
|
|
delete device;
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DriverInfoDeviceTest, GivenDeviceCreatedWithoutCorrectOSInterfaceThenDontCreateDriverInfo) {
|
|
|
|
overrideCommandStreamReceiverCreation = false;
|
2018-07-03 16:00:12 +08:00
|
|
|
auto device = MockDevice::createWithNewExecutionEnvironment<MockDevice>(hwInfo);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
EXPECT_FALSE(device->hasDriverInfo());
|
|
|
|
delete device;
|
|
|
|
}
|
|
|
|
|
|
|
|
class RegistryReaderMock : public SettingsReader {
|
|
|
|
public:
|
|
|
|
std::string nameString;
|
|
|
|
std::string versionString;
|
|
|
|
std::string getSetting(const char *settingName, const std::string &value) {
|
|
|
|
std::string key(settingName);
|
|
|
|
if (key == "HardwareInformation.AdapterString") {
|
|
|
|
properNameKey = true;
|
|
|
|
} else if (key == "DriverVersion") {
|
|
|
|
properVersionKey = true;
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool getSetting(const char *settingName, bool defaultValue) { return defaultValue; };
|
|
|
|
int32_t getSetting(const char *settingName, int32_t defaultValue) { return defaultValue; };
|
2018-10-10 22:02:19 +08:00
|
|
|
const char *appSpecificLocation(const std::string &name) { return name.c_str(); };
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
bool properNameKey = false;
|
|
|
|
bool properVersionKey = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST(DriverInfo, GivenDriverInfoWhenThenReturnNonNullptr) {
|
|
|
|
DriverInfoWindows driverInfo;
|
|
|
|
RegistryReaderMock *registryReaderMock = new RegistryReaderMock();
|
|
|
|
|
|
|
|
driverInfo.setRegistryReader(registryReaderMock);
|
|
|
|
|
|
|
|
std::string defaultName = "defaultName";
|
|
|
|
|
|
|
|
auto name = driverInfo.getDeviceName(defaultName);
|
|
|
|
|
|
|
|
EXPECT_STREQ(defaultName.c_str(), name.c_str());
|
|
|
|
EXPECT_TRUE(registryReaderMock->properNameKey);
|
|
|
|
|
|
|
|
std::string defaultVersion = "defaultVersion";
|
|
|
|
|
|
|
|
auto driverVersion = driverInfo.getVersion(defaultVersion);
|
|
|
|
|
|
|
|
EXPECT_STREQ(defaultVersion.c_str(), driverVersion.c_str());
|
|
|
|
EXPECT_TRUE(registryReaderMock->properVersionKey);
|
|
|
|
}
|
|
|
|
} // namespace OCLRT
|