mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-08 14:02:58 +08:00
Stop using CONTEXT_SET_PARAM
Related-To: NEO-5881 Signed-off-by: Piotr Obst <piotr.obst@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
ce12c97a74
commit
e9f56e7d96
@@ -31,6 +31,7 @@ set(IGDRCL_SRCS_tests_os_interface_linux
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/drm_residency_handler_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/drm_system_info_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/drm_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/drm_context_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/drm_uuid_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/file_logger_linux_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/hw_info_config_linux_tests.cpp
|
||||
|
||||
129
opencl/test/unit_test/os_interface/linux/drm_context_tests.cpp
Normal file
129
opencl/test/unit_test/os_interface/linux/drm_context_tests.cpp
Normal file
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/source/os_interface/linux/os_context_linux.h"
|
||||
#include "shared/test/common/helpers/default_hw_info.h"
|
||||
#include "shared/test/common/helpers/engine_descriptor_helper.h"
|
||||
|
||||
#include "opencl/test/unit_test/os_interface/linux/drm_mock.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace NEO;
|
||||
|
||||
TEST(DrmTest, givenDrmWhenOsContextIsCreatedThenCreateAndDestroyNewDrmOsContext) {
|
||||
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
|
||||
executionEnvironment->prepareRootDeviceEnvironments(1);
|
||||
DrmMock drmMock(*executionEnvironment->rootDeviceEnvironments[0]);
|
||||
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
|
||||
|
||||
{
|
||||
OsContextLinux osContext1(drmMock, 0u, EngineDescriptorHelper::getDefaultDescriptor());
|
||||
osContext1.ensureContextInitialized();
|
||||
|
||||
EXPECT_EQ(1u, osContext1.getDrmContextIds().size());
|
||||
EXPECT_EQ(drmMock.receivedCreateContextId, osContext1.getDrmContextIds()[0]);
|
||||
EXPECT_EQ(0u, drmMock.receivedDestroyContextId);
|
||||
|
||||
{
|
||||
OsContextLinux osContext2(drmMock, 0u, EngineDescriptorHelper::getDefaultDescriptor());
|
||||
osContext2.ensureContextInitialized();
|
||||
EXPECT_EQ(1u, osContext2.getDrmContextIds().size());
|
||||
EXPECT_EQ(drmMock.receivedCreateContextId, osContext2.getDrmContextIds()[0]);
|
||||
EXPECT_EQ(0u, drmMock.receivedDestroyContextId);
|
||||
}
|
||||
}
|
||||
|
||||
EXPECT_EQ(2u, drmMock.receivedContextParamRequestCount);
|
||||
}
|
||||
|
||||
TEST(DrmTest, whenCreatingDrmContextWithVirtualMemoryAddressSpaceThenProperVmIdIsSet) {
|
||||
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
|
||||
executionEnvironment->prepareRootDeviceEnvironments(1);
|
||||
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
|
||||
DrmMock drmMock(*executionEnvironment->rootDeviceEnvironments[0]);
|
||||
|
||||
ASSERT_EQ(1u, drmMock.virtualMemoryIds.size());
|
||||
|
||||
OsContextLinux osContext(drmMock, 0u, EngineDescriptorHelper::getDefaultDescriptor());
|
||||
osContext.ensureContextInitialized();
|
||||
|
||||
EXPECT_EQ(drmMock.receivedContextParamRequest.value, drmMock.getVirtualMemoryAddressSpace(0u));
|
||||
}
|
||||
|
||||
TEST(DrmTest, givenDrmAndNegativeCheckNonPersistentContextsSupportWhenOsContextIsCreatedThenReceivedContextParamRequestCountReturnsCorrectValue) {
|
||||
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
|
||||
executionEnvironment->prepareRootDeviceEnvironments(1);
|
||||
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
|
||||
DrmMock drmMock(*executionEnvironment->rootDeviceEnvironments[0]);
|
||||
auto expectedCount = 0u;
|
||||
|
||||
{
|
||||
drmMock.storedRetValForPersistant = -1;
|
||||
drmMock.checkNonPersistentContextsSupport();
|
||||
expectedCount += 2;
|
||||
OsContextLinux osContext(drmMock, 0u, EngineDescriptorHelper::getDefaultDescriptor());
|
||||
osContext.ensureContextInitialized();
|
||||
EXPECT_EQ(expectedCount, drmMock.receivedContextParamRequestCount);
|
||||
}
|
||||
{
|
||||
drmMock.storedRetValForPersistant = 0;
|
||||
drmMock.checkNonPersistentContextsSupport();
|
||||
++expectedCount;
|
||||
OsContextLinux osContext(drmMock, 0u, EngineDescriptorHelper::getDefaultDescriptor());
|
||||
osContext.ensureContextInitialized();
|
||||
expectedCount += 2;
|
||||
EXPECT_EQ(expectedCount, drmMock.receivedContextParamRequestCount);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(DrmTest, givenDrmPreemptionEnabledAndLowPriorityEngineWhenCreatingOsContextThenCallSetContextPriorityIoctl) {
|
||||
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
|
||||
executionEnvironment->prepareRootDeviceEnvironments(1);
|
||||
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
|
||||
DrmMock drmMock(*executionEnvironment->rootDeviceEnvironments[0]);
|
||||
drmMock.preemptionSupported = false;
|
||||
|
||||
OsContextLinux osContext1(drmMock, 0u, EngineDescriptorHelper::getDefaultDescriptor());
|
||||
osContext1.ensureContextInitialized();
|
||||
OsContextLinux osContext2(drmMock, 0u, EngineDescriptorHelper::getDefaultDescriptor({aub_stream::ENGINE_RCS, EngineUsage::LowPriority}));
|
||||
osContext2.ensureContextInitialized();
|
||||
|
||||
EXPECT_EQ(2u, drmMock.receivedContextParamRequestCount);
|
||||
|
||||
drmMock.preemptionSupported = true;
|
||||
|
||||
OsContextLinux osContext3(drmMock, 0u, EngineDescriptorHelper::getDefaultDescriptor());
|
||||
osContext3.ensureContextInitialized();
|
||||
EXPECT_EQ(3u, drmMock.receivedContextParamRequestCount);
|
||||
|
||||
OsContextLinux osContext4(drmMock, 0u, EngineDescriptorHelper::getDefaultDescriptor({aub_stream::ENGINE_RCS, EngineUsage::LowPriority}));
|
||||
osContext4.ensureContextInitialized();
|
||||
EXPECT_EQ(5u, drmMock.receivedContextParamRequestCount);
|
||||
EXPECT_EQ(drmMock.receivedCreateContextId, drmMock.receivedContextParamRequest.ctx_id);
|
||||
EXPECT_EQ(static_cast<uint64_t>(I915_CONTEXT_PARAM_PRIORITY), drmMock.receivedContextParamRequest.param);
|
||||
EXPECT_EQ(static_cast<uint64_t>(-1023), drmMock.receivedContextParamRequest.value);
|
||||
EXPECT_EQ(0u, drmMock.receivedContextParamRequest.size);
|
||||
}
|
||||
|
||||
TEST(DrmTest, givenNoPerContextVmsDrmWhenCreatingOsContextsThenVmIdIsNotQueriedAndStored) {
|
||||
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
|
||||
executionEnvironment->prepareRootDeviceEnvironments(1);
|
||||
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
|
||||
DrmMock drmMock(*executionEnvironment->rootDeviceEnvironments[0]);
|
||||
EXPECT_FALSE(drmMock.requirePerContextVM);
|
||||
|
||||
drmMock.storedRetValForVmId = 1;
|
||||
|
||||
OsContextLinux osContext(drmMock, 0u, EngineDescriptorHelper::getDefaultDescriptor());
|
||||
osContext.ensureContextInitialized();
|
||||
EXPECT_EQ(0u, drmMock.receivedCreateContextId);
|
||||
EXPECT_EQ(1u, drmMock.receivedContextParamRequestCount);
|
||||
|
||||
auto &drmVmIds = osContext.getDrmVmIds();
|
||||
EXPECT_EQ(0u, drmVmIds.size());
|
||||
}
|
||||
@@ -74,6 +74,7 @@ int DrmMock::ioctl(unsigned long request, void *arg) {
|
||||
auto create = static_cast<drm_i915_gem_context_create_ext *>(arg);
|
||||
this->receivedCreateContextId = create->ctx_id;
|
||||
this->receivedContextCreateFlags = create->flags;
|
||||
this->receivedContextCreateExtensions = create->extensions;
|
||||
return this->storedRetVal;
|
||||
}
|
||||
|
||||
|
||||
@@ -150,6 +150,7 @@ class DrmMock : public Drm {
|
||||
bool allowDebugAttachCallBase = false;
|
||||
uint32_t passedContextDebugId = std::numeric_limits<uint32_t>::max();
|
||||
|
||||
uint64_t receivedContextCreateExtensions = 0;
|
||||
uint32_t receivedContextCreateFlags = 0;
|
||||
uint32_t receivedCreateContextId = 0;
|
||||
uint32_t receivedDestroyContextId = 0;
|
||||
|
||||
@@ -5,24 +5,16 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/source/helpers/file_io.h"
|
||||
#include "shared/source/helpers/hw_info.h"
|
||||
#include "shared/source/os_interface/device_factory.h"
|
||||
#include "shared/source/os_interface/linux/os_context_linux.h"
|
||||
#include "shared/source/os_interface/os_interface.h"
|
||||
#include "shared/test/common/helpers/debug_manager_state_restore.h"
|
||||
#include "shared/test/common/helpers/default_hw_info.h"
|
||||
#include "shared/test/common/helpers/engine_descriptor_helper.h"
|
||||
|
||||
#include "opencl/test/unit_test/fixtures/memory_management_fixture.h"
|
||||
#include "opencl/test/unit_test/mocks/mock_platform.h"
|
||||
#include "opencl/test/unit_test/os_interface/linux/drm_mock.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
|
||||
using namespace NEO;
|
||||
|
||||
TEST(DrmTest, WhenGettingDeviceIdThenCorrectIdReturned) {
|
||||
@@ -186,46 +178,6 @@ TEST(DrmTest, GivenDrmWhenAskedForContextThatFailsThenFalseIsReturned) {
|
||||
delete pDrm;
|
||||
}
|
||||
|
||||
TEST(DrmTest, givenDrmWhenOsContextIsCreatedThenCreateAndDestroyNewDrmOsContext) {
|
||||
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
|
||||
executionEnvironment->prepareRootDeviceEnvironments(1);
|
||||
DrmMock drmMock(*executionEnvironment->rootDeviceEnvironments[0]);
|
||||
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
|
||||
|
||||
{
|
||||
OsContextLinux osContext1(drmMock, 0u, EngineDescriptorHelper::getDefaultDescriptor());
|
||||
osContext1.ensureContextInitialized();
|
||||
|
||||
EXPECT_EQ(1u, osContext1.getDrmContextIds().size());
|
||||
EXPECT_EQ(drmMock.receivedCreateContextId, osContext1.getDrmContextIds()[0]);
|
||||
EXPECT_EQ(0u, drmMock.receivedDestroyContextId);
|
||||
|
||||
{
|
||||
OsContextLinux osContext2(drmMock, 0u, EngineDescriptorHelper::getDefaultDescriptor());
|
||||
osContext2.ensureContextInitialized();
|
||||
EXPECT_EQ(1u, osContext2.getDrmContextIds().size());
|
||||
EXPECT_EQ(drmMock.receivedCreateContextId, osContext2.getDrmContextIds()[0]);
|
||||
EXPECT_EQ(0u, drmMock.receivedDestroyContextId);
|
||||
}
|
||||
}
|
||||
|
||||
EXPECT_EQ(2u, drmMock.receivedContextParamRequestCount);
|
||||
}
|
||||
|
||||
TEST(DrmTest, whenCreatingDrmContextWithVirtualMemoryAddressSpaceThenProperVmIdIsSet) {
|
||||
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
|
||||
executionEnvironment->prepareRootDeviceEnvironments(1);
|
||||
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
|
||||
DrmMock drmMock(*executionEnvironment->rootDeviceEnvironments[0]);
|
||||
|
||||
ASSERT_EQ(1u, drmMock.virtualMemoryIds.size());
|
||||
|
||||
OsContextLinux osContext(drmMock, 0u, EngineDescriptorHelper::getDefaultDescriptor());
|
||||
osContext.ensureContextInitialized();
|
||||
|
||||
EXPECT_EQ(drmMock.receivedContextParamRequest.value, drmMock.getVirtualMemoryAddressSpace(0u));
|
||||
}
|
||||
|
||||
TEST(DrmTest, whenCreatingDrmContextWithNoVirtualMemoryAddressSpaceThenProperContextIdIsSet) {
|
||||
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
|
||||
executionEnvironment->prepareRootDeviceEnvironments(1);
|
||||
@@ -242,61 +194,6 @@ TEST(DrmTest, whenCreatingDrmContextWithNoVirtualMemoryAddressSpaceThenProperCon
|
||||
EXPECT_EQ(0u, drmMock.receivedContextParamRequestCount);
|
||||
}
|
||||
|
||||
TEST(DrmTest, givenDrmAndNegativeCheckNonPersistentContextsSupportWhenOsContextIsCreatedThenReceivedContextParamRequestCountReturnsCorrectValue) {
|
||||
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
|
||||
executionEnvironment->prepareRootDeviceEnvironments(1);
|
||||
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
|
||||
DrmMock drmMock(*executionEnvironment->rootDeviceEnvironments[0]);
|
||||
auto expectedCount = 0u;
|
||||
|
||||
{
|
||||
drmMock.storedRetValForPersistant = -1;
|
||||
drmMock.checkNonPersistentContextsSupport();
|
||||
expectedCount += 2;
|
||||
OsContextLinux osContext(drmMock, 0u, EngineDescriptorHelper::getDefaultDescriptor());
|
||||
osContext.ensureContextInitialized();
|
||||
EXPECT_EQ(expectedCount, drmMock.receivedContextParamRequestCount);
|
||||
}
|
||||
{
|
||||
drmMock.storedRetValForPersistant = 0;
|
||||
drmMock.checkNonPersistentContextsSupport();
|
||||
++expectedCount;
|
||||
OsContextLinux osContext(drmMock, 0u, EngineDescriptorHelper::getDefaultDescriptor());
|
||||
osContext.ensureContextInitialized();
|
||||
expectedCount += 2;
|
||||
EXPECT_EQ(expectedCount, drmMock.receivedContextParamRequestCount);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(DrmTest, givenDrmPreemptionEnabledAndLowPriorityEngineWhenCreatingOsContextThenCallSetContextPriorityIoctl) {
|
||||
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
|
||||
executionEnvironment->prepareRootDeviceEnvironments(1);
|
||||
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
|
||||
DrmMock drmMock(*executionEnvironment->rootDeviceEnvironments[0]);
|
||||
drmMock.preemptionSupported = false;
|
||||
|
||||
OsContextLinux osContext1(drmMock, 0u, EngineDescriptorHelper::getDefaultDescriptor());
|
||||
osContext1.ensureContextInitialized();
|
||||
OsContextLinux osContext2(drmMock, 0u, EngineDescriptorHelper::getDefaultDescriptor({aub_stream::ENGINE_RCS, EngineUsage::LowPriority}));
|
||||
osContext2.ensureContextInitialized();
|
||||
|
||||
EXPECT_EQ(2u, drmMock.receivedContextParamRequestCount);
|
||||
|
||||
drmMock.preemptionSupported = true;
|
||||
|
||||
OsContextLinux osContext3(drmMock, 0u, EngineDescriptorHelper::getDefaultDescriptor());
|
||||
osContext3.ensureContextInitialized();
|
||||
EXPECT_EQ(3u, drmMock.receivedContextParamRequestCount);
|
||||
|
||||
OsContextLinux osContext4(drmMock, 0u, EngineDescriptorHelper::getDefaultDescriptor({aub_stream::ENGINE_RCS, EngineUsage::LowPriority}));
|
||||
osContext4.ensureContextInitialized();
|
||||
EXPECT_EQ(5u, drmMock.receivedContextParamRequestCount);
|
||||
EXPECT_EQ(drmMock.receivedCreateContextId, drmMock.receivedContextParamRequest.ctx_id);
|
||||
EXPECT_EQ(static_cast<uint64_t>(I915_CONTEXT_PARAM_PRIORITY), drmMock.receivedContextParamRequest.param);
|
||||
EXPECT_EQ(static_cast<uint64_t>(-1023), drmMock.receivedContextParamRequest.value);
|
||||
EXPECT_EQ(0u, drmMock.receivedContextParamRequest.size);
|
||||
}
|
||||
|
||||
TEST(DrmTest, WhenGettingExecSoftPinThenCorrectValueIsReturned) {
|
||||
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
|
||||
executionEnvironment->prepareRootDeviceEnvironments(1);
|
||||
@@ -577,24 +474,6 @@ TEST(DrmTest, givenPerContextVMRequiredWhenCreatingOsContextsForRootDeviceThenIm
|
||||
EXPECT_EQ(0u, drmVmIds[31]);
|
||||
}
|
||||
|
||||
TEST(DrmTest, givenNoPerContextVmsDrmWhenCreatingOsContextsThenVmIdIsNotQueriedAndStored) {
|
||||
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
|
||||
executionEnvironment->prepareRootDeviceEnvironments(1);
|
||||
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
|
||||
DrmMock drmMock(*executionEnvironment->rootDeviceEnvironments[0]);
|
||||
EXPECT_FALSE(drmMock.requirePerContextVM);
|
||||
|
||||
drmMock.storedRetValForVmId = 1;
|
||||
|
||||
OsContextLinux osContext(drmMock, 0u, EngineDescriptorHelper::getDefaultDescriptor());
|
||||
osContext.ensureContextInitialized();
|
||||
EXPECT_EQ(0u, drmMock.receivedCreateContextId);
|
||||
EXPECT_EQ(1u, drmMock.receivedContextParamRequestCount);
|
||||
|
||||
auto &drmVmIds = osContext.getDrmVmIds();
|
||||
EXPECT_EQ(0u, drmVmIds.size());
|
||||
}
|
||||
|
||||
TEST(DrmTest, givenProgramDebuggingAndContextDebugAvailableWhenCreatingContextThenSetContextDebugFlagIsCalled) {
|
||||
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
|
||||
executionEnvironment->setDebuggingEnabled();
|
||||
|
||||
Reference in New Issue
Block a user