2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2021-01-21 20:10:13 +08:00
|
|
|
* Copyright (C) 2017-2021 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/execution_environment/execution_environment.h"
|
|
|
|
#include "shared/source/helpers/aligned_memory.h"
|
|
|
|
#include "shared/source/helpers/basic_math.h"
|
|
|
|
#include "shared/source/memory_manager/memory_manager.h"
|
|
|
|
#include "shared/source/os_interface/linux/allocator_helper.h"
|
|
|
|
#include "shared/source/os_interface/linux/os_interface.h"
|
2021-01-21 20:10:13 +08:00
|
|
|
#include "shared/test/common/helpers/debug_manager_state_restore.h"
|
|
|
|
#include "shared/test/common/helpers/default_hw_info.inl"
|
|
|
|
#include "shared/test/common/helpers/ult_hw_config.inl"
|
|
|
|
#include "shared/test/common/helpers/variable_backup.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2020-02-23 22:20:22 +08:00
|
|
|
#include "opencl/test/unit_test/custom_event_listener.h"
|
|
|
|
#include "opencl/test/unit_test/linux/drm_wrap.h"
|
|
|
|
#include "opencl/test/unit_test/linux/mock_os_layer.h"
|
|
|
|
#include "opencl/test/unit_test/mocks/mock_execution_environment.h"
|
|
|
|
#include "opencl/test/unit_test/os_interface/linux/device_command_stream_fixture.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
#include "test.h"
|
2018-11-22 05:32:00 +08:00
|
|
|
|
|
|
|
#include "gmock/gmock.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
#include "gtest/gtest.h"
|
2018-11-22 05:32:00 +08:00
|
|
|
|
|
|
|
#include <string>
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-09-01 18:38:50 +08:00
|
|
|
namespace NEO {
|
|
|
|
void __attribute__((destructor)) platformsDestructor();
|
|
|
|
}
|
2019-03-26 18:59:46 +08:00
|
|
|
using namespace NEO;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
class DrmTestsFixture {
|
|
|
|
public:
|
|
|
|
void SetUp() {
|
2020-01-30 02:10:49 +08:00
|
|
|
executionEnvironment.prepareRootDeviceEnvironments(1);
|
|
|
|
rootDeviceEnvironment = executionEnvironment.rootDeviceEnvironments[0].get();
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TearDown() {
|
|
|
|
}
|
2020-01-30 02:10:49 +08:00
|
|
|
ExecutionEnvironment executionEnvironment;
|
|
|
|
RootDeviceEnvironment *rootDeviceEnvironment = nullptr;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef Test<DrmTestsFixture> DrmTests;
|
|
|
|
|
2019-03-27 19:44:49 +08:00
|
|
|
void initializeTestedDevice() {
|
|
|
|
for (uint32_t i = 0; deviceDescriptorTable[i].eGtType != GTTYPE::GTTYPE_UNDEFINED; i++) {
|
2020-03-23 17:23:43 +08:00
|
|
|
if (defaultHwInfo->platform.eProductFamily == deviceDescriptorTable[i].pHwInfo->platform.eProductFamily) {
|
2019-03-27 19:44:49 +08:00
|
|
|
deviceId = deviceDescriptorTable[i].deviceId;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-15 00:05:30 +08:00
|
|
|
int openRetVal = 0;
|
2020-04-08 17:27:04 +08:00
|
|
|
std::string lastOpenedPath;
|
2019-10-15 00:05:30 +08:00
|
|
|
int testOpen(const char *fullPath, int, ...) {
|
|
|
|
return openRetVal;
|
|
|
|
};
|
|
|
|
|
2020-02-26 16:08:22 +08:00
|
|
|
int openCounter = 1;
|
|
|
|
int openWithCounter(const char *fullPath, int, ...) {
|
|
|
|
if (openCounter > 0) {
|
2020-04-08 17:27:04 +08:00
|
|
|
if (fullPath) {
|
|
|
|
lastOpenedPath = fullPath;
|
|
|
|
}
|
2020-02-26 16:08:22 +08:00
|
|
|
openCounter--;
|
|
|
|
return 1023; // valid file descriptor for ULT
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST(DrmTest, GivenTwoOpenableDevicesWhenDiscoverDevicesThenCreateTwoHwDeviceIds) {
|
|
|
|
VariableBackup<decltype(openFull)> backupOpenFull(&openFull);
|
|
|
|
openFull = openWithCounter;
|
|
|
|
openCounter = 2;
|
2020-03-17 14:26:46 +08:00
|
|
|
ExecutionEnvironment executionEnvironment;
|
|
|
|
auto hwDeviceIds = OSInterface::discoverDevices(executionEnvironment);
|
2020-02-26 16:08:22 +08:00
|
|
|
EXPECT_EQ(2u, hwDeviceIds.size());
|
|
|
|
}
|
|
|
|
|
2019-10-15 00:05:30 +08:00
|
|
|
TEST(DrmTest, GivenSelectedNotExistingDeviceWhenGetDeviceFdThenFail) {
|
|
|
|
DebugManagerStateRestore stateRestore;
|
|
|
|
DebugManager.flags.ForceDeviceId.set("1234");
|
|
|
|
VariableBackup<decltype(openFull)> backupOpenFull(&openFull);
|
|
|
|
openFull = testOpen;
|
|
|
|
openRetVal = -1;
|
2020-03-17 14:26:46 +08:00
|
|
|
ExecutionEnvironment executionEnvironment;
|
|
|
|
auto hwDeviceIds = OSInterface::discoverDevices(executionEnvironment);
|
2020-02-17 23:14:22 +08:00
|
|
|
EXPECT_TRUE(hwDeviceIds.empty());
|
2019-10-15 00:05:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(DrmTest, GivenSelectedExistingDeviceWhenGetDeviceFdThenReturnFd) {
|
|
|
|
DebugManagerStateRestore stateRestore;
|
|
|
|
DebugManager.flags.ForceDeviceId.set("1234");
|
|
|
|
VariableBackup<decltype(openFull)> backupOpenFull(&openFull);
|
|
|
|
openRetVal = 1023; // fakeFd
|
|
|
|
openFull = testOpen;
|
2020-03-17 14:26:46 +08:00
|
|
|
ExecutionEnvironment executionEnvironment;
|
|
|
|
auto hwDeviceIds = OSInterface::discoverDevices(executionEnvironment);
|
2020-02-17 23:14:22 +08:00
|
|
|
EXPECT_EQ(1u, hwDeviceIds.size());
|
|
|
|
EXPECT_NE(nullptr, hwDeviceIds[0].get());
|
2019-10-15 00:05:30 +08:00
|
|
|
}
|
|
|
|
|
2020-04-09 00:14:19 +08:00
|
|
|
TEST(DrmTest, GivenSelectedExistingDeviceWhenOpenDirSuccedsThenHwDeviceIdsHaveProperPciPaths) {
|
|
|
|
VariableBackup<decltype(openFull)> backupOpenFull(&openFull);
|
|
|
|
VariableBackup<decltype(failOnOpenDir)> backupOpenDir(&failOnOpenDir, false);
|
|
|
|
VariableBackup<decltype(entryIndex)> backupEntryIndex(&entryIndex, 0u);
|
|
|
|
openFull = openWithCounter;
|
|
|
|
|
|
|
|
ExecutionEnvironment executionEnvironment;
|
|
|
|
|
|
|
|
entryIndex = 0;
|
|
|
|
openCounter = 1;
|
|
|
|
auto hwDeviceIds = OSInterface::discoverDevices(executionEnvironment);
|
|
|
|
EXPECT_EQ(1u, hwDeviceIds.size());
|
|
|
|
EXPECT_NE(nullptr, hwDeviceIds[0].get());
|
|
|
|
EXPECT_STREQ("test1", hwDeviceIds[0]->getPciPath());
|
|
|
|
|
|
|
|
entryIndex = 0;
|
|
|
|
openCounter = 2;
|
|
|
|
hwDeviceIds = OSInterface::discoverDevices(executionEnvironment);
|
|
|
|
EXPECT_EQ(2u, hwDeviceIds.size());
|
|
|
|
EXPECT_NE(nullptr, hwDeviceIds[0].get());
|
|
|
|
EXPECT_STREQ("test1", hwDeviceIds[0]->getPciPath());
|
|
|
|
EXPECT_NE(nullptr, hwDeviceIds[1].get());
|
|
|
|
EXPECT_STREQ("test2", hwDeviceIds[1]->getPciPath());
|
|
|
|
}
|
|
|
|
|
2020-04-08 17:27:04 +08:00
|
|
|
TEST(DrmTest, GivenSelectedExistingDeviceWhenOpenDirFailsThenRetryOpeningRenderDevices) {
|
|
|
|
VariableBackup<decltype(openFull)> backupOpenFull(&openFull);
|
|
|
|
VariableBackup<decltype(failOnOpenDir)> backupOpenDir(&failOnOpenDir, true);
|
2021-03-29 19:43:50 +08:00
|
|
|
VariableBackup<decltype(readLinkCalledTimes)> backupReadlink(&readLinkCalledTimes, 0);
|
2020-04-08 17:27:04 +08:00
|
|
|
openFull = openWithCounter;
|
|
|
|
openCounter = 1;
|
|
|
|
|
|
|
|
ExecutionEnvironment executionEnvironment;
|
|
|
|
auto hwDeviceIds = OSInterface::discoverDevices(executionEnvironment);
|
|
|
|
EXPECT_STREQ("/dev/dri/renderD128", lastOpenedPath.c_str());
|
|
|
|
EXPECT_EQ(1u, hwDeviceIds.size());
|
|
|
|
EXPECT_NE(nullptr, hwDeviceIds[0].get());
|
2020-04-09 00:14:19 +08:00
|
|
|
EXPECT_STREQ("00:02.0", hwDeviceIds[0]->getPciPath());
|
2020-04-08 17:27:04 +08:00
|
|
|
|
|
|
|
openCounter = 2;
|
|
|
|
hwDeviceIds = OSInterface::discoverDevices(executionEnvironment);
|
|
|
|
EXPECT_STREQ("/dev/dri/renderD129", lastOpenedPath.c_str());
|
|
|
|
EXPECT_EQ(2u, hwDeviceIds.size());
|
|
|
|
EXPECT_NE(nullptr, hwDeviceIds[0].get());
|
2020-04-09 00:14:19 +08:00
|
|
|
EXPECT_STREQ("00:02.0", hwDeviceIds[0]->getPciPath());
|
2020-04-08 17:27:04 +08:00
|
|
|
EXPECT_NE(nullptr, hwDeviceIds[1].get());
|
2021-03-29 19:43:50 +08:00
|
|
|
EXPECT_STREQ("00:03.0", hwDeviceIds[1]->getPciPath());
|
2020-04-08 17:27:04 +08:00
|
|
|
}
|
|
|
|
|
2020-05-21 19:01:07 +08:00
|
|
|
TEST(DrmTest, GivenSelectedNonExistingDeviceWhenOpenDirFailsThenRetryOpeningRenderDevicesAndNoDevicesAreCreated) {
|
|
|
|
VariableBackup<decltype(openFull)> backupOpenFull(&openFull);
|
|
|
|
VariableBackup<decltype(failOnOpenDir)> backupOpenDir(&failOnOpenDir, true);
|
|
|
|
openFull = openWithCounter;
|
|
|
|
openCounter = 0;
|
|
|
|
|
|
|
|
ExecutionEnvironment executionEnvironment;
|
|
|
|
auto hwDeviceIds = OSInterface::discoverDevices(executionEnvironment);
|
|
|
|
EXPECT_EQ(0u, hwDeviceIds.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(DrmTest, GivenFailingOpenDirAndMultipleAvailableDevicesWhenCreateMultipleRootDevicesFlagIsSetThenTheFlagIsRespected) {
|
|
|
|
DebugManagerStateRestore stateRestore;
|
|
|
|
VariableBackup<decltype(openFull)> backupOpenFull(&openFull);
|
|
|
|
VariableBackup<decltype(failOnOpenDir)> backupOpenDir(&failOnOpenDir, true);
|
2021-03-29 19:43:50 +08:00
|
|
|
VariableBackup<decltype(readLinkCalledTimes)> backupReadlink(&readLinkCalledTimes, 0);
|
2020-05-21 19:01:07 +08:00
|
|
|
openFull = openWithCounter;
|
|
|
|
ExecutionEnvironment executionEnvironment;
|
|
|
|
const uint32_t requestedNumRootDevices = 2u;
|
|
|
|
DebugManager.flags.CreateMultipleRootDevices.set(requestedNumRootDevices);
|
|
|
|
|
|
|
|
openCounter = 4;
|
|
|
|
auto hwDeviceIds = OSInterface::discoverDevices(executionEnvironment);
|
|
|
|
EXPECT_STREQ("/dev/dri/renderD129", lastOpenedPath.c_str());
|
|
|
|
EXPECT_EQ(requestedNumRootDevices, hwDeviceIds.size());
|
|
|
|
EXPECT_NE(nullptr, hwDeviceIds[0].get());
|
|
|
|
EXPECT_STREQ("00:02.0", hwDeviceIds[0]->getPciPath());
|
|
|
|
EXPECT_NE(nullptr, hwDeviceIds[1].get());
|
2021-03-29 19:43:50 +08:00
|
|
|
EXPECT_STREQ("00:03.0", hwDeviceIds[1]->getPciPath());
|
2020-05-21 19:01:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(DrmTest, GivenMultipleAvailableDevicesWhenCreateMultipleRootDevicesFlagIsSetThenTheFlagIsRespected) {
|
|
|
|
DebugManagerStateRestore stateRestore;
|
|
|
|
VariableBackup<decltype(openFull)> backupOpenFull(&openFull);
|
|
|
|
openFull = openWithCounter;
|
|
|
|
ExecutionEnvironment executionEnvironment;
|
|
|
|
const uint32_t requestedNumRootDevices = 2u;
|
|
|
|
DebugManager.flags.CreateMultipleRootDevices.set(requestedNumRootDevices);
|
|
|
|
|
|
|
|
openCounter = 4;
|
|
|
|
auto hwDeviceIds = OSInterface::discoverDevices(executionEnvironment);
|
|
|
|
EXPECT_STREQ("/dev/dri/by-path/pci-0000:test2-render", lastOpenedPath.c_str());
|
|
|
|
EXPECT_EQ(requestedNumRootDevices, hwDeviceIds.size());
|
|
|
|
EXPECT_NE(nullptr, hwDeviceIds[0].get());
|
|
|
|
EXPECT_STREQ("test1", hwDeviceIds[0]->getPciPath());
|
|
|
|
EXPECT_NE(nullptr, hwDeviceIds[1].get());
|
|
|
|
EXPECT_STREQ("test2", hwDeviceIds[1]->getPciPath());
|
|
|
|
}
|
|
|
|
|
2019-10-15 00:05:30 +08:00
|
|
|
TEST(DrmTest, GivenSelectedIncorectDeviceWhenGetDeviceFdThenFail) {
|
|
|
|
DebugManagerStateRestore stateRestore;
|
|
|
|
DebugManager.flags.ForceDeviceId.set("1234");
|
|
|
|
VariableBackup<decltype(openFull)> backupOpenFull(&openFull);
|
|
|
|
openFull = testOpen;
|
2020-02-07 21:32:02 +08:00
|
|
|
openRetVal = 1024;
|
2020-03-17 14:26:46 +08:00
|
|
|
ExecutionEnvironment executionEnvironment;
|
2019-10-15 00:05:30 +08:00
|
|
|
|
2020-03-17 14:26:46 +08:00
|
|
|
auto hwDeviceIds = OSInterface::discoverDevices(executionEnvironment);
|
2020-02-17 23:14:22 +08:00
|
|
|
EXPECT_TRUE(hwDeviceIds.empty());
|
2019-10-15 00:05:30 +08:00
|
|
|
}
|
|
|
|
|
2020-09-17 20:56:32 +08:00
|
|
|
TEST(DrmTest, givenUseVmBindFlagWhenOverrideBindSupportThenReturnProperValue) {
|
|
|
|
DebugManagerStateRestore dbgRestorer;
|
|
|
|
bool useVmBind = false;
|
|
|
|
|
|
|
|
DebugManager.flags.UseVmBind.set(1);
|
|
|
|
Drm::overrideBindSupport(useVmBind);
|
|
|
|
EXPECT_TRUE(useVmBind);
|
|
|
|
|
|
|
|
DebugManager.flags.UseVmBind.set(0);
|
|
|
|
Drm::overrideBindSupport(useVmBind);
|
|
|
|
EXPECT_FALSE(useVmBind);
|
|
|
|
|
|
|
|
DebugManager.flags.UseVmBind.set(-1);
|
|
|
|
Drm::overrideBindSupport(useVmBind);
|
|
|
|
EXPECT_FALSE(useVmBind);
|
|
|
|
}
|
|
|
|
|
2020-12-07 22:50:43 +08:00
|
|
|
TEST_F(DrmTests, GivenErrorCodeWhenCreatingDrmThenDrmCreatedOnlyWithSpecificErrors) {
|
2020-02-07 21:32:02 +08:00
|
|
|
auto drm = DrmWrap::createDrm(*rootDeviceEnvironment);
|
2018-07-27 19:59:39 +08:00
|
|
|
EXPECT_NE(drm, nullptr);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
drm_i915_getparam_t getParam;
|
|
|
|
int lDeviceId;
|
|
|
|
|
2019-03-28 19:53:48 +08:00
|
|
|
VariableBackup<decltype(ioctlCnt)> backupIoctlCnt(&ioctlCnt);
|
|
|
|
VariableBackup<int> backupIoctlSeq(&ioctlSeq[0]);
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
ioctlCnt = 0;
|
|
|
|
ioctlSeq[0] = -1;
|
|
|
|
errno = EINTR;
|
|
|
|
// check if device works, although there was EINTR error from KMD
|
|
|
|
getParam.param = I915_PARAM_CHIPSET_ID;
|
|
|
|
getParam.value = &lDeviceId;
|
2018-07-27 19:59:39 +08:00
|
|
|
auto ret = drm->ioctl(DRM_IOCTL_I915_GETPARAM, &getParam);
|
2017-12-21 07:45:38 +08:00
|
|
|
EXPECT_EQ(0, ret);
|
|
|
|
EXPECT_EQ(deviceId, lDeviceId);
|
|
|
|
|
|
|
|
ioctlCnt = 0;
|
|
|
|
ioctlSeq[0] = -1;
|
|
|
|
errno = EAGAIN;
|
|
|
|
// check if device works, although there was EAGAIN error from KMD
|
|
|
|
getParam.param = I915_PARAM_CHIPSET_ID;
|
|
|
|
getParam.value = &lDeviceId;
|
2018-07-27 19:59:39 +08:00
|
|
|
ret = drm->ioctl(DRM_IOCTL_I915_GETPARAM, &getParam);
|
2017-12-21 07:45:38 +08:00
|
|
|
EXPECT_EQ(0, ret);
|
|
|
|
EXPECT_EQ(deviceId, lDeviceId);
|
|
|
|
|
2020-07-28 16:25:04 +08:00
|
|
|
ioctlCnt = 0;
|
|
|
|
ioctlSeq[0] = -1;
|
|
|
|
errno = EBUSY;
|
|
|
|
// check if device works, although there was EBUSY error from KMD
|
|
|
|
getParam.param = I915_PARAM_CHIPSET_ID;
|
|
|
|
getParam.value = &lDeviceId;
|
|
|
|
ret = drm->ioctl(DRM_IOCTL_I915_GETPARAM, &getParam);
|
|
|
|
EXPECT_EQ(0, ret);
|
|
|
|
EXPECT_EQ(deviceId, lDeviceId);
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
ioctlCnt = 0;
|
|
|
|
ioctlSeq[0] = -1;
|
|
|
|
errno = 0;
|
|
|
|
// we failed with any other error code
|
|
|
|
getParam.param = I915_PARAM_CHIPSET_ID;
|
|
|
|
getParam.value = &lDeviceId;
|
2018-07-27 19:59:39 +08:00
|
|
|
ret = drm->ioctl(DRM_IOCTL_I915_GETPARAM, &getParam);
|
2017-12-21 07:45:38 +08:00
|
|
|
EXPECT_EQ(-1, ret);
|
|
|
|
EXPECT_EQ(deviceId, lDeviceId);
|
|
|
|
}
|
|
|
|
|
2020-12-07 22:50:43 +08:00
|
|
|
TEST_F(DrmTests, WhenCreatingTwiceThenDifferentDrmReturned) {
|
2020-02-07 21:32:02 +08:00
|
|
|
auto drm1 = DrmWrap::createDrm(*rootDeviceEnvironment);
|
2018-07-27 19:59:39 +08:00
|
|
|
EXPECT_NE(drm1, nullptr);
|
2020-02-07 21:32:02 +08:00
|
|
|
auto drm2 = DrmWrap::createDrm(*rootDeviceEnvironment);
|
2018-07-27 19:59:39 +08:00
|
|
|
EXPECT_NE(drm2, nullptr);
|
2020-02-12 00:48:40 +08:00
|
|
|
EXPECT_NE(drm1, drm2);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2020-12-07 22:50:43 +08:00
|
|
|
TEST_F(DrmTests, WhenDriDeviceFoundThenDrmCreatedOnFallback) {
|
2019-03-28 19:53:48 +08:00
|
|
|
VariableBackup<decltype(haveDri)> backupHaveDri(&haveDri);
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
haveDri = 1;
|
2020-02-07 21:32:02 +08:00
|
|
|
auto drm = DrmWrap::createDrm(*rootDeviceEnvironment);
|
2018-07-27 19:59:39 +08:00
|
|
|
EXPECT_NE(drm, nullptr);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2020-12-07 22:50:43 +08:00
|
|
|
TEST_F(DrmTests, GivenNoDeviceWhenCreatingDrmThenNullIsReturned) {
|
2019-03-28 19:53:48 +08:00
|
|
|
VariableBackup<decltype(haveDri)> backupHaveDri(&haveDri);
|
2017-12-21 07:45:38 +08:00
|
|
|
haveDri = -1;
|
2020-02-07 21:32:02 +08:00
|
|
|
auto drm = DrmWrap::createDrm(*rootDeviceEnvironment);
|
2018-07-27 19:59:39 +08:00
|
|
|
EXPECT_EQ(drm, nullptr);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2020-12-07 22:50:43 +08:00
|
|
|
TEST_F(DrmTests, GivenUnknownDeviceWhenCreatingDrmThenNullIsReturned) {
|
2019-03-28 19:53:48 +08:00
|
|
|
DebugManagerStateRestore dbgRestorer;
|
2018-11-22 05:32:00 +08:00
|
|
|
DebugManager.flags.PrintDebugMessages.set(true);
|
|
|
|
|
2019-03-28 19:53:48 +08:00
|
|
|
VariableBackup<decltype(deviceId)> backupDeviceId(&deviceId);
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
deviceId = -1;
|
|
|
|
|
2018-11-22 05:32:00 +08:00
|
|
|
::testing::internal::CaptureStderr();
|
2020-11-13 23:33:21 +08:00
|
|
|
::testing::internal::CaptureStdout();
|
2020-02-07 21:32:02 +08:00
|
|
|
auto drm = DrmWrap::createDrm(*rootDeviceEnvironment);
|
2018-07-27 19:59:39 +08:00
|
|
|
EXPECT_EQ(drm, nullptr);
|
2018-11-22 05:32:00 +08:00
|
|
|
std::string errStr = ::testing::internal::GetCapturedStderr();
|
|
|
|
EXPECT_THAT(errStr, ::testing::HasSubstr(std::string("FATAL: Unknown device: deviceId: ffffffff, revisionId: 0000")));
|
2020-11-13 23:33:21 +08:00
|
|
|
::testing::internal::GetCapturedStdout();
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2020-12-07 22:50:43 +08:00
|
|
|
TEST_F(DrmTests, GivenNoSoftPinWhenCreatingDrmThenNullIsReturned) {
|
2019-03-28 19:53:48 +08:00
|
|
|
VariableBackup<decltype(haveSoftPin)> backupHaveSoftPin(&haveSoftPin);
|
2017-12-21 07:45:38 +08:00
|
|
|
haveSoftPin = 0;
|
|
|
|
|
2020-02-07 21:32:02 +08:00
|
|
|
auto drm = DrmWrap::createDrm(*rootDeviceEnvironment);
|
2018-07-27 19:59:39 +08:00
|
|
|
EXPECT_EQ(drm, nullptr);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2020-12-07 22:50:43 +08:00
|
|
|
TEST_F(DrmTests, WhenCantFindDeviceIdThenDrmIsNotCreated) {
|
2019-03-28 19:53:48 +08:00
|
|
|
VariableBackup<decltype(failOnDeviceId)> backupFailOnDeviceId(&failOnDeviceId);
|
2017-12-21 07:45:38 +08:00
|
|
|
failOnDeviceId = -1;
|
|
|
|
|
2020-02-07 21:32:02 +08:00
|
|
|
auto drm = DrmWrap::createDrm(*rootDeviceEnvironment);
|
2018-07-27 19:59:39 +08:00
|
|
|
EXPECT_EQ(drm, nullptr);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2020-12-07 22:50:43 +08:00
|
|
|
TEST_F(DrmTests, WhenCantQueryEuCountThenDrmIsNotCreated) {
|
2019-10-18 16:15:09 +08:00
|
|
|
VariableBackup<decltype(failOnEuTotal)> backupfailOnEuTotal(&failOnEuTotal);
|
|
|
|
failOnEuTotal = -1;
|
|
|
|
|
2020-02-07 21:32:02 +08:00
|
|
|
auto drm = DrmWrap::createDrm(*rootDeviceEnvironment);
|
2019-10-18 16:15:09 +08:00
|
|
|
EXPECT_EQ(drm, nullptr);
|
|
|
|
}
|
|
|
|
|
2020-12-07 22:50:43 +08:00
|
|
|
TEST_F(DrmTests, WhenCantQuerySubsliceCountThenDrmIsNotCreated) {
|
2019-10-18 16:15:09 +08:00
|
|
|
VariableBackup<decltype(failOnSubsliceTotal)> backupfailOnSubsliceTotal(&failOnSubsliceTotal);
|
|
|
|
failOnSubsliceTotal = -1;
|
|
|
|
|
2020-02-07 21:32:02 +08:00
|
|
|
auto drm = DrmWrap::createDrm(*rootDeviceEnvironment);
|
2019-10-18 16:15:09 +08:00
|
|
|
EXPECT_EQ(drm, nullptr);
|
|
|
|
}
|
|
|
|
|
2020-12-07 22:50:43 +08:00
|
|
|
TEST_F(DrmTests, WhenCantQueryRevisionIdThenDrmIsNotCreated) {
|
2019-03-28 19:53:48 +08:00
|
|
|
VariableBackup<decltype(failOnRevisionId)> backupFailOnRevisionId(&failOnRevisionId);
|
2017-12-21 07:45:38 +08:00
|
|
|
failOnRevisionId = -1;
|
|
|
|
|
2020-02-07 21:32:02 +08:00
|
|
|
auto drm = DrmWrap::createDrm(*rootDeviceEnvironment);
|
2018-07-27 19:59:39 +08:00
|
|
|
EXPECT_EQ(drm, nullptr);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2020-12-07 22:50:43 +08:00
|
|
|
TEST_F(DrmTests, WhenCantQuerySoftPinSupportThenDrmIsNotCreated) {
|
2019-03-28 19:53:48 +08:00
|
|
|
VariableBackup<decltype(failOnSoftPin)> backupFailOnSoftPin(&failOnSoftPin);
|
2017-12-21 07:45:38 +08:00
|
|
|
failOnSoftPin = -1;
|
|
|
|
|
2020-02-07 21:32:02 +08:00
|
|
|
auto drm = DrmWrap::createDrm(*rootDeviceEnvironment);
|
2018-07-27 19:59:39 +08:00
|
|
|
EXPECT_EQ(drm, nullptr);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2020-12-07 22:50:43 +08:00
|
|
|
TEST_F(DrmTests, GivenFailOnParamBoostWhenCreatingDrmThenDrmIsCreated) {
|
2019-03-28 19:53:48 +08:00
|
|
|
VariableBackup<decltype(failOnParamBoost)> backupFailOnParamBoost(&failOnParamBoost);
|
2017-12-21 07:45:38 +08:00
|
|
|
failOnParamBoost = -1;
|
|
|
|
|
2020-02-07 21:32:02 +08:00
|
|
|
auto drm = DrmWrap::createDrm(*rootDeviceEnvironment);
|
2017-12-21 07:45:38 +08:00
|
|
|
//non-fatal error - issue warning only
|
2018-07-27 19:59:39 +08:00
|
|
|
EXPECT_NE(drm, nullptr);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2020-12-07 22:50:43 +08:00
|
|
|
TEST_F(DrmTests, GivenFailOnContextCreateWhenCreatingDrmThenDrmIsCreated) {
|
2019-03-28 19:53:48 +08:00
|
|
|
VariableBackup<decltype(failOnContextCreate)> backupFailOnContextCreate(&failOnContextCreate);
|
|
|
|
|
2020-02-07 21:32:02 +08:00
|
|
|
auto drm = DrmWrap::createDrm(*rootDeviceEnvironment);
|
2018-07-27 19:59:39 +08:00
|
|
|
EXPECT_NE(drm, nullptr);
|
2017-12-21 07:45:38 +08:00
|
|
|
failOnContextCreate = -1;
|
2021-02-10 23:13:50 +08:00
|
|
|
EXPECT_THROW(drm->createDrmContext(1, false), std::exception);
|
2018-12-07 22:03:23 +08:00
|
|
|
EXPECT_FALSE(drm->isPreemptionSupported());
|
2017-12-21 07:45:38 +08:00
|
|
|
failOnContextCreate = 0;
|
|
|
|
}
|
|
|
|
|
2020-12-07 22:50:43 +08:00
|
|
|
TEST_F(DrmTests, GivenFailOnSetPriorityWhenCreatingDrmThenDrmIsCreated) {
|
2019-03-28 19:53:48 +08:00
|
|
|
VariableBackup<decltype(failOnSetPriority)> backupFailOnSetPriority(&failOnSetPriority);
|
|
|
|
|
2020-02-07 21:32:02 +08:00
|
|
|
auto drm = DrmWrap::createDrm(*rootDeviceEnvironment);
|
2018-07-27 19:59:39 +08:00
|
|
|
EXPECT_NE(drm, nullptr);
|
2017-12-21 07:45:38 +08:00
|
|
|
failOnSetPriority = -1;
|
2021-02-10 23:13:50 +08:00
|
|
|
auto drmContext = drm->createDrmContext(1, false);
|
2018-12-11 15:21:56 +08:00
|
|
|
EXPECT_THROW(drm->setLowPriorityContextParam(drmContext), std::exception);
|
2018-12-07 22:03:23 +08:00
|
|
|
EXPECT_FALSE(drm->isPreemptionSupported());
|
2017-12-21 07:45:38 +08:00
|
|
|
failOnSetPriority = 0;
|
|
|
|
}
|
|
|
|
|
2020-12-07 22:50:43 +08:00
|
|
|
TEST_F(DrmTests, WhenCantQueryDrmVersionThenDrmIsNotCreated) {
|
2019-03-28 19:53:48 +08:00
|
|
|
VariableBackup<decltype(failOnDrmVersion)> backupFailOnDrmVersion(&failOnDrmVersion);
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
failOnDrmVersion = -1;
|
2020-02-07 21:32:02 +08:00
|
|
|
auto drm = DrmWrap::createDrm(*rootDeviceEnvironment);
|
2018-07-27 19:59:39 +08:00
|
|
|
EXPECT_EQ(drm, nullptr);
|
2017-12-21 07:45:38 +08:00
|
|
|
failOnDrmVersion = 0;
|
|
|
|
}
|
|
|
|
|
2020-12-07 22:50:43 +08:00
|
|
|
TEST_F(DrmTests, GivenInvalidDrmVersionNameWhenCreatingDrmThenNullIsReturned) {
|
2019-03-28 19:53:48 +08:00
|
|
|
VariableBackup<decltype(failOnDrmVersion)> backupFailOnDrmVersion(&failOnDrmVersion);
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
strcpy(providedDrmVersion, "NA");
|
2020-02-07 21:32:02 +08:00
|
|
|
auto drm = DrmWrap::createDrm(*rootDeviceEnvironment);
|
2018-07-27 19:59:39 +08:00
|
|
|
EXPECT_EQ(drm, nullptr);
|
2017-12-21 07:45:38 +08:00
|
|
|
failOnDrmVersion = 0;
|
|
|
|
strcpy(providedDrmVersion, "i915");
|
|
|
|
}
|
|
|
|
|
2019-10-15 16:23:04 +08:00
|
|
|
TEST_F(DrmTests, whenDrmIsCreatedThenSetMemoryRegionsDoesntFailAndDrmObjectIsReturned) {
|
|
|
|
DebugManagerStateRestore restore;
|
|
|
|
DebugManager.flags.EnableLocalMemory.set(1);
|
|
|
|
|
2020-02-07 21:32:02 +08:00
|
|
|
auto drm = DrmWrap::createDrm(*rootDeviceEnvironment);
|
2019-10-15 16:23:04 +08:00
|
|
|
EXPECT_NE(drm, nullptr);
|
|
|
|
}
|
|
|
|
|
2019-04-18 21:30:47 +08:00
|
|
|
TEST(AllocatorHelper, givenExpectedSizeToReserveWhenGetSizeToReserveCalledThenExpectedValueReturned) {
|
2019-11-28 01:00:52 +08:00
|
|
|
EXPECT_EQ((maxNBitValue(47) + 1) / 4, NEO::getSizeToReserve());
|
2019-04-18 21:30:47 +08:00
|
|
|
}
|
|
|
|
|
2019-03-15 17:22:35 +08:00
|
|
|
TEST(DrmMemoryManagerCreate, whenCallCreateMemoryManagerThenDrmMemoryManagerIsCreated) {
|
2020-03-23 17:23:43 +08:00
|
|
|
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
|
2020-07-07 15:34:31 +08:00
|
|
|
auto drm = new DrmMockSuccess(fakeFd, *executionEnvironment.rootDeviceEnvironments[0]);
|
2019-03-12 06:06:30 +08:00
|
|
|
|
2020-01-07 14:42:40 +08:00
|
|
|
executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique<OSInterface>();
|
2020-02-12 00:48:40 +08:00
|
|
|
executionEnvironment.rootDeviceEnvironments[0]->osInterface->get()->setDrm(drm);
|
2019-03-15 17:22:35 +08:00
|
|
|
auto drmMemoryManager = MemoryManager::createMemoryManager(executionEnvironment);
|
|
|
|
EXPECT_NE(nullptr, drmMemoryManager.get());
|
2019-03-12 06:06:30 +08:00
|
|
|
executionEnvironment.memoryManager = std::move(drmMemoryManager);
|
|
|
|
}
|
|
|
|
|
2019-07-01 22:22:53 +08:00
|
|
|
TEST(OsInterfaceTests, givenOsInterfaceWhenEnableLocalMemoryIsSpecifiedThenItIsSetToTrueOn64Bit) {
|
|
|
|
EXPECT_TRUE(OSInterface::osEnableLocalMemory);
|
|
|
|
}
|
|
|
|
|
2020-07-07 15:34:31 +08:00
|
|
|
TEST_F(DrmTests, whenDrmIsCreatedWithMultipleSubDevicesThenCreateMultipleVirtualMemoryAddressSpaces) {
|
|
|
|
DebugManagerStateRestore restore;
|
|
|
|
DebugManager.flags.CreateMultipleSubDevices.set(2);
|
|
|
|
|
|
|
|
auto drm = DrmWrap::createDrm(*rootDeviceEnvironment);
|
|
|
|
EXPECT_NE(drm, nullptr);
|
|
|
|
|
|
|
|
auto numSubDevices = HwHelper::getSubDevicesCount(rootDeviceEnvironment->getHardwareInfo());
|
|
|
|
for (auto id = 0u; id < numSubDevices; id++) {
|
|
|
|
EXPECT_EQ(id + 1, drm->getVirtualMemoryAddressSpace(id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-23 22:31:20 +08:00
|
|
|
TEST_F(DrmTests, givenDebuggingEnabledWhenDrmIsCreatedThenPerContextVMIsTrueGetVirtualMemoryAddressSpaceReturnsZeroAndVMsAreNotCreated) {
|
2020-07-15 14:07:53 +08:00
|
|
|
DebugManagerStateRestore restore;
|
|
|
|
DebugManager.flags.CreateMultipleSubDevices.set(2);
|
2020-11-23 22:31:20 +08:00
|
|
|
DebugManager.flags.UseVmBind.set(1);
|
|
|
|
|
|
|
|
rootDeviceEnvironment->executionEnvironment.setDebuggingEnabled();
|
|
|
|
|
|
|
|
auto drm = DrmWrap::createDrm(*rootDeviceEnvironment);
|
|
|
|
ASSERT_NE(drm, nullptr);
|
|
|
|
if (drm->isVmBindAvailable()) {
|
|
|
|
EXPECT_TRUE(drm->isPerContextVMRequired());
|
|
|
|
|
|
|
|
auto numSubDevices = HwHelper::getSubDevicesCount(rootDeviceEnvironment->getHardwareInfo());
|
|
|
|
for (auto id = 0u; id < numSubDevices; id++) {
|
|
|
|
EXPECT_EQ(0u, drm->getVirtualMemoryAddressSpace(id));
|
|
|
|
}
|
|
|
|
EXPECT_EQ(0u, static_cast<DrmWrap *>(drm.get())->virtualMemoryIds.size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DrmTests, givenEnabledDebuggingAndVmBindNotAvailableWhenDrmIsCreatedThenPerContextVMIsFalseVMsAreCreatedAndDebugMessageIsPrinted) {
|
|
|
|
DebugManagerStateRestore restore;
|
|
|
|
|
|
|
|
::testing::internal::CaptureStderr();
|
|
|
|
::testing::internal::CaptureStdout();
|
|
|
|
|
|
|
|
DebugManager.flags.CreateMultipleSubDevices.set(2);
|
|
|
|
DebugManager.flags.UseVmBind.set(0);
|
|
|
|
DebugManager.flags.PrintDebugMessages.set(true);
|
2020-07-15 14:07:53 +08:00
|
|
|
|
2020-11-23 22:31:20 +08:00
|
|
|
rootDeviceEnvironment->executionEnvironment.setDebuggingEnabled();
|
2020-07-15 14:07:53 +08:00
|
|
|
|
|
|
|
auto drm = DrmWrap::createDrm(*rootDeviceEnvironment);
|
|
|
|
EXPECT_NE(drm, nullptr);
|
2020-11-23 22:31:20 +08:00
|
|
|
EXPECT_FALSE(drm->isPerContextVMRequired());
|
2020-07-15 14:07:53 +08:00
|
|
|
|
|
|
|
auto numSubDevices = HwHelper::getSubDevicesCount(rootDeviceEnvironment->getHardwareInfo());
|
|
|
|
for (auto id = 0u; id < numSubDevices; id++) {
|
2020-11-23 22:31:20 +08:00
|
|
|
EXPECT_NE(0u, drm->getVirtualMemoryAddressSpace(id));
|
2020-07-15 14:07:53 +08:00
|
|
|
}
|
2020-11-23 22:31:20 +08:00
|
|
|
EXPECT_NE(0u, static_cast<DrmWrap *>(drm.get())->virtualMemoryIds.size());
|
|
|
|
|
|
|
|
DebugManager.flags.PrintDebugMessages.set(false);
|
|
|
|
::testing::internal::GetCapturedStdout();
|
|
|
|
std::string errStr = ::testing::internal::GetCapturedStderr();
|
|
|
|
|
|
|
|
EXPECT_THAT(errStr, ::testing::HasSubstr(std::string("WARNING: Debugging not supported\n")));
|
2020-07-15 14:07:53 +08:00
|
|
|
}
|
|
|
|
|
2020-07-14 10:36:16 +08:00
|
|
|
TEST_F(DrmTests, givenDrmIsCreatedWhenCreateVirtualMemoryFailsThenReturnVirtualMemoryIdZeroAndPrintDebugMessage) {
|
|
|
|
DebugManagerStateRestore dbgRestorer;
|
|
|
|
DebugManager.flags.PrintDebugMessages.set(true);
|
|
|
|
|
|
|
|
VariableBackup<decltype(failOnVirtualMemoryCreate)> backupFailOnVirtualMemoryCreate(&failOnVirtualMemoryCreate);
|
2020-07-07 15:34:31 +08:00
|
|
|
|
|
|
|
failOnVirtualMemoryCreate = -1;
|
2020-07-14 10:36:16 +08:00
|
|
|
|
|
|
|
::testing::internal::CaptureStderr();
|
2020-11-13 23:33:21 +08:00
|
|
|
::testing::internal::CaptureStdout();
|
2020-07-14 10:36:16 +08:00
|
|
|
auto drm = DrmWrap::createDrm(*rootDeviceEnvironment);
|
|
|
|
EXPECT_NE(drm, nullptr);
|
|
|
|
|
|
|
|
EXPECT_EQ(0u, drm->getVirtualMemoryAddressSpace(0));
|
|
|
|
EXPECT_EQ(0u, static_cast<DrmWrap *>(drm.get())->virtualMemoryIds.size());
|
|
|
|
|
|
|
|
std::string errStr = ::testing::internal::GetCapturedStderr();
|
|
|
|
EXPECT_THAT(errStr, ::testing::HasSubstr(std::string("INFO: Device doesn't support GEM Virtual Memory")));
|
2020-11-13 23:33:21 +08:00
|
|
|
::testing::internal::GetCapturedStdout();
|
2020-07-07 15:34:31 +08:00
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
int main(int argc, char **argv) {
|
2018-02-16 17:15:42 +08:00
|
|
|
bool useDefaultListener = false;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
|
|
|
|
|
|
// parse remaining args assuming they're mine
|
|
|
|
for (int i = 1; i < argc; ++i) {
|
|
|
|
if (!strcmp("--disable_default_listener", argv[i])) {
|
|
|
|
useDefaultListener = false;
|
2018-02-16 17:15:42 +08:00
|
|
|
} else if (!strcmp("--enable_default_listener", argv[i])) {
|
|
|
|
useDefaultListener = true;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (useDefaultListener == false) {
|
|
|
|
auto &listeners = ::testing::UnitTest::GetInstance()->listeners();
|
|
|
|
auto defaultListener = listeners.default_result_printer();
|
|
|
|
auto customEventListener = new CCustomEventListener(defaultListener);
|
|
|
|
|
|
|
|
listeners.Release(defaultListener);
|
|
|
|
listeners.Append(customEventListener);
|
|
|
|
}
|
|
|
|
|
2020-03-23 17:23:43 +08:00
|
|
|
defaultHwInfo = std::make_unique<HardwareInfo>();
|
|
|
|
*defaultHwInfo = DEFAULT_TEST_PLATFORM::hwInfo;
|
|
|
|
|
2019-03-27 19:44:49 +08:00
|
|
|
initializeTestedDevice();
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
auto retVal = RUN_ALL_TESTS();
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
}
|
2020-01-30 22:04:19 +08:00
|
|
|
|
|
|
|
TEST_F(DrmTests, whenCreateDrmIsCalledThenProperHwInfoIsSetup) {
|
2020-03-04 15:51:02 +08:00
|
|
|
auto oldHwInfo = rootDeviceEnvironment->getMutableHardwareInfo();
|
2020-01-30 22:04:19 +08:00
|
|
|
*oldHwInfo = {};
|
2020-02-07 21:32:02 +08:00
|
|
|
auto drm = DrmWrap::createDrm(*rootDeviceEnvironment);
|
2020-01-30 22:04:19 +08:00
|
|
|
EXPECT_NE(drm, nullptr);
|
2020-03-04 15:51:02 +08:00
|
|
|
auto currentHwInfo = rootDeviceEnvironment->getHardwareInfo();
|
2020-01-30 22:04:19 +08:00
|
|
|
EXPECT_NE(IGFX_UNKNOWN, currentHwInfo->platform.eProductFamily);
|
|
|
|
EXPECT_NE(IGFX_UNKNOWN_CORE, currentHwInfo->platform.eRenderCoreFamily);
|
|
|
|
EXPECT_LT(0u, currentHwInfo->gtSystemInfo.EUCount);
|
|
|
|
EXPECT_LT(0u, currentHwInfo->gtSystemInfo.SubSliceCount);
|
|
|
|
}
|
2020-09-01 18:38:50 +08:00
|
|
|
|
|
|
|
TEST(PlatformsDestructor, whenGlobalPlatformsDestructorIsCalledThenGlobalPlatformsAreDestroyed) {
|
|
|
|
EXPECT_NE(nullptr, platformsImpl);
|
|
|
|
platformsDestructor();
|
|
|
|
|
|
|
|
EXPECT_EQ(nullptr, platformsImpl);
|
|
|
|
platformsImpl = new std::vector<std::unique_ptr<Platform>>;
|
|
|
|
}
|