2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2020-01-07 07:42:40 +01:00
|
|
|
* Copyright (C) 2017-2020 Intel Corporation
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
2018-09-18 09:11:08 +02:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-02-05 08:30:17 +01:00
|
|
|
#include "core/execution_environment/execution_environment.h"
|
2019-11-29 15:41:47 +01:00
|
|
|
#include "core/helpers/hw_info.h"
|
2019-09-04 10:58:52 +02:00
|
|
|
#include "core/memory_manager/memory_constants.h"
|
2020-02-05 11:49:26 +01:00
|
|
|
#include "core/os_interface/device_factory.h"
|
2020-01-21 15:24:52 +01:00
|
|
|
#include "core/os_interface/os_interface.h"
|
2019-11-19 11:49:19 +01:00
|
|
|
#include "core/os_interface/os_library.h"
|
2019-07-15 13:51:08 +02:00
|
|
|
#include "core/unit_tests/helpers/debug_manager_state_restore.h"
|
2019-01-23 11:59:54 +01:00
|
|
|
#include "runtime/platform/platform.h"
|
2019-11-13 13:53:27 +01:00
|
|
|
#include "unit_tests/mocks/mock_execution_environment.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
2019-11-28 13:02:11 +01:00
|
|
|
#include <set>
|
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
using namespace NEO;
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2019-03-15 11:09:06 +01:00
|
|
|
OsLibrary *setAdapterInfo(const PLATFORM *platform, const GT_SYSTEM_INFO *gtSystemInfo, uint64_t gpuAddressSpace);
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2018-03-29 00:38:41 +02:00
|
|
|
struct DeviceFactoryTest : public ::testing::Test {
|
2017-12-21 00:45:38 +01:00
|
|
|
public:
|
|
|
|
void SetUp() override {
|
2019-05-06 12:33:44 +02:00
|
|
|
const HardwareInfo *hwInfo = platformDevices[0];
|
2020-02-03 16:18:21 +01:00
|
|
|
executionEnvironment = platform()->peekExecutionEnvironment();
|
2019-05-08 16:00:24 +02:00
|
|
|
mockGdiDll = setAdapterInfo(&hwInfo->platform, &hwInfo->gtSystemInfo, hwInfo->capabilityTable.gpuAddressSpace);
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TearDown() override {
|
|
|
|
delete mockGdiDll;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
OsLibrary *mockGdiDll;
|
2019-01-23 11:59:54 +01:00
|
|
|
ExecutionEnvironment *executionEnvironment;
|
2017-12-21 00:45:38 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(DeviceFactoryTest, GetDevices_Expect_True_If_Returned) {
|
2018-07-12 11:45:02 +02:00
|
|
|
DeviceFactoryCleaner cleaner;
|
2017-12-21 00:45:38 +01:00
|
|
|
size_t numDevices = 0;
|
2019-05-06 12:33:44 +02:00
|
|
|
bool success = DeviceFactory::getDevices(numDevices, *executionEnvironment);
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
EXPECT_TRUE((numDevices > 0) ? success : !success);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DeviceFactoryTest, GetDevices_Check_HwInfo_Null) {
|
2018-07-12 11:45:02 +02:00
|
|
|
DeviceFactoryCleaner cleaner;
|
2017-12-21 00:45:38 +01:00
|
|
|
size_t numDevices = 0;
|
2019-05-06 12:33:44 +02:00
|
|
|
bool success = DeviceFactory::getDevices(numDevices, *executionEnvironment);
|
2017-12-21 00:45:38 +01:00
|
|
|
EXPECT_TRUE((numDevices > 0) ? success : !success);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DeviceFactoryTest, GetDevices_Check_HwInfo_Platform) {
|
2018-07-12 11:45:02 +02:00
|
|
|
DeviceFactoryCleaner cleaner;
|
2017-12-21 00:45:38 +01:00
|
|
|
const HardwareInfo *refHwinfo = *platformDevices;
|
|
|
|
size_t numDevices = 0;
|
|
|
|
|
2019-05-06 12:33:44 +02:00
|
|
|
bool success = DeviceFactory::getDevices(numDevices, *executionEnvironment);
|
|
|
|
const HardwareInfo *hwInfo = executionEnvironment->getHardwareInfo();
|
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
EXPECT_TRUE((numDevices > 0) ? success : !success);
|
|
|
|
|
|
|
|
if (numDevices > 0) {
|
|
|
|
|
2019-05-08 16:00:24 +02:00
|
|
|
EXPECT_EQ(refHwinfo->platform.eDisplayCoreFamily, hwInfo->platform.eDisplayCoreFamily);
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DeviceFactoryTest, overrideKmdNotifySettings) {
|
2018-07-12 11:45:02 +02:00
|
|
|
DeviceFactoryCleaner cleaner;
|
2017-12-21 00:45:38 +01:00
|
|
|
DebugManagerStateRestore stateRestore;
|
|
|
|
|
|
|
|
size_t numDevices = 0;
|
|
|
|
|
2019-05-06 12:33:44 +02:00
|
|
|
bool success = DeviceFactory::getDevices(numDevices, *executionEnvironment);
|
|
|
|
auto hwInfo = executionEnvironment->getHardwareInfo();
|
2017-12-21 00:45:38 +01:00
|
|
|
ASSERT_TRUE(success);
|
2019-05-06 12:33:44 +02:00
|
|
|
auto refEnableKmdNotify = hwInfo->capabilityTable.kmdNotifyProperties.enableKmdNotify;
|
|
|
|
auto refDelayKmdNotifyMicroseconds = hwInfo->capabilityTable.kmdNotifyProperties.delayKmdNotifyMicroseconds;
|
|
|
|
auto refEnableQuickKmdSleep = hwInfo->capabilityTable.kmdNotifyProperties.enableQuickKmdSleep;
|
|
|
|
auto refDelayQuickKmdSleepMicroseconds = hwInfo->capabilityTable.kmdNotifyProperties.delayQuickKmdSleepMicroseconds;
|
|
|
|
auto refEnableQuickKmdSleepForSporadicWaits = hwInfo->capabilityTable.kmdNotifyProperties.enableQuickKmdSleepForSporadicWaits;
|
|
|
|
auto refDelayQuickKmdSleepForSporadicWaitsMicroseconds = hwInfo->capabilityTable.kmdNotifyProperties.delayQuickKmdSleepForSporadicWaitsMicroseconds;
|
2017-12-21 00:45:38 +01:00
|
|
|
DeviceFactory::releaseDevices();
|
|
|
|
|
|
|
|
DebugManager.flags.OverrideEnableKmdNotify.set(!refEnableKmdNotify);
|
2018-02-27 07:40:15 +01:00
|
|
|
DebugManager.flags.OverrideKmdNotifyDelayMicroseconds.set(static_cast<int32_t>(refDelayKmdNotifyMicroseconds) + 10);
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2018-03-21 10:00:49 +01:00
|
|
|
DebugManager.flags.OverrideEnableQuickKmdSleep.set(!refEnableQuickKmdSleep);
|
|
|
|
DebugManager.flags.OverrideQuickKmdSleepDelayMicroseconds.set(static_cast<int32_t>(refDelayQuickKmdSleepMicroseconds) + 11);
|
|
|
|
|
2018-03-22 09:41:17 +01:00
|
|
|
DebugManager.flags.OverrideEnableQuickKmdSleepForSporadicWaits.set(!refEnableQuickKmdSleepForSporadicWaits);
|
|
|
|
DebugManager.flags.OverrideDelayQuickKmdSleepForSporadicWaitsMicroseconds.set(static_cast<int32_t>(refDelayQuickKmdSleepForSporadicWaitsMicroseconds) + 12);
|
|
|
|
|
2019-05-06 12:33:44 +02:00
|
|
|
success = DeviceFactory::getDevices(numDevices, *executionEnvironment);
|
2017-12-21 00:45:38 +01:00
|
|
|
ASSERT_TRUE(success);
|
2019-05-06 12:33:44 +02:00
|
|
|
hwInfo = executionEnvironment->getHardwareInfo();
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2019-05-06 12:33:44 +02:00
|
|
|
EXPECT_EQ(!refEnableKmdNotify, hwInfo->capabilityTable.kmdNotifyProperties.enableKmdNotify);
|
|
|
|
EXPECT_EQ(refDelayKmdNotifyMicroseconds + 10, hwInfo->capabilityTable.kmdNotifyProperties.delayKmdNotifyMicroseconds);
|
2018-03-21 10:00:49 +01:00
|
|
|
|
2019-05-06 12:33:44 +02:00
|
|
|
EXPECT_EQ(!refEnableQuickKmdSleep, hwInfo->capabilityTable.kmdNotifyProperties.enableQuickKmdSleep);
|
|
|
|
EXPECT_EQ(refDelayQuickKmdSleepMicroseconds + 11, hwInfo->capabilityTable.kmdNotifyProperties.delayQuickKmdSleepMicroseconds);
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2018-03-22 09:41:17 +01:00
|
|
|
EXPECT_EQ(!refEnableQuickKmdSleepForSporadicWaits,
|
2019-05-06 12:33:44 +02:00
|
|
|
hwInfo->capabilityTable.kmdNotifyProperties.enableQuickKmdSleepForSporadicWaits);
|
2018-03-22 09:41:17 +01:00
|
|
|
EXPECT_EQ(refDelayQuickKmdSleepForSporadicWaitsMicroseconds + 12,
|
2019-05-06 12:33:44 +02:00
|
|
|
hwInfo->capabilityTable.kmdNotifyProperties.delayQuickKmdSleepForSporadicWaitsMicroseconds);
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
2018-02-14 14:52:00 +01:00
|
|
|
|
|
|
|
TEST_F(DeviceFactoryTest, getEngineTypeDebugOverride) {
|
2018-07-12 11:45:02 +02:00
|
|
|
DeviceFactoryCleaner cleaner;
|
2018-02-14 14:52:00 +01:00
|
|
|
DebugManagerStateRestore dbgRestorer;
|
|
|
|
int32_t debugEngineType = 2;
|
|
|
|
DebugManager.flags.NodeOrdinal.set(debugEngineType);
|
2019-05-06 12:33:44 +02:00
|
|
|
|
2018-02-14 14:52:00 +01:00
|
|
|
size_t numDevices = 0;
|
|
|
|
|
2019-05-06 12:33:44 +02:00
|
|
|
bool success = DeviceFactory::getDevices(numDevices, *executionEnvironment);
|
2018-02-14 14:52:00 +01:00
|
|
|
ASSERT_TRUE(success);
|
2019-05-06 12:33:44 +02:00
|
|
|
auto hwInfo = executionEnvironment->getHardwareInfo();
|
|
|
|
|
|
|
|
int32_t actualEngineType = static_cast<int32_t>(hwInfo->capabilityTable.defaultEngineType);
|
2018-02-14 14:52:00 +01:00
|
|
|
EXPECT_EQ(debugEngineType, actualEngineType);
|
|
|
|
}
|
2018-02-21 16:06:09 +01:00
|
|
|
|
|
|
|
TEST_F(DeviceFactoryTest, givenPointerToHwInfoWhenGetDevicedCalledThenRequiedSurfaceSizeIsSettedProperly) {
|
2018-07-12 11:45:02 +02:00
|
|
|
DeviceFactoryCleaner cleaner;
|
2018-02-21 16:06:09 +01:00
|
|
|
size_t numDevices = 0;
|
2019-05-06 12:33:44 +02:00
|
|
|
bool success = DeviceFactory::getDevices(numDevices, *executionEnvironment);
|
2018-02-21 16:06:09 +01:00
|
|
|
ASSERT_TRUE(success);
|
2019-05-06 12:33:44 +02:00
|
|
|
auto hwInfo = executionEnvironment->getHardwareInfo();
|
2018-02-21 16:06:09 +01:00
|
|
|
|
2019-05-08 16:00:24 +02:00
|
|
|
EXPECT_EQ(hwInfo->gtSystemInfo.CsrSizeInMb * MemoryConstants::megaByte, hwInfo->capabilityTable.requiredPreemptionSurfaceSize);
|
2018-03-21 10:00:49 +01:00
|
|
|
}
|
2018-06-20 11:19:55 +02:00
|
|
|
|
2019-10-17 16:00:12 +02:00
|
|
|
TEST_F(DeviceFactoryTest, givenCreateMultipleRootDevicesDebugFlagWhenGetDevicesIsCalledThenNumberOfReturnedDevicesIsEqualToDebugVariable) {
|
2018-07-12 11:45:02 +02:00
|
|
|
DeviceFactoryCleaner cleaner;
|
2018-06-20 11:19:55 +02:00
|
|
|
DebugManagerStateRestore stateRestore;
|
|
|
|
auto requiredDeviceCount = 2u;
|
2019-10-17 16:00:12 +02:00
|
|
|
DebugManager.flags.CreateMultipleRootDevices.set(requiredDeviceCount);
|
2018-06-20 11:19:55 +02:00
|
|
|
|
2019-05-06 12:33:44 +02:00
|
|
|
size_t numDevices = 0;
|
|
|
|
bool success = DeviceFactory::getDevices(numDevices, *executionEnvironment);
|
2018-06-20 11:19:55 +02:00
|
|
|
|
|
|
|
ASSERT_TRUE(success);
|
|
|
|
EXPECT_EQ(requiredDeviceCount, numDevices);
|
2019-10-23 16:17:06 +02:00
|
|
|
EXPECT_EQ(requiredDeviceCount, executionEnvironment->rootDeviceEnvironments.size());
|
2018-06-20 11:19:55 +02:00
|
|
|
}
|
2018-08-10 11:07:17 +02:00
|
|
|
|
2019-10-17 16:00:12 +02:00
|
|
|
TEST_F(DeviceFactoryTest, givenCreateMultipleRootDevicesDebugFlagWhenGetDevicesForProductFamilyOverrideIsCalledThenNumberOfReturnedDevicesIsEqualToDebugVariable) {
|
2018-09-18 16:31:47 +02:00
|
|
|
DeviceFactoryCleaner cleaner;
|
|
|
|
DebugManagerStateRestore stateRestore;
|
|
|
|
auto requiredDeviceCount = 2u;
|
2019-10-17 16:00:12 +02:00
|
|
|
DebugManager.flags.CreateMultipleRootDevices.set(requiredDeviceCount);
|
2018-09-18 16:31:47 +02:00
|
|
|
|
2019-05-06 12:33:44 +02:00
|
|
|
size_t numDevices = 0;
|
|
|
|
bool success = DeviceFactory::getDevicesForProductFamilyOverride(numDevices, *executionEnvironment);
|
2018-09-18 16:31:47 +02:00
|
|
|
|
|
|
|
ASSERT_TRUE(success);
|
|
|
|
EXPECT_EQ(requiredDeviceCount, numDevices);
|
|
|
|
}
|
|
|
|
|
2019-11-28 13:02:11 +01:00
|
|
|
TEST_F(DeviceFactoryTest, whenGetDevicesIsCalledThenAllRootDeviceEnvironmentMembersAreInitialized) {
|
|
|
|
DeviceFactoryCleaner cleaner;
|
|
|
|
DebugManagerStateRestore stateRestore;
|
|
|
|
auto requiredDeviceCount = 2u;
|
|
|
|
DebugManager.flags.CreateMultipleRootDevices.set(requiredDeviceCount);
|
|
|
|
|
|
|
|
MockExecutionEnvironment executionEnvironment(*platformDevices, true, requiredDeviceCount);
|
|
|
|
|
|
|
|
size_t numDevices = 0;
|
|
|
|
bool success = DeviceFactory::getDevices(numDevices, executionEnvironment);
|
|
|
|
ASSERT_TRUE(success);
|
|
|
|
EXPECT_EQ(requiredDeviceCount, numDevices);
|
|
|
|
|
|
|
|
std::set<MemoryOperationsHandler *> memoryOperationHandlers;
|
2020-01-07 07:42:40 +01:00
|
|
|
std::set<OSInterface *> osInterfaces;
|
2019-11-28 13:02:11 +01:00
|
|
|
for (auto rootDeviceIndex = 0u; rootDeviceIndex < requiredDeviceCount; rootDeviceIndex++) {
|
|
|
|
auto rootDeviceEnvironment = static_cast<MockRootDeviceEnvironment *>(executionEnvironment.rootDeviceEnvironments[rootDeviceIndex].get());
|
|
|
|
|
|
|
|
auto memoryOperationInterface = rootDeviceEnvironment->memoryOperationsInterface.get();
|
|
|
|
EXPECT_NE(nullptr, memoryOperationInterface);
|
|
|
|
EXPECT_EQ(memoryOperationHandlers.end(), memoryOperationHandlers.find(memoryOperationInterface));
|
|
|
|
memoryOperationHandlers.insert(memoryOperationInterface);
|
2020-01-07 07:42:40 +01:00
|
|
|
|
|
|
|
auto osInterface = rootDeviceEnvironment->osInterface.get();
|
|
|
|
EXPECT_NE(nullptr, osInterface);
|
|
|
|
EXPECT_EQ(osInterfaces.end(), osInterfaces.find(osInterface));
|
|
|
|
osInterfaces.insert(osInterface);
|
2019-11-15 09:59:48 +01:00
|
|
|
}
|
2019-11-13 13:53:27 +01:00
|
|
|
}
|
|
|
|
|
2019-10-18 10:15:09 +02:00
|
|
|
TEST_F(DeviceFactoryTest, givenInvalidHwConfigStringGetDevicesForProductFamilyOverrideReturnsFalse) {
|
|
|
|
DeviceFactoryCleaner cleaner;
|
|
|
|
DebugManagerStateRestore stateRestore;
|
|
|
|
DebugManager.flags.HardwareInfoOverride.set("1x3");
|
|
|
|
|
|
|
|
MockExecutionEnvironment executionEnvironment(*platformDevices);
|
|
|
|
|
|
|
|
size_t numDevices = 0;
|
|
|
|
bool success = DeviceFactory::getDevicesForProductFamilyOverride(numDevices, executionEnvironment);
|
|
|
|
EXPECT_FALSE(success);
|
|
|
|
}
|
|
|
|
|
2020-01-24 17:19:06 +01:00
|
|
|
TEST_F(DeviceFactoryTest, givenValidHwConfigStringGetDevicesForProductFamilyOverrideReturnsTrue) {
|
|
|
|
DeviceFactoryCleaner cleaner;
|
|
|
|
DebugManagerStateRestore stateRestore;
|
|
|
|
DebugManager.flags.HardwareInfoOverride.set("1x1x1");
|
|
|
|
|
|
|
|
MockExecutionEnvironment executionEnvironment(*platformDevices);
|
|
|
|
|
|
|
|
size_t numDevices = 0;
|
|
|
|
EXPECT_ANY_THROW(DeviceFactory::getDevicesForProductFamilyOverride(numDevices, executionEnvironment));
|
|
|
|
}
|
|
|
|
|
2018-08-10 11:07:17 +02:00
|
|
|
TEST_F(DeviceFactoryTest, givenGetDevicesCallWhenItIsDoneThenOsInterfaceIsAllocated) {
|
|
|
|
DeviceFactoryCleaner cleaner;
|
2019-05-06 12:33:44 +02:00
|
|
|
|
2018-08-10 11:07:17 +02:00
|
|
|
size_t numDevices = 0;
|
2019-05-06 12:33:44 +02:00
|
|
|
bool success = DeviceFactory::getDevices(numDevices, *executionEnvironment);
|
2018-08-10 11:07:17 +02:00
|
|
|
EXPECT_TRUE(success);
|
2020-01-07 07:42:40 +01:00
|
|
|
EXPECT_NE(nullptr, executionEnvironment->rootDeviceEnvironments[0]->osInterface);
|
2019-11-28 13:02:11 +01:00
|
|
|
}
|
2020-02-07 09:00:25 +01:00
|
|
|
|
|
|
|
TEST(DeviceFactory, givenHwModeSelectedWhenIsHwModeSelectedIsCalledThenTrueIsReturned) {
|
|
|
|
DebugManagerStateRestore stateRestore;
|
|
|
|
constexpr int32_t hwModes[] = {-1, CommandStreamReceiverType::CSR_HW, CommandStreamReceiverType::CSR_HW_WITH_AUB};
|
|
|
|
for (const auto &hwMode : hwModes) {
|
|
|
|
DebugManager.flags.SetCommandStreamReceiver.set(hwMode);
|
|
|
|
EXPECT_TRUE(DeviceFactory::isHwModeSelected());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(DeviceFactory, givenNonHwModeSelectedWhenIsHwModeSelectedIsCalledThenFalseIsReturned) {
|
|
|
|
DebugManagerStateRestore stateRestore;
|
|
|
|
constexpr int32_t nonHwModes[] = {CommandStreamReceiverType::CSR_AUB, CommandStreamReceiverType::CSR_TBX, CommandStreamReceiverType::CSR_TBX_WITH_AUB};
|
|
|
|
for (const auto &nonHwMode : nonHwModes) {
|
|
|
|
DebugManager.flags.SetCommandStreamReceiver.set(nonHwMode);
|
|
|
|
EXPECT_FALSE(DeviceFactory::isHwModeSelected());
|
|
|
|
}
|
|
|
|
}
|