test: Move linux specific tests to shared

Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2022-05-23 18:14:48 +00:00
committed by Compute-Runtime-Automation
parent 2bc0402deb
commit f8983a8ecf
21 changed files with 33 additions and 38 deletions

View File

@@ -6,19 +6,33 @@
set(NEO_CORE_OS_INTERFACE_TESTS_LINUX
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/allocator_helper_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/debug_env_reader.cpp
${CMAKE_CURRENT_SOURCE_DIR}/device_command_stream_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/device_factory_tests_linux.cpp
${CMAKE_CURRENT_SOURCE_DIR}/device_factory_tests_linux.h
${CMAKE_CURRENT_SOURCE_DIR}/driver_info_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/drm_bind_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/drm_buffer_object_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/drm_command_stream_mm_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/drm_command_stream_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/drm_engine_info_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/drm_version_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/drm_mapper_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/drm_mock_impl.h
${CMAKE_CURRENT_SOURCE_DIR}/drm_os_memory_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/drm_pci_speed_info_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/drm_query_topology_upstream_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/drm_residency_handler_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/drm_special_heap_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/drm_system_info_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/drm_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/drm_uuid_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/drm_version_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/hw_info_config_uuid_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/os_context_linux_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/os_interface_linux_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/os_library_linux_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/os_time_test.cpp
)
if(NEO_ENABLE_i915_PRELIM_DETECTION)
@@ -32,6 +46,7 @@ if(NEO_ENABLE_i915_PRELIM_DETECTION)
${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_info_prelim_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_manager_debug_surface_prelim_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_manager_localmem_prelim_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/drm_residency_handler_prelim_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/drm_with_prelim_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/drm_vm_bind_prelim_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ioctl_helper_tests_prelim.cpp
@@ -49,6 +64,11 @@ if(NEO_ENABLE_i915_PRELIM_DETECTION)
)
endif()
endif()
if(TESTS_XEHP_AND_LATER)
list(APPEND NEO_CORE_OS_INTERFACE_TESTS_LINUX
${CMAKE_CURRENT_SOURCE_DIR}/drm_command_stream_xehp_and_later_tests.cpp
)
endif()
if("${BRANCH_TYPE}" STREQUAL "")
list(APPEND NEO_CORE_OS_INTERFACE_TESTS_LINUX

View File

@@ -0,0 +1,15 @@
/*
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/helpers/constants.h"
#include "shared/source/os_interface/linux/allocator_helper.h"
#include "gtest/gtest.h"
TEST(AllocatorHelper, givenExpectedSizeToReserveWhenGetSizeToReserveCalledThenExpectedValueReturned) {
EXPECT_EQ((4 * 4 + 2 * 4) * GB, NEO::getSizeToReserve());
}

View File

@@ -0,0 +1,121 @@
/*
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/os_interface/debug_env_reader.h"
#include "shared/test/common/helpers/variable_backup.h"
#include "shared/test/common/mocks/mock_io_functions.h"
#include "shared/test/common/test_macros/test.h"
#include <memory>
#include <unordered_map>
namespace NEO {
class DebugEnvReaderTests : public ::testing::Test {
public:
void SetUp() override {
evr = SettingsReader::createOsReader(false, "");
EXPECT_NE(nullptr, evr);
}
void TearDown() override {
delete evr;
}
SettingsReader *evr = nullptr;
};
TEST_F(DebugEnvReaderTests, GivenSetVariableThenSetValueIsReturned) {
int32_t ret;
std::string retString;
std::string defaultString = "Default Value";
std::string setString = "Expected Value";
const char *testingVariableName = "TestingVariable";
const char *testingVariableValue = "1234";
{
VariableBackup<uint32_t> mockGetenvCalledBackup(&IoFunctions::mockGetenvCalled, 0);
std::unordered_map<std::string, std::string> mockableEnvs = {{testingVariableName, testingVariableValue}};
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs);
ret = evr->getSetting(testingVariableName, 1);
EXPECT_EQ(1u, IoFunctions::mockGetenvCalled);
EXPECT_EQ(1234, ret);
}
{
VariableBackup<uint32_t> mockGetenvCalledBackup(&IoFunctions::mockGetenvCalled, 0);
std::unordered_map<std::string, std::string> mockableEnvs = {{testingVariableName, setString.c_str()}};
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs);
retString = evr->getSetting("TestingVariable", defaultString);
EXPECT_EQ(1u, IoFunctions::mockGetenvCalled);
EXPECT_EQ(0, retString.compare(setString));
}
{
VariableBackup<uint32_t> mockGetenvCalledBackup(&IoFunctions::mockGetenvCalled, 0);
std::unordered_map<std::string, std::string> mockableEnvs = {};
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs);
ret = evr->getSetting("TestingVariable", 1);
EXPECT_EQ(1u, IoFunctions::mockGetenvCalled);
EXPECT_EQ(1, ret);
}
}
TEST_F(DebugEnvReaderTests, GivenUnsetVariableThenDefaultValueIsReturned) {
int32_t ret;
std::string retString;
std::string defaultString = "Default Value";
VariableBackup<uint32_t> mockGetenvCalledBackup(&IoFunctions::mockGetenvCalled, 0);
std::unordered_map<std::string, std::string> mockableEnvs = {};
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs);
ret = evr->getSetting("TestingVariable", 1);
EXPECT_EQ(1u, IoFunctions::mockGetenvCalled);
EXPECT_EQ(1, ret);
retString = evr->getSetting("TestingVariable", defaultString);
EXPECT_EQ(2u, IoFunctions::mockGetenvCalled);
EXPECT_EQ(0, retString.compare(defaultString));
}
TEST_F(DebugEnvReaderTests, GivenBoolEnvVariableWhenGettingThenCorrectValueIsReturned) {
bool ret;
bool defaultValue = true;
bool expectedValue = false;
{
VariableBackup<uint32_t> mockGetenvCalledBackup(&IoFunctions::mockGetenvCalled, 0);
std::unordered_map<std::string, std::string> mockableEnvs = {{"TestingVariable", "0"}};
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs);
ret = evr->getSetting("TestingVariable", defaultValue);
EXPECT_EQ(1u, IoFunctions::mockGetenvCalled);
EXPECT_EQ(expectedValue, ret);
}
{
VariableBackup<uint32_t> mockGetenvCalledBackup(&IoFunctions::mockGetenvCalled, 0);
std::unordered_map<std::string, std::string> mockableEnvs = {};
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs);
ret = evr->getSetting("TestingVariable", defaultValue);
EXPECT_EQ(1u, IoFunctions::mockGetenvCalled);
EXPECT_EQ(defaultValue, ret);
}
}
TEST_F(DebugEnvReaderTests, WhenSettingAppSpecificLocationThenLocationIsReturned) {
std::string appSpecific;
appSpecific = "cl_cache_dir";
EXPECT_EQ(appSpecific, evr->appSpecificLocation(appSpecific));
}
TEST_F(DebugEnvReaderTests, givenEnvironmentVariableReaderWhenCreateOsReaderWithStringThenNotNullPointer) {
std::unique_ptr<SettingsReader> evr(SettingsReader::createOsReader(false, ""));
EXPECT_NE(nullptr, evr);
}
} // namespace NEO

View File

@@ -0,0 +1,108 @@
/*
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/command_stream/aub_command_stream_receiver.h"
#include "shared/source/command_stream/command_stream_receiver.h"
#include "shared/source/command_stream/device_command_stream.h"
#include "shared/source/command_stream/linear_stream.h"
#include "shared/source/os_interface/linux/device_command_stream.inl"
#include "shared/source/os_interface/linux/drm_command_stream.h"
#include "shared/source/os_interface/linux/drm_neo.h"
#include "shared/source/os_interface/os_interface.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/helpers/execution_environment_helper.h"
#include "shared/test/common/os_interface/linux/device_command_stream_fixture.h"
#include "shared/test/common/test_macros/test.h"
#include "shared/test/unit_test/fixtures/mock_aub_center_fixture.h"
#include "gtest/gtest.h"
#include <memory>
using namespace NEO;
struct DeviceCommandStreamLeaksTest : ::testing::Test {
void SetUp() override {
HardwareInfo *hwInfo = nullptr;
executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1);
executionEnvironment->incRefInternal();
MockAubCenterFixture::setMockAubCenter(*executionEnvironment->rootDeviceEnvironments[0]);
}
void TearDown() override {
executionEnvironment->decRefInternal();
}
ExecutionEnvironment *executionEnvironment;
};
HWTEST_F(DeviceCommandStreamLeaksTest, WhenCreatingDeviceCsrThenValidPointerIsReturned) {
std::unique_ptr<CommandStreamReceiver> ptr(DeviceCommandStreamReceiver<FamilyType>::create(false, *executionEnvironment, 0, 1));
DrmMockSuccess mockDrm(mockFd, *executionEnvironment->rootDeviceEnvironments[0]);
EXPECT_NE(nullptr, ptr);
}
HWTEST_F(DeviceCommandStreamLeaksTest, givenDefaultDrmCsrWhenItIsCreatedThenGemCloseWorkerInactiveModeIsSelected) {
std::unique_ptr<CommandStreamReceiver> ptr(DeviceCommandStreamReceiver<FamilyType>::create(false, *executionEnvironment, 0, 1));
auto drmCsr = (DrmCommandStreamReceiver<FamilyType> *)ptr.get();
EXPECT_EQ(drmCsr->peekGemCloseWorkerOperationMode(), gemCloseWorkerMode::gemCloseWorkerActive);
}
HWTEST_F(DeviceCommandStreamLeaksTest, givenDefaultDrmCsrWithAubDumWhenItIsCreatedThenGemCloseWorkerInactiveModeIsSelected) {
std::unique_ptr<CommandStreamReceiver> ptr(DeviceCommandStreamReceiver<FamilyType>::create(true, *executionEnvironment, 0, 1));
auto drmCsrWithAubDump = (CommandStreamReceiverWithAUBDump<DrmCommandStreamReceiver<FamilyType>> *)ptr.get();
EXPECT_EQ(drmCsrWithAubDump->peekGemCloseWorkerOperationMode(), gemCloseWorkerMode::gemCloseWorkerActive);
auto aubCSR = static_cast<CommandStreamReceiverWithAUBDump<DrmCommandStreamReceiver<FamilyType>> *>(ptr.get())->aubCSR.get();
EXPECT_NE(nullptr, aubCSR);
}
HWTEST_F(DeviceCommandStreamLeaksTest, givenDefaultDrmCsrWhenOsInterfaceIsNullptrThenValidateDrm) {
std::unique_ptr<CommandStreamReceiver> ptr(DeviceCommandStreamReceiver<FamilyType>::create(false, *executionEnvironment, 0, 1));
auto drmCsr = (DrmCommandStreamReceiver<FamilyType> *)ptr.get();
EXPECT_NE(nullptr, executionEnvironment->rootDeviceEnvironments[0]->osInterface);
auto expected = drmCsr->getOSInterface()->getDriverModel()->template as<NEO::Drm>();
auto got = executionEnvironment->rootDeviceEnvironments[0]->osInterface->getDriverModel()->as<NEO::Drm>();
EXPECT_EQ(expected, got);
}
HWTEST_F(DeviceCommandStreamLeaksTest, givenDisabledGemCloseWorkerWhenCsrIsCreatedThenGemCloseWorkerInactiveModeIsSelected) {
DebugManagerStateRestore restorer;
DebugManager.flags.EnableGemCloseWorker.set(0u);
std::unique_ptr<CommandStreamReceiver> ptr(DeviceCommandStreamReceiver<FamilyType>::create(false, *executionEnvironment, 0, 1));
auto drmCsr = (DrmCommandStreamReceiver<FamilyType> *)ptr.get();
EXPECT_EQ(drmCsr->peekGemCloseWorkerOperationMode(), gemCloseWorkerMode::gemCloseWorkerInactive);
}
HWTEST_F(DeviceCommandStreamLeaksTest, givenEnabledGemCloseWorkerWhenCsrIsCreatedThenGemCloseWorkerActiveModeIsSelected) {
DebugManagerStateRestore restorer;
DebugManager.flags.EnableGemCloseWorker.set(1u);
std::unique_ptr<CommandStreamReceiver> ptr(DeviceCommandStreamReceiver<FamilyType>::create(false, *executionEnvironment, 0, 1));
auto drmCsr = (DrmCommandStreamReceiver<FamilyType> *)ptr.get();
EXPECT_EQ(drmCsr->peekGemCloseWorkerOperationMode(), gemCloseWorkerMode::gemCloseWorkerActive);
}
HWTEST_F(DeviceCommandStreamLeaksTest, givenDefaultGemCloseWorkerWhenCsrIsCreatedThenGemCloseWorkerActiveModeIsSelected) {
std::unique_ptr<CommandStreamReceiver> ptr(DeviceCommandStreamReceiver<FamilyType>::create(false, *executionEnvironment, 0, 1));
auto drmCsr = (DrmCommandStreamReceiver<FamilyType> *)ptr.get();
EXPECT_EQ(drmCsr->peekGemCloseWorkerOperationMode(), gemCloseWorkerMode::gemCloseWorkerActive);
}
using DeviceCommandStreamSetInternalUsageTests = DeviceCommandStreamLeaksTest;
HWTEST_F(DeviceCommandStreamSetInternalUsageTests, givenValidDrmCsrThenGemCloseWorkerOperationModeIsSetToInactiveWhenInternalUsageIsSet) {
std::unique_ptr<CommandStreamReceiver> ptr(DeviceCommandStreamReceiver<FamilyType>::create(false, *executionEnvironment, 0, 1));
auto drmCsr = (DrmCommandStreamReceiver<FamilyType> *)ptr.get();
EXPECT_EQ(drmCsr->peekGemCloseWorkerOperationMode(), gemCloseWorkerMode::gemCloseWorkerActive);
drmCsr->initializeDefaultsForInternalEngine();
EXPECT_EQ(drmCsr->peekGemCloseWorkerOperationMode(), gemCloseWorkerMode::gemCloseWorkerInactive);
}

View File

@@ -0,0 +1,63 @@
/*
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/helpers/hw_info.h"
#include "shared/source/os_interface/driver_info.h"
#include "shared/test/common/helpers/default_hw_info.h"
#include "gtest/gtest.h"
#include <memory>
#include <string>
namespace NEO {
TEST(DriverInfo, GivenUninitializedHardwareInfoWhenCreateDriverInfoLinuxThenReturnNull) {
std::unique_ptr<DriverInfo> driverInfo(DriverInfo::create(nullptr, nullptr));
EXPECT_EQ(nullptr, driverInfo.get());
}
TEST(DriverInfo, GivenCreateDriverInfoWhenLinuxThenReturnNewInstance) {
auto hwInfo = *defaultHwInfo;
std::unique_ptr<DriverInfo> driverInfo(DriverInfo::create(&hwInfo, nullptr));
EXPECT_NE(nullptr, driverInfo.get());
}
TEST(DriverInfo, GivenDriverInfoWhenLinuxThenReturnDefault) {
auto hwInfo = *defaultHwInfo;
std::unique_ptr<DriverInfo> driverInfo(DriverInfo::create(&hwInfo, nullptr));
std::string defaultName = "testName";
std::string defaultVersion = "testVersion";
auto resultName = driverInfo->getDeviceName(defaultName);
auto resultVersion = driverInfo->getVersion(defaultVersion);
EXPECT_STREQ(defaultName.c_str(), resultName.c_str());
EXPECT_STREQ(defaultVersion.c_str(), resultVersion.c_str());
}
TEST(DriverInfo, givenGetMediaSharingSupportWhenLinuxThenReturnTrue) {
auto hwInfo = *defaultHwInfo;
std::unique_ptr<DriverInfo> driverInfo(DriverInfo::create(&hwInfo, nullptr));
EXPECT_TRUE(driverInfo->getMediaSharingSupport());
}
TEST(DriverInfo, givenGetImageSupportWhenHwInfoSupportsImagesThenReturnTrueOtherwiseFalse) {
auto hwInfo = *defaultHwInfo;
for (bool supportsImages : {false, true}) {
hwInfo.capabilityTable.supportsImages = supportsImages;
std::unique_ptr<DriverInfo> driverInfo(DriverInfo::create(&hwInfo, nullptr));
EXPECT_EQ(supportsImages, driverInfo->getImageSupport());
}
}
} // namespace NEO

View File

@@ -0,0 +1,614 @@
/*
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/os_interface/os_interface.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/libult/linux/drm_mock.h"
#include "shared/test/common/mocks/linux/mock_drm_allocation.h"
#include "shared/test/common/mocks/linux/mock_drm_wrappers.h"
#include "shared/test/common/mocks/mock_device.h"
#include "shared/test/common/mocks/mock_gmm_helper.h"
#include "shared/test/common/os_interface/linux/device_command_stream_fixture.h"
#include "shared/test/common/os_interface/linux/drm_buffer_object_fixture.h"
#include "shared/test/common/test_macros/test.h"
#include "shared/test/unit_test/helpers/gtest_helpers.h"
using namespace NEO;
using DrmMockBufferObjectFixture = DrmBufferObjectFixture<DrmMockCustom>;
using DrmBufferObjectTest = Test<DrmMockBufferObjectFixture>;
TEST_F(DrmBufferObjectTest, WhenCallingExecThenReturnIsCorrect) {
mock->ioctl_expected.total = 1;
mock->ioctl_res = 0;
ExecObject execObjectsStorage = {};
auto ret = bo->exec(0, 0, 0, false, osContext.get(), 0, 1, nullptr, 0u, &execObjectsStorage, 0, 0);
EXPECT_EQ(mock->ioctl_res, ret);
EXPECT_EQ(0u, mock->execBuffer.getFlags());
}
TEST_F(DrmBufferObjectTest, GivenInvalidParamsWhenCallingExecThenEfaultIsReturned) {
mock->ioctl_expected.total = 3;
mock->ioctl_res = -1;
mock->errnoValue = EFAULT;
ExecObject execObjectsStorage = {};
EXPECT_EQ(EFAULT, bo->exec(0, 0, 0, false, osContext.get(), 0, 1, nullptr, 0u, &execObjectsStorage, 0, 0));
}
TEST_F(DrmBufferObjectTest, GivenDetectedGpuHangDuringEvictUnusedAllocationsWhenCallingExecGpuHangErrorCodeIsRetrurned) {
mock->ioctl_expected.total = 2;
mock->ioctl_res = -1;
mock->errnoValue = EFAULT;
bo->callBaseEvictUnusedAllocations = false;
ExecObject execObjectsStorage = {};
const auto result = bo->exec(0, 0, 0, false, osContext.get(), 0, 1, nullptr, 0u, &execObjectsStorage, 0, 0);
EXPECT_EQ(BufferObject::gpuHangDetected, result);
}
TEST_F(DrmBufferObjectTest, WhenSettingTilingThenCallSucceeds) {
mock->ioctl_expected.total = 1; //set_tiling
auto ret = bo->setTiling(I915_TILING_X, 0);
EXPECT_TRUE(ret);
}
TEST_F(DrmBufferObjectTest, WhenSettingSameTilingThenCallSucceeds) {
mock->ioctl_expected.total = 0; //set_tiling
bo->tileBy(I915_TILING_X);
auto ret = bo->setTiling(I915_TILING_X, 0);
EXPECT_TRUE(ret);
}
TEST_F(DrmBufferObjectTest, GivenInvalidTilingWhenSettingTilingThenCallFails) {
mock->ioctl_expected.total = 1; //set_tiling
mock->ioctl_res = -1;
auto ret = bo->setTiling(I915_TILING_X, 0);
EXPECT_FALSE(ret);
}
TEST_F(DrmBufferObjectTest, givenBindAvailableWhenCallWaitThenNoIoctlIsCalled) {
mock->bindAvailable = true;
mock->ioctl_expected.total = 0;
auto ret = bo->wait(-1);
EXPECT_FALSE(ret);
}
TEST_F(DrmBufferObjectTest, givenAddressThatWhenSizeIsAddedCrosses32BitBoundaryWhenExecIsCalledThen48BitFlagIsSet) {
MockExecObject execObject{};
memset(&execObject, 0, sizeof(execObject));
bo->setAddress(((uint64_t)1u << 32) - 0x1000u);
bo->setSize(0x1000);
bo->fillExecObject(execObject, osContext.get(), 0, 1);
//base address + size > size of 32bit address space
EXPECT_TRUE(execObject.has48BAddressSupportFlag());
}
TEST_F(DrmBufferObjectTest, givenAddressThatWhenSizeIsAddedWithin32BitBoundaryWhenExecIsCalledThen48BitFlagSet) {
MockExecObject execObject{};
memset(&execObject, 0, sizeof(execObject));
bo->setAddress(((uint64_t)1u << 32) - 0x1000u);
bo->setSize(0xFFF);
bo->fillExecObject(execObject, osContext.get(), 0, 1);
//base address + size < size of 32bit address space
EXPECT_TRUE(execObject.has48BAddressSupportFlag());
}
TEST_F(DrmBufferObjectTest, whenExecFailsThenPinFails) {
std::unique_ptr<uint32_t[]> buff(new uint32_t[1024]);
mock->ioctl_expected.total = 3;
mock->ioctl_res = -1;
this->mock->errnoValue = EINVAL;
std::unique_ptr<BufferObject> boToPin(new TestedBufferObject(this->mock.get()));
ASSERT_NE(nullptr, boToPin.get());
bo->setAddress(reinterpret_cast<uint64_t>(buff.get()));
BufferObject *boArray[1] = {boToPin.get()};
auto ret = bo->pin(boArray, 1, osContext.get(), 0, 1);
EXPECT_EQ(EINVAL, ret);
}
TEST_F(DrmBufferObjectTest, whenExecFailsThenValidateHostPtrFails) {
std::unique_ptr<uint32_t[]> buff(new uint32_t[1024]);
mock->ioctl_expected.total = 3;
mock->ioctl_res = -1;
this->mock->errnoValue = EINVAL;
std::unique_ptr<BufferObject> boToPin(new TestedBufferObject(this->mock.get()));
ASSERT_NE(nullptr, boToPin.get());
bo->setAddress(reinterpret_cast<uint64_t>(buff.get()));
BufferObject *boArray[1] = {boToPin.get()};
auto ret = bo->validateHostPtr(boArray, 1, osContext.get(), 0, 1);
EXPECT_EQ(EINVAL, ret);
}
TEST_F(DrmBufferObjectTest, givenResidentBOWhenPrintExecutionBufferIsSetToTrueThenDebugInformationAboutBOIsPrinted) {
mock->ioctl_expected.total = 1;
DebugManagerStateRestore restore;
DebugManager.flags.PrintExecutionBuffer.set(true);
std::unique_ptr<uint32_t[]> buff(new uint32_t[1024]);
std::unique_ptr<BufferObject> bo(new TestedBufferObject(this->mock.get()));
ASSERT_NE(nullptr, bo.get());
bo->setAddress(reinterpret_cast<uint64_t>(buff.get()));
BufferObject *boArray[1] = {bo.get()};
testing::internal::CaptureStdout();
auto ret = bo->pin(boArray, 1, osContext.get(), 0, 1);
EXPECT_EQ(0, ret);
std::string output = testing::internal::GetCapturedStdout();
auto idx = output.find("drm_i915_gem_execbuffer2 {");
size_t expectedValue = 29;
EXPECT_EQ(expectedValue, idx);
idx = output.find("Buffer Object = { handle: BO-");
EXPECT_NE(std::string::npos, idx);
idx = output.find("Command Buffer Object = { handle: BO-");
EXPECT_NE(std::string::npos, idx);
}
TEST_F(DrmBufferObjectTest, whenPrintBOCreateDestroyResultFlagIsSetAndCloseIsCalledOnBOThenDebugInfromationIsPrinted) {
mock->ioctl_expected.total = 1;
DebugManagerStateRestore stateRestore;
DebugManager.flags.PrintBOCreateDestroyResult.set(true);
testing::internal::CaptureStdout();
bool result = bo->close();
EXPECT_EQ(true, result);
std::string output = testing::internal::GetCapturedStdout();
size_t idx = output.find("Calling gem close on handle: BO-");
size_t expectedValue = 0;
EXPECT_EQ(expectedValue, idx);
}
TEST_F(DrmBufferObjectTest, whenPrintExecutionBufferIsSetToTrueThenMessageFoundInStdStream) {
mock->ioctl_expected.total = 1;
DebugManagerStateRestore restore;
DebugManager.flags.PrintExecutionBuffer.set(true);
ExecObject execObjectsStorage = {};
testing::internal::CaptureStdout();
auto ret = bo->exec(0, 0, 0, false, osContext.get(), 0, 1, nullptr, 0u, &execObjectsStorage, 0, 0);
EXPECT_EQ(0, ret);
std::string output = testing::internal::GetCapturedStdout();
auto idx = output.find("drm_i915_gem_execbuffer2 {");
size_t expectedValue = 29;
EXPECT_EQ(expectedValue, idx);
}
TEST(DrmBufferObjectSimpleTest, givenInvalidBoWhenValidateHostptrIsCalledThenErrorIsReturned) {
std::unique_ptr<uint32_t[]> buff(new uint32_t[256]);
MockExecutionEnvironment executionEnvironment;
std::unique_ptr<DrmMockCustom> mock(new DrmMockCustom(*executionEnvironment.rootDeviceEnvironments[0]));
executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock.get(), 0u);
OsContextLinux osContext(*mock, 0u, EngineDescriptorHelper::getDefaultDescriptor());
ASSERT_NE(nullptr, mock.get());
std::unique_ptr<TestedBufferObject> bo(new TestedBufferObject(mock.get()));
ASSERT_NE(nullptr, bo.get());
// fail DRM_IOCTL_I915_GEM_EXECBUFFER2 in pin
mock->ioctl_res = -1;
std::unique_ptr<BufferObject> boToPin(new TestedBufferObject(mock.get()));
ASSERT_NE(nullptr, boToPin.get());
bo->setAddress(reinterpret_cast<uint64_t>(buff.get()));
mock->errnoValue = EFAULT;
BufferObject *boArray[1] = {boToPin.get()};
auto ret = bo->pin(boArray, 1, &osContext, 0, 1);
EXPECT_EQ(EFAULT, ret);
mock->ioctl_res = 0;
}
TEST(DrmBufferObjectSimpleTest, givenInvalidBoWhenPinIsCalledThenErrorIsReturned) {
std::unique_ptr<uint32_t[]> buff(new uint32_t[256]);
MockExecutionEnvironment executionEnvironment;
std::unique_ptr<DrmMockCustom> mock(new DrmMockCustom(*executionEnvironment.rootDeviceEnvironments[0]));
executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock.get(), 0u);
OsContextLinux osContext(*mock, 0u, EngineDescriptorHelper::getDefaultDescriptor());
ASSERT_NE(nullptr, mock.get());
std::unique_ptr<TestedBufferObject> bo(new TestedBufferObject(mock.get()));
ASSERT_NE(nullptr, bo.get());
// fail DRM_IOCTL_I915_GEM_EXECBUFFER2 in pin
mock->ioctl_res = -1;
std::unique_ptr<BufferObject> boToPin(new TestedBufferObject(mock.get()));
ASSERT_NE(nullptr, boToPin.get());
bo->setAddress(reinterpret_cast<uint64_t>(buff.get()));
mock->errnoValue = EFAULT;
BufferObject *boArray[1] = {boToPin.get()};
auto ret = bo->validateHostPtr(boArray, 1, &osContext, 0, 1);
EXPECT_EQ(EFAULT, ret);
mock->ioctl_res = 0;
}
TEST(DrmBufferObjectSimpleTest, givenBufferObjectWhenConstructedWithASizeThenTheSizeIsInitialized) {
MockExecutionEnvironment executionEnvironment;
std::unique_ptr<DrmMockCustom> drmMock(new DrmMockCustom(*executionEnvironment.rootDeviceEnvironments[0]));
std::unique_ptr<BufferObject> bo(new BufferObject(drmMock.get(), 3, 1, 0x1000, 1));
EXPECT_EQ(0x1000u, bo->peekSize());
}
TEST(DrmBufferObjectSimpleTest, givenArrayOfBosWhenPinnedThenAllBosArePinned) {
std::unique_ptr<uint32_t[]> buff(new uint32_t[256]);
MockExecutionEnvironment executionEnvironment;
std::unique_ptr<DrmMockCustom> mock(new DrmMockCustom(*executionEnvironment.rootDeviceEnvironments[0]));
ASSERT_NE(nullptr, mock.get());
OsContextLinux osContext(*mock, 0u, EngineDescriptorHelper::getDefaultDescriptor());
std::unique_ptr<TestedBufferObject> bo(new TestedBufferObject(mock.get()));
ASSERT_NE(nullptr, bo.get());
mock->ioctl_res = 0;
std::unique_ptr<TestedBufferObject> boToPin(new TestedBufferObject(mock.get()));
std::unique_ptr<TestedBufferObject> boToPin2(new TestedBufferObject(mock.get()));
std::unique_ptr<TestedBufferObject> boToPin3(new TestedBufferObject(mock.get()));
ASSERT_NE(nullptr, boToPin.get());
ASSERT_NE(nullptr, boToPin2.get());
ASSERT_NE(nullptr, boToPin3.get());
BufferObject *array[3] = {boToPin.get(), boToPin2.get(), boToPin3.get()};
bo->setAddress(reinterpret_cast<uint64_t>(buff.get()));
auto ret = bo->pin(array, 3, &osContext, 0, 1);
EXPECT_EQ(mock->ioctl_res, ret);
EXPECT_LT(0u, mock->execBuffer.getBatchLen());
EXPECT_EQ(4u, mock->execBuffer.getBufferCount()); // 3 bos to pin plus 1 exec bo
EXPECT_EQ(reinterpret_cast<uintptr_t>(boToPin->execObjectPointerFilled), mock->execBuffer.getBuffersPtr());
EXPECT_NE(nullptr, boToPin2->execObjectPointerFilled);
EXPECT_NE(nullptr, boToPin3->execObjectPointerFilled);
bo->setAddress(0llu);
}
TEST(DrmBufferObjectSimpleTest, givenArrayOfBosWhenValidatedThenAllBosArePinned) {
std::unique_ptr<uint32_t[]> buff(new uint32_t[256]);
MockExecutionEnvironment executionEnvironment;
std::unique_ptr<DrmMockCustom> mock(new DrmMockCustom(*executionEnvironment.rootDeviceEnvironments[0]));
ASSERT_NE(nullptr, mock.get());
OsContextLinux osContext(*mock, 0u, EngineDescriptorHelper::getDefaultDescriptor());
std::unique_ptr<TestedBufferObject> bo(new TestedBufferObject(mock.get()));
ASSERT_NE(nullptr, bo.get());
mock->ioctl_res = 0;
std::unique_ptr<TestedBufferObject> boToPin(new TestedBufferObject(mock.get()));
std::unique_ptr<TestedBufferObject> boToPin2(new TestedBufferObject(mock.get()));
std::unique_ptr<TestedBufferObject> boToPin3(new TestedBufferObject(mock.get()));
ASSERT_NE(nullptr, boToPin.get());
ASSERT_NE(nullptr, boToPin2.get());
ASSERT_NE(nullptr, boToPin3.get());
BufferObject *array[3] = {boToPin.get(), boToPin2.get(), boToPin3.get()};
bo->setAddress(reinterpret_cast<uint64_t>(buff.get()));
auto ret = bo->validateHostPtr(array, 3, &osContext, 0, 1);
EXPECT_EQ(mock->ioctl_res, ret);
EXPECT_LT(0u, mock->execBuffer.getBatchLen());
EXPECT_EQ(4u, mock->execBuffer.getBufferCount()); // 3 bos to pin plus 1 exec bo
EXPECT_EQ(reinterpret_cast<uintptr_t>(boToPin->execObjectPointerFilled), mock->execBuffer.getBuffersPtr());
EXPECT_NE(nullptr, boToPin2->execObjectPointerFilled);
EXPECT_NE(nullptr, boToPin3->execObjectPointerFilled);
bo->setAddress(0llu);
}
TEST_F(DrmBufferObjectTest, givenDeleterWhenBufferObjectIsCreatedAndDeletedThenCloseIsCalled) {
mock->ioctl_cnt.reset();
mock->ioctl_expected.reset();
{
std::unique_ptr<BufferObject, BufferObject::Deleter> bo(new BufferObject(mock.get(), 3, 1, 0x1000, 1));
}
EXPECT_EQ(1, mock->ioctl_cnt.gemClose);
mock->ioctl_cnt.reset();
mock->ioctl_expected.reset();
}
TEST(DrmBufferObject, givenPerContextVmRequiredWhenBoCreatedThenBindInfoIsInitializedToOsContextCount) {
auto device = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
device->getRootDeviceEnvironment().executionEnvironment.setDebuggingEnabled();
device->getExecutionEnvironment()->calculateMaxOsContextCount();
DrmMock drm(*(device->getExecutionEnvironment()->rootDeviceEnvironments[0].get()));
EXPECT_TRUE(drm.isPerContextVMRequired());
auto osContextCount = device->getExecutionEnvironment()->memoryManager->getRegisteredEnginesCount();
MockBufferObject bo(&drm, 3, 0, 0, osContextCount);
EXPECT_EQ(osContextCount, bo.bindInfo.size());
for (auto &iter : bo.bindInfo) {
for (uint32_t i = 0; i < EngineLimits::maxHandleCount; i++) {
EXPECT_FALSE(iter[i]);
}
}
}
TEST(DrmBufferObject, givenDrmIoctlReturnsErrorNotSupportedThenBufferObjectReturnsError) {
auto executionEnvironment = new ExecutionEnvironment;
executionEnvironment->setDebuggingEnabled();
executionEnvironment->prepareRootDeviceEnvironments(1);
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
executionEnvironment->calculateMaxOsContextCount();
executionEnvironment->rootDeviceEnvironments[0]->osInterface = std::make_unique<OSInterface>();
DrmMockReturnErrorNotSupported *drm = new DrmMockReturnErrorNotSupported(*executionEnvironment->rootDeviceEnvironments[0]);
executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr<DriverModel>(drm));
executionEnvironment->rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*drm, 0u);
std::unique_ptr<Device> device(MockDevice::createWithExecutionEnvironment<MockDevice>(defaultHwInfo.get(), executionEnvironment, 0));
auto osContextCount = device->getExecutionEnvironment()->memoryManager->getRegisteredEnginesCount();
MockBufferObject bo(drm, 3, 0, 0, osContextCount);
std::unique_ptr<OsContextLinux> osContext;
osContext.reset(new OsContextLinux(*drm, 0u, EngineDescriptorHelper::getDefaultDescriptor()));
ExecObject execObjectsStorage = {};
auto ret = bo.exec(0, 0, 0, false, osContext.get(), 0, 1, nullptr, 0u, &execObjectsStorage, 0, 0);
EXPECT_NE(0, ret);
}
TEST(DrmBufferObject, givenPerContextVmRequiredWhenBoBoundAndUnboundThenCorrectBindInfoIsUpdated) {
auto executionEnvironment = new ExecutionEnvironment;
executionEnvironment->setDebuggingEnabled();
executionEnvironment->prepareRootDeviceEnvironments(1);
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
executionEnvironment->calculateMaxOsContextCount();
executionEnvironment->rootDeviceEnvironments[0]->osInterface = std::make_unique<OSInterface>();
DrmMockNonFailing *drm = new DrmMockNonFailing(*executionEnvironment->rootDeviceEnvironments[0]);
EXPECT_TRUE(drm->isPerContextVMRequired());
executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr<DriverModel>(drm));
executionEnvironment->rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*drm, 0u);
std::unique_ptr<Device> device(MockDevice::createWithExecutionEnvironment<MockDevice>(defaultHwInfo.get(), executionEnvironment, 0));
auto osContextCount = device->getExecutionEnvironment()->memoryManager->getRegisteredEnginesCount();
MockBufferObject bo(drm, 3, 0, 0, osContextCount);
EXPECT_EQ(osContextCount, bo.bindInfo.size());
auto contextId = device->getExecutionEnvironment()->memoryManager->getRegisteredEnginesCount() / 2;
auto osContext = device->getExecutionEnvironment()->memoryManager->getRegisteredEngines()[contextId].osContext;
osContext->ensureContextInitialized();
bo.bind(osContext, 0);
EXPECT_TRUE(bo.bindInfo[contextId][0]);
bo.unbind(osContext, 0);
EXPECT_FALSE(bo.bindInfo[contextId][0]);
}
TEST(DrmBufferObject, givenPrintBOBindingResultWhenBOBindAndUnbindSucceedsThenPrintDebugInformationAboutBOBindingResult) {
struct DrmMockToSucceedBindBufferObject : public DrmMock {
DrmMockToSucceedBindBufferObject(RootDeviceEnvironment &rootDeviceEnvironment)
: DrmMock(rootDeviceEnvironment) {}
int bindBufferObject(OsContext *osContext, uint32_t vmHandleId, BufferObject *bo) override { return 0; }
int unbindBufferObject(OsContext *osContext, uint32_t vmHandleId, BufferObject *bo) override { return 0; }
};
DebugManagerStateRestore restore;
DebugManager.flags.PrintBOBindingResult.set(true);
auto executionEnvironment = new ExecutionEnvironment;
executionEnvironment->setDebuggingEnabled();
executionEnvironment->prepareRootDeviceEnvironments(1);
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
executionEnvironment->calculateMaxOsContextCount();
executionEnvironment->rootDeviceEnvironments[0]->osInterface = std::make_unique<OSInterface>();
auto drm = new DrmMockToSucceedBindBufferObject(*executionEnvironment->rootDeviceEnvironments[0]);
executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr<DriverModel>(drm));
executionEnvironment->rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*drm, 0u);
std::unique_ptr<Device> device(MockDevice::createWithExecutionEnvironment<MockDevice>(defaultHwInfo.get(), executionEnvironment, 0));
auto osContextCount = device->getExecutionEnvironment()->memoryManager->getRegisteredEnginesCount();
MockBufferObject bo(drm, 3, 0, 0, osContextCount);
EXPECT_EQ(osContextCount, bo.bindInfo.size());
auto contextId = device->getExecutionEnvironment()->memoryManager->getRegisteredEnginesCount() / 2;
auto osContext = device->getExecutionEnvironment()->memoryManager->getRegisteredEngines()[contextId].osContext;
osContext->ensureContextInitialized();
testing::internal::CaptureStdout();
bo.bind(osContext, 0);
EXPECT_TRUE(bo.bindInfo[contextId][0]);
std::string bindOutput = testing::internal::GetCapturedStdout();
EXPECT_STREQ(bindOutput.c_str(), "bind BO-0 to VM 0, drmVmId = 1, range: 0 - 0, size: 0, result: 0\n");
testing::internal::CaptureStdout();
bo.unbind(osContext, 0);
EXPECT_FALSE(bo.bindInfo[contextId][0]);
std::string unbindOutput = testing::internal::GetCapturedStdout();
EXPECT_STREQ(unbindOutput.c_str(), "unbind BO-0 from VM 0, drmVmId = 1, range: 0 - 0, size: 0, result: 0\n");
}
TEST(DrmBufferObject, givenPrintBOBindingResultWhenBOBindAndUnbindFailsThenPrintDebugInformationAboutBOBindingResultWithErrno) {
struct DrmMockToFailBindBufferObject : public DrmMock {
DrmMockToFailBindBufferObject(RootDeviceEnvironment &rootDeviceEnvironment)
: DrmMock(rootDeviceEnvironment) {}
int bindBufferObject(OsContext *osContext, uint32_t vmHandleId, BufferObject *bo) override { return -1; }
int unbindBufferObject(OsContext *osContext, uint32_t vmHandleId, BufferObject *bo) override { return -1; }
int getErrno() override { return EINVAL; }
};
DebugManagerStateRestore restore;
DebugManager.flags.PrintBOBindingResult.set(true);
auto executionEnvironment = new ExecutionEnvironment;
executionEnvironment->setDebuggingEnabled();
executionEnvironment->prepareRootDeviceEnvironments(1);
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
executionEnvironment->calculateMaxOsContextCount();
executionEnvironment->rootDeviceEnvironments[0]->osInterface = std::make_unique<OSInterface>();
auto drm = new DrmMockToFailBindBufferObject(*executionEnvironment->rootDeviceEnvironments[0]);
executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr<DriverModel>(drm));
executionEnvironment->rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*drm, 0u);
std::unique_ptr<Device> device(MockDevice::createWithExecutionEnvironment<MockDevice>(defaultHwInfo.get(), executionEnvironment, 0));
auto osContextCount = device->getExecutionEnvironment()->memoryManager->getRegisteredEnginesCount();
MockBufferObject bo(drm, 3, 0, 0, osContextCount);
EXPECT_EQ(osContextCount, bo.bindInfo.size());
auto contextId = device->getExecutionEnvironment()->memoryManager->getRegisteredEnginesCount() / 2;
auto osContext = device->getExecutionEnvironment()->memoryManager->getRegisteredEngines()[contextId].osContext;
osContext->ensureContextInitialized();
testing::internal::CaptureStderr();
bo.bind(osContext, 0);
EXPECT_FALSE(bo.bindInfo[contextId][0]);
std::string bindOutput = testing::internal::GetCapturedStderr();
EXPECT_TRUE(hasSubstr(bindOutput, "bind BO-0 to VM 0, drmVmId = 1, range: 0 - 0, size: 0, result: -1, errno: 22"));
testing::internal::CaptureStderr();
bo.bindInfo[contextId][0] = true;
bo.unbind(osContext, 0);
EXPECT_TRUE(bo.bindInfo[contextId][0]);
std::string unbindOutput = testing::internal::GetCapturedStderr();
EXPECT_TRUE(hasSubstr(unbindOutput, "unbind BO-0 from VM 0, drmVmId = 1, range: 0 - 0, size: 0, result: -1, errno: 22"));
}
TEST(DrmBufferObject, whenBindExtHandleAddedThenItIsStored) {
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
executionEnvironment->prepareRootDeviceEnvironments(1);
DrmMockResources drm(*executionEnvironment->rootDeviceEnvironments[0]);
MockBufferObject bo(&drm, 3, 0, 0, 1);
bo.addBindExtHandle(4);
EXPECT_EQ(1u, bo.bindExtHandles.size());
EXPECT_EQ(4u, bo.bindExtHandles[0]);
EXPECT_EQ(1u, bo.getBindExtHandles().size());
EXPECT_EQ(4u, bo.getBindExtHandles()[0]);
}
TEST(DrmBufferObject, whenMarkForCapturedCalledThenIsMarkedForCaptureReturnsTrue) {
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
executionEnvironment->prepareRootDeviceEnvironments(1);
DrmMockResources drm(*executionEnvironment->rootDeviceEnvironments[0]);
MockBufferObject bo(&drm, 3, 0, 0, 1);
EXPECT_FALSE(bo.isMarkedForCapture());
bo.markForCapture();
EXPECT_TRUE(bo.isMarkedForCapture());
}
TEST_F(DrmBufferObjectTest, givenBoMarkedForCaptureWhenFillingExecObjectThenCaptureFlagIsSet) {
MockExecObject execObject{};
memset(&execObject, 0, sizeof(execObject));
bo->markForCapture();
bo->setAddress(0x45000);
bo->setSize(0x1000);
bo->fillExecObject(execObject, osContext.get(), 0, 1);
EXPECT_TRUE(execObject.hasCaptureFlag());
}
TEST_F(DrmBufferObjectTest, givenAsyncDebugFlagWhenFillingExecObjectThenFlagIsSet) {
MockExecObject execObject{};
DebugManagerStateRestore restorer;
DebugManager.flags.UseAsyncDrmExec.set(1);
memset(&execObject, 0, sizeof(execObject));
bo->setAddress(0x45000);
bo->setSize(0x1000);
bo->fillExecObject(execObject, osContext.get(), 0, 1);
EXPECT_TRUE(execObject.hasAsyncFlag());
}
TEST_F(DrmBufferObjectTest, given47bitAddressWhenSetThenIsAddressNotCanonized) {
VariableBackup<uint32_t> backup(&MockGmmHelper::addressWidth, 48);
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
DrmMock drm(*(executionEnvironment.rootDeviceEnvironments[0].get()));
uint64_t address = maxNBitValue(47) - maxNBitValue(5);
MockBufferObject bo(&drm, 3, 0, 0, 1);
bo.setAddress(address);
auto boAddress = bo.peekAddress();
EXPECT_EQ(boAddress, address);
}
TEST_F(DrmBufferObjectTest, given48bitAddressWhenSetThenAddressIsCanonized) {
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
DrmMock drm(*(executionEnvironment.rootDeviceEnvironments[0].get()));
VariableBackup<uint32_t> backup(&MockGmmHelper::addressWidth, 48);
uint64_t address = maxNBitValue(48) - maxNBitValue(5);
uint64_t expectedAddress = std::numeric_limits<uint64_t>::max() - maxNBitValue(5);
MockBufferObject bo(&drm, 3, 0, 0, 1);
bo.setAddress(address);
auto boAddress = bo.peekAddress();
EXPECT_EQ(boAddress, expectedAddress);
}
TEST_F(DrmBufferObjectTest, givenBoIsCreatedWhenPageFaultIsSupportedThenExplicitResidencyIsRequiredByDefault) {
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
DrmMock drm(*(executionEnvironment.rootDeviceEnvironments[0].get()));
for (auto isPageFaultSupported : {false, true}) {
drm.pageFaultSupported = isPageFaultSupported;
MockBufferObject bo(&drm, 3, 0, 0, 1);
EXPECT_EQ(isPageFaultSupported, bo.isExplicitResidencyRequired());
}
}
TEST_F(DrmBufferObjectTest, whenBoRequiresExplicitResidencyThenTheCorrespondingQueryReturnsCorrectValue) {
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
DrmMock drm(*(executionEnvironment.rootDeviceEnvironments[0].get()));
MockBufferObject bo(&drm, 3, 0, 0, 1);
for (auto required : {false, true}) {
bo.requireExplicitResidency(required);
EXPECT_EQ(required, bo.isExplicitResidencyRequired());
}
}

View File

@@ -0,0 +1,202 @@
/*
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/command_container/command_encoder.h"
#include "shared/source/execution_environment/root_device_environment.h"
#include "shared/source/os_interface/linux/drm_command_stream.h"
#include "shared/source/os_interface/linux/drm_memory_manager.h"
#include "shared/source/os_interface/linux/drm_memory_operations_handler.h"
#include "shared/source/os_interface/os_interface.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/libult/linux/drm_mock.h"
#include "shared/test/common/mocks/linux/mock_drm_allocation.h"
#include "shared/test/common/mocks/linux/mock_drm_memory_manager.h"
#include "shared/test/common/mocks/mock_allocation_properties.h"
#include "shared/test/common/mocks/mock_execution_environment.h"
#include "shared/test/common/os_interface/linux/device_command_stream_fixture.h"
#include "shared/test/common/os_interface/linux/drm_buffer_object_fixture.h"
#include "shared/test/common/os_interface/linux/drm_command_stream_fixture.h"
#include "shared/test/common/test_macros/test.h"
using namespace NEO;
using DrmCommandStreamMMTest = ::testing::Test;
struct DrmCommandStreamMemExecTest : public DrmCommandStreamEnhancedTemplate<DrmMockCustom> {
void SetUp() override {
DrmCommandStreamEnhancedTemplate::SetUp();
}
void TearDown() override {
DrmCommandStreamEnhancedTemplate::TearDown();
}
};
HWTEST_F(DrmCommandStreamMMTest, GivenForcePinThenMemoryManagerCreatesPinBb) {
DebugManagerStateRestore dbgRestorer;
DebugManager.flags.EnableForcePin.set(true);
MockExecutionEnvironment executionEnvironment;
auto drm = new DrmMockCustom(*executionEnvironment.rootDeviceEnvironments[0]);
executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique<OSInterface>();
executionEnvironment.rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr<DriverModel>(drm));
executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*drm, 0u);
executionEnvironment.rootDeviceEnvironments[0]->initGmm();
DrmCommandStreamReceiver<FamilyType> csr(executionEnvironment, 0, 1, gemCloseWorkerMode::gemCloseWorkerInactive);
auto memoryManager = new TestedDrmMemoryManager(false, true, false, executionEnvironment);
executionEnvironment.memoryManager.reset(memoryManager);
ASSERT_NE(nullptr, memoryManager);
EXPECT_NE(nullptr, memoryManager->pinBBs[0]);
}
HWTEST_F(DrmCommandStreamMMTest, givenForcePinDisabledWhenMemoryManagerIsCreatedThenPinBBIsCreated) {
DebugManagerStateRestore dbgRestorer;
DebugManager.flags.EnableForcePin.set(false);
MockExecutionEnvironment executionEnvironment;
auto drm = new DrmMockCustom(*executionEnvironment.rootDeviceEnvironments[0]);
executionEnvironment.rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique<OSInterface>();
executionEnvironment.rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr<DriverModel>(drm));
executionEnvironment.rootDeviceEnvironments[0]->initGmm();
DrmCommandStreamReceiver<FamilyType> csr(executionEnvironment, 0, 1, gemCloseWorkerMode::gemCloseWorkerInactive);
auto memoryManager = new TestedDrmMemoryManager(false, true, false, executionEnvironment);
executionEnvironment.memoryManager.reset(memoryManager);
ASSERT_NE(nullptr, memoryManager);
EXPECT_NE(nullptr, memoryManager->pinBBs[0]);
}
HWTEST_F(DrmCommandStreamMMTest, givenExecutionEnvironmentWithMoreThanOneRootDeviceEnvWhenCreatingDrmMemoryManagerThenCreateAsManyPinBBs) {
MockExecutionEnvironment executionEnvironment;
executionEnvironment.prepareRootDeviceEnvironments(2);
for (uint32_t rootDeviceIndex = 0; rootDeviceIndex < executionEnvironment.rootDeviceEnvironments.size(); rootDeviceIndex++) {
executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->setHwInfo(defaultHwInfo.get());
executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->osInterface = std::make_unique<OSInterface>();
auto drm = new DrmMockCustom(*executionEnvironment.rootDeviceEnvironments[0]);
executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->osInterface->setDriverModel(std::unique_ptr<DriverModel>(drm));
executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*drm, 0u);
executionEnvironment.rootDeviceEnvironments[0]->initGmm();
}
auto memoryManager = new TestedDrmMemoryManager(false, true, false, executionEnvironment);
executionEnvironment.memoryManager.reset(memoryManager);
ASSERT_NE(nullptr, memoryManager);
for (uint32_t rootDeviceIndex = 0; rootDeviceIndex < executionEnvironment.rootDeviceEnvironments.size(); rootDeviceIndex++) {
EXPECT_NE(nullptr, memoryManager->pinBBs[rootDeviceIndex]);
}
}
HWTEST_TEMPLATED_F(DrmCommandStreamMemExecTest, GivenDrmSupportsVmBindAndCompletionFenceWhenCallingCsrExecThenTagAllocationIsPassed) {
mock->completionFenceSupported = true;
mock->isVmBindAvailableCall.callParent = false;
mock->isVmBindAvailableCall.returnValue = true;
TestedBufferObject bo(mock, 128);
MockDrmAllocation cmdBuffer(AllocationType::COMMAND_BUFFER, MemoryPool::System4KBPages);
cmdBuffer.bufferObjects[0] = &bo;
uint8_t buff[128];
LinearStream cs(&cmdBuffer, buff, 128);
CommandStreamReceiverHw<FamilyType>::addBatchBufferEnd(cs, nullptr);
EncodeNoop<FamilyType>::alignToCacheLine(cs);
BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, QueueSliceCount::defaultSliceCount, cs.getUsed(), &cs, nullptr, false};
auto allocation = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize});
csr->makeResident(cmdBuffer);
csr->makeResident(*allocation);
csr->makeResident(*csr->getTagAllocation());
uint64_t expectedCompletionGpuAddress = csr->getTagAllocation()->getGpuAddress() + Drm::completionFenceOffset;
auto *testCsr = static_cast<TestedDrmCommandStreamReceiver<FamilyType> *>(csr);
testCsr->latestSentTaskCount = 2;
int ret = testCsr->exec(batchBuffer, 1, 2, 0);
EXPECT_EQ(0, ret);
EXPECT_EQ(expectedCompletionGpuAddress, bo.receivedCompletionGpuAddress);
EXPECT_EQ(testCsr->latestSentTaskCount, bo.receivedCompletionValue);
mm->freeGraphicsMemory(allocation);
}
HWTEST_TEMPLATED_F(DrmCommandStreamMemExecTest, GivenDrmSupportsVmBindAndNotCompletionFenceWhenCallingCsrExecThenTagAllocationIsNotPassed) {
mock->completionFenceSupported = false;
mock->isVmBindAvailableCall.callParent = false;
mock->isVmBindAvailableCall.returnValue = true;
TestedBufferObject bo(mock, 128);
MockDrmAllocation cmdBuffer(AllocationType::COMMAND_BUFFER, MemoryPool::System4KBPages);
cmdBuffer.bufferObjects[0] = &bo;
uint8_t buff[128];
LinearStream cs(&cmdBuffer, buff, 128);
CommandStreamReceiverHw<FamilyType>::addBatchBufferEnd(cs, nullptr);
EncodeNoop<FamilyType>::alignToCacheLine(cs);
BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, QueueSliceCount::defaultSliceCount, cs.getUsed(), &cs, nullptr, false};
auto allocation = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize});
csr->makeResident(cmdBuffer);
csr->makeResident(*allocation);
csr->makeResident(*csr->getTagAllocation());
constexpr uint64_t expectedCompletionGpuAddress = 0;
constexpr uint32_t expectedCompletionValue = 0;
auto *testCsr = static_cast<TestedDrmCommandStreamReceiver<FamilyType> *>(csr);
testCsr->latestSentTaskCount = 2;
int ret = testCsr->exec(batchBuffer, 1, 2, 0);
EXPECT_EQ(0, ret);
EXPECT_EQ(expectedCompletionGpuAddress, bo.receivedCompletionGpuAddress);
EXPECT_EQ(expectedCompletionValue, bo.receivedCompletionValue);
mm->freeGraphicsMemory(allocation);
}
HWTEST_TEMPLATED_F(DrmCommandStreamMemExecTest, GivenDrmSupportsCompletionFenceAndNotVmBindWhenCallingCsrExecThenTagAllocationIsNotPassed) {
mock->completionFenceSupported = true;
mock->isVmBindAvailableCall.callParent = false;
mock->isVmBindAvailableCall.returnValue = false;
TestedBufferObject bo(mock, 128);
MockDrmAllocation cmdBuffer(AllocationType::COMMAND_BUFFER, MemoryPool::System4KBPages);
cmdBuffer.bufferObjects[0] = &bo;
uint8_t buff[128];
LinearStream cs(&cmdBuffer, buff, 128);
CommandStreamReceiverHw<FamilyType>::addBatchBufferEnd(cs, nullptr);
EncodeNoop<FamilyType>::alignToCacheLine(cs);
BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, QueueSliceCount::defaultSliceCount, cs.getUsed(), &cs, nullptr, false};
auto allocation = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize});
csr->makeResident(cmdBuffer);
csr->makeResident(*allocation);
csr->makeResident(*csr->getTagAllocation());
constexpr uint64_t expectedCompletionGpuAddress = 0;
constexpr uint32_t expectedCompletionValue = 0;
auto *testCsr = static_cast<TestedDrmCommandStreamReceiver<FamilyType> *>(csr);
testCsr->latestSentTaskCount = 2;
int ret = testCsr->exec(batchBuffer, 1, 2, 0);
EXPECT_EQ(0, ret);
EXPECT_EQ(expectedCompletionGpuAddress, bo.receivedCompletionGpuAddress);
EXPECT_EQ(expectedCompletionValue, bo.receivedCompletionValue);
mm->freeGraphicsMemory(allocation);
}

View File

@@ -0,0 +1,180 @@
/*
* Copyright (C) 2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/command_container/command_encoder.h"
#include "shared/source/execution_environment/root_device_environment.h"
#include "shared/source/os_interface/linux/drm_command_stream.h"
#include "shared/source/os_interface/linux/drm_memory_manager.h"
#include "shared/source/os_interface/linux/drm_memory_operations_handler.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/engine_descriptor_helper.h"
#include "shared/test/common/helpers/variable_backup.h"
#include "shared/test/common/libult/linux/drm_mock.h"
#include "shared/test/common/mocks/linux/mock_drm_allocation.h"
#include "shared/test/common/mocks/linux/mock_drm_memory_manager.h"
#include "shared/test/common/mocks/mock_allocation_properties.h"
#include "shared/test/common/mocks/mock_execution_environment.h"
#include "shared/test/common/os_interface/linux/device_command_stream_fixture.h"
#include "shared/test/common/os_interface/linux/drm_buffer_object_fixture.h"
#include "shared/test/common/os_interface/linux/drm_command_stream_fixture.h"
#include "shared/test/common/test_macros/test.h"
using namespace NEO;
struct DrmCommandStreamMultiTileMemExecFixture {
void SetUp() { // NOLINT(readability-identifier-naming)
DebugManager.flags.CreateMultipleSubDevices.set(2u);
DebugManager.flags.EnableImplicitScaling.set(1);
DebugManager.flags.EnableForcePin.set(false);
osLocalMemoryBackup = std::make_unique<VariableBackup<bool>>(&OSInterface::osEnableLocalMemory, true);
executionEnvironment = new MockExecutionEnvironment();
executionEnvironment->incRefInternal();
executionEnvironment->initGmm();
mock = new DrmMockCustom(*executionEnvironment->rootDeviceEnvironments[0]);
executionEnvironment->rootDeviceEnvironments[0]->osInterface = std::make_unique<OSInterface>();
executionEnvironment->rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr<DriverModel>(mock));
executionEnvironment->rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock, 0);
memoryManager = new DrmMemoryManager(gemCloseWorkerMode::gemCloseWorkerInactive,
DebugManager.flags.EnableForcePin.get(),
true,
*executionEnvironment);
executionEnvironment->memoryManager.reset(memoryManager);
executionEnvironment->prepareRootDeviceEnvironments(1u);
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(NEO::defaultHwInfo.get());
executionEnvironment->initializeMemoryManager();
VariableBackup<UltHwConfig> backup(&ultHwConfig);
ultHwConfig.useHwCsr = true;
device.reset(MockDevice::create<MockDevice>(executionEnvironment, 0));
}
void TearDown() { // NOLINT(readability-identifier-naming)
executionEnvironment->decRefInternal();
}
DebugManagerStateRestore dbgRestore;
std::unique_ptr<VariableBackup<bool>> osLocalMemoryBackup;
std::unique_ptr<MockDevice> device;
MockExecutionEnvironment *executionEnvironment = nullptr;
DrmMockCustom *mock = nullptr;
DrmMemoryManager *memoryManager = nullptr;
};
using DrmCommandStreamMultiTileMemExecTest = Test<DrmCommandStreamMultiTileMemExecFixture>;
HWCMDTEST_F(IGFX_XE_HP_CORE, DrmCommandStreamMultiTileMemExecTest, GivenDrmSupportsCompletionFenceAndVmBindWhenCallingCsrExecThenMultipleTagAllocationIsPassed) {
auto *testCsr = new TestedDrmCommandStreamReceiver<FamilyType>(*executionEnvironment, 0, device->getDeviceBitfield());
device->resetCommandStreamReceiver(testCsr);
EXPECT_EQ(2u, testCsr->activePartitions);
mock->completionFenceSupported = true;
mock->isVmBindAvailableCall.callParent = false;
mock->isVmBindAvailableCall.returnValue = true;
TestedBufferObject bo(mock, 128);
MockDrmAllocation cmdBuffer(AllocationType::COMMAND_BUFFER, MemoryPool::System4KBPages);
cmdBuffer.bufferObjects[0] = &bo;
uint8_t buff[128];
LinearStream cs(&cmdBuffer, buff, 128);
CommandStreamReceiverHw<FamilyType>::addBatchBufferEnd(cs, nullptr);
EncodeNoop<FamilyType>::alignToCacheLine(cs);
BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, QueueSliceCount::defaultSliceCount, cs.getUsed(), &cs, nullptr, false};
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{testCsr->getRootDeviceIndex(), MemoryConstants::pageSize});
testCsr->makeResident(cmdBuffer);
testCsr->makeResident(*allocation);
testCsr->makeResident(*testCsr->getTagAllocation());
testCsr->latestSentTaskCount = 2;
testCsr->postSyncWriteOffset = 16;
uint64_t expectedCompletionGpuAddress = testCsr->getTagAllocation()->getGpuAddress() + Drm::completionFenceOffset + testCsr->postSyncWriteOffset;
int ret = testCsr->flushInternal(batchBuffer, testCsr->getResidencyAllocations());
EXPECT_EQ(0, ret);
EXPECT_EQ(expectedCompletionGpuAddress, bo.receivedCompletionGpuAddress);
EXPECT_EQ(testCsr->latestSentTaskCount, bo.receivedCompletionValue);
EXPECT_EQ(2u, bo.execCalled);
memoryManager->freeGraphicsMemory(allocation);
}
HWCMDTEST_F(IGFX_XE_HP_CORE, DrmCommandStreamMultiTileMemExecTest, GivenDrmSupportsCompletionFenceAndVmBindWhenHandlingCompletionThenExpectMultipleWaitCalls) {
EngineControl &defaultEngine = device->getDefaultEngine();
EXPECT_EQ(2u, defaultEngine.commandStreamReceiver->getActivePartitions());
uint32_t postSyncOffset = defaultEngine.commandStreamReceiver->getPostSyncWriteOffset();
EXPECT_NE(0u, postSyncOffset);
mock->completionFenceSupported = true;
mock->isVmBindAvailableCall.callParent = false;
mock->isVmBindAvailableCall.returnValue = true;
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{0, 1024, AllocationType::COMMAND_BUFFER});
allocation->updateTaskCount(2, defaultEngine.osContext->getContextId());
volatile uint32_t *completionAddress = defaultEngine.commandStreamReceiver->getTagAddress();
completionAddress += (Drm::completionFenceOffset / sizeof(uint32_t));
*completionAddress = 1;
completionAddress += (postSyncOffset / sizeof(uint32_t));
*completionAddress = 1;
memoryManager->handleFenceCompletion(allocation);
uint64_t expectedAddress = castToUint64(const_cast<uint32_t *>(defaultEngine.commandStreamReceiver->getTagAddress())) +
Drm::completionFenceOffset +
postSyncOffset;
constexpr uint64_t expectedValue = 2;
EXPECT_EQ(2u, mock->waitUserFenceCall.called);
EXPECT_EQ(expectedAddress, mock->waitUserFenceCall.address);
EXPECT_EQ(expectedValue, mock->waitUserFenceCall.value);
memoryManager->freeGraphicsMemory(allocation);
}
HWCMDTEST_F(IGFX_XE_HP_CORE, DrmCommandStreamMultiTileMemExecTest, GivenDrmSupportsCompletionFenceAndVmBindWhenHandlingCompletionAndOneContextIsReadyThenExpectOneWaitCall) {
EngineControl &defaultEngine = device->getDefaultEngine();
EXPECT_EQ(2u, defaultEngine.commandStreamReceiver->getActivePartitions());
uint32_t postSyncOffset = defaultEngine.commandStreamReceiver->getPostSyncWriteOffset();
EXPECT_NE(0u, postSyncOffset);
mock->completionFenceSupported = true;
mock->isVmBindAvailableCall.callParent = false;
mock->isVmBindAvailableCall.returnValue = true;
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{0, 1024, AllocationType::COMMAND_BUFFER});
allocation->updateTaskCount(2, defaultEngine.osContext->getContextId());
volatile uint32_t *completionAddress = defaultEngine.commandStreamReceiver->getTagAddress();
completionAddress += (Drm::completionFenceOffset / sizeof(uint32_t));
*completionAddress = 2; //1st context is ready
completionAddress += (postSyncOffset / sizeof(uint32_t));
*completionAddress = 1;
memoryManager->handleFenceCompletion(allocation);
uint64_t expectedAddress = castToUint64(const_cast<uint32_t *>(defaultEngine.commandStreamReceiver->getTagAddress())) +
Drm::completionFenceOffset +
postSyncOffset;
constexpr uint64_t expectedValue = 2;
EXPECT_EQ(1u, mock->waitUserFenceCall.called);
EXPECT_EQ(expectedAddress, mock->waitUserFenceCall.address);
EXPECT_EQ(expectedValue, mock->waitUserFenceCall.value);
memoryManager->freeGraphicsMemory(allocation);
}

View File

@@ -0,0 +1,50 @@
/*
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/os_interface/linux/drm_engine_mapper.h"
#include "shared/test/common/test_macros/test.h"
#include "drm/i915_drm.h"
using namespace NEO;
TEST(DrmMapperTests, GivenEngineWhenMappingNodeThenCorrectEngineReturned) {
unsigned int flagBcs = DrmEngineMapper::engineNodeMap(aub_stream::ENGINE_BCS);
unsigned int flagRcs = DrmEngineMapper::engineNodeMap(aub_stream::ENGINE_RCS);
unsigned int flagCcs = DrmEngineMapper::engineNodeMap(aub_stream::ENGINE_CCS);
unsigned int flagCccs = DrmEngineMapper::engineNodeMap(aub_stream::ENGINE_CCCS);
unsigned int expectedBcs = I915_EXEC_BLT;
unsigned int expectedRcs = I915_EXEC_RENDER;
unsigned int expectedCcs = I915_EXEC_DEFAULT;
unsigned int expectedCccs = I915_EXEC_RENDER;
EXPECT_EQ(expectedBcs, flagBcs);
EXPECT_EQ(expectedRcs, flagRcs);
EXPECT_EQ(expectedCcs, flagCcs);
EXPECT_EQ(expectedCccs, flagCccs);
}
TEST(DrmMapperTests, givenLinkCopyEngineWhenMapperCalledThenReturnDefaultBltEngine) {
const std::array<aub_stream::EngineType, 8> bcsLinkEngines = {{aub_stream::ENGINE_BCS1, aub_stream::ENGINE_BCS2, aub_stream::ENGINE_BCS3,
aub_stream::ENGINE_BCS4, aub_stream::ENGINE_BCS5, aub_stream::ENGINE_BCS6,
aub_stream::ENGINE_BCS7, aub_stream::ENGINE_BCS8}};
for (auto engine : bcsLinkEngines) {
EXPECT_EQ(static_cast<unsigned int>(I915_EXEC_BLT), DrmEngineMapper::engineNodeMap(engine));
}
}
TEST(DrmMapperTests, GivenCcsWhenGettingEngineNodeMapThenReturnDefault) {
unsigned int expected = I915_EXEC_DEFAULT;
EXPECT_EQ(DrmEngineMapper::engineNodeMap(aub_stream::ENGINE_CCS), expected);
EXPECT_EQ(DrmEngineMapper::engineNodeMap(aub_stream::ENGINE_CCS1), expected);
EXPECT_EQ(DrmEngineMapper::engineNodeMap(aub_stream::ENGINE_CCS2), expected);
EXPECT_EQ(DrmEngineMapper::engineNodeMap(aub_stream::ENGINE_CCS3), expected);
}
TEST(DrmMapperTests, GivenVcsWhenGettingEngineNodeMapThenExceptionIsThrown) {
EXPECT_THROW(DrmEngineMapper::engineNodeMap(aub_stream::ENGINE_VCS), std::exception);
}

View File

@@ -0,0 +1,126 @@
/*
* Copyright (C) 2019-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/helpers/constants.h"
#include "shared/source/helpers/file_io.h"
#include "shared/source/os_interface/linux/os_inc.h"
#include "shared/source/os_interface/linux/os_memory_linux.h"
#include "shared/source/utilities/stackvec.h"
#include "gtest/gtest.h"
namespace NEO {
class MockOSMemoryLinux : public OSMemoryLinux {
public:
static std::unique_ptr<MockOSMemoryLinux> create() {
return std::make_unique<MockOSMemoryLinux>();
}
MockOSMemoryLinux() = default;
void *mmapWrapper(void *addr, size_t size, int prot, int flags, int fd, off_t off) override {
mmapWrapperCalled++;
mmapWrapperParamsPassed.push_back({addr, size, prot, flags, fd, off});
return this->baseMmapWrapper(addr, size, prot, flags, fd, off);
}
struct MmapWrapperParams {
void *addr;
size_t size;
int prot;
int flags;
int fd;
off_t off;
};
uint32_t mmapWrapperCalled = 0u;
StackVec<MmapWrapperParams, 1> mmapWrapperParamsPassed{};
int munmapWrapper(void *addr, size_t size) override {
munmapWrapperCalled++;
munmapWrapperParamsPassed.push_back({addr, size});
return this->baseMunmapWrapper(addr, size);
}
struct MunmapWrapperParams {
void *addr;
size_t size;
};
uint32_t munmapWrapperCalled = 0u;
StackVec<MunmapWrapperParams, 1> munmapWrapperParamsPassed{};
void *baseMmapWrapper(void *addr, size_t size, int prot, int flags, int fd, off_t off) {
return OSMemoryLinux::mmapWrapper(addr, size, prot, flags, fd, off);
}
int baseMunmapWrapper(void *addr, size_t size) {
return OSMemoryLinux::munmapWrapper(addr, size);
}
};
TEST(OSMemoryLinux, givenOSMemoryLinuxWhenReserveCpuAddressRangeIsCalledThenMinusOneIsPassedToMmapAsFdParam) {
auto mockOSMemoryLinux = MockOSMemoryLinux::create();
auto reservedCpuRange = mockOSMemoryLinux->reserveCpuAddressRange(MemoryConstants::pageSize, MemoryConstants::pageSize64k);
mockOSMemoryLinux->releaseCpuAddressRange(reservedCpuRange);
EXPECT_EQ(-1, mockOSMemoryLinux->mmapWrapperParamsPassed[0].fd);
EXPECT_EQ(reservedCpuRange.originalPtr, mockOSMemoryLinux->munmapWrapperParamsPassed[0].addr);
EXPECT_EQ(reservedCpuRange.actualReservedSize, mockOSMemoryLinux->munmapWrapperParamsPassed[0].size);
}
TEST(OSMemoryLinux, givenOSMemoryLinuxWhenReserveCpuAddressRangeIsCalledAndBaseAddressIsSpecifiedThenCorrectValueIsPassedToMmapAsAddrParam) {
auto mockOSMemoryLinux = MockOSMemoryLinux::create();
auto reservedCpuRange = mockOSMemoryLinux->reserveCpuAddressRange(reinterpret_cast<void *>(0x10000000), MemoryConstants::pageSize, MemoryConstants::pageSize64k);
mockOSMemoryLinux->releaseCpuAddressRange(reservedCpuRange);
EXPECT_EQ(reinterpret_cast<void *>(0x10000000), mockOSMemoryLinux->mmapWrapperParamsPassed[0].addr);
EXPECT_EQ(-1, mockOSMemoryLinux->mmapWrapperParamsPassed[0].fd);
EXPECT_EQ(reservedCpuRange.originalPtr, mockOSMemoryLinux->munmapWrapperParamsPassed[0].addr);
EXPECT_EQ(reservedCpuRange.actualReservedSize, mockOSMemoryLinux->munmapWrapperParamsPassed[0].size);
}
TEST(OSMemoryLinux, givenOSMemoryLinuxWhenReserveCpuAddressRangeIsCalledAndBaseAddressIsNotSpecifiedThenoZeroIsPassedToMmapAsAddrParam) {
auto mockOSMemoryLinux = MockOSMemoryLinux::create();
auto reservedCpuRange = mockOSMemoryLinux->reserveCpuAddressRange(MemoryConstants::pageSize, MemoryConstants::pageSize64k);
mockOSMemoryLinux->releaseCpuAddressRange(reservedCpuRange);
EXPECT_EQ(nullptr, mockOSMemoryLinux->mmapWrapperParamsPassed[0].addr);
EXPECT_EQ(-1, mockOSMemoryLinux->mmapWrapperParamsPassed[0].fd);
EXPECT_EQ(reservedCpuRange.originalPtr, mockOSMemoryLinux->munmapWrapperParamsPassed[0].addr);
EXPECT_EQ(reservedCpuRange.actualReservedSize, mockOSMemoryLinux->munmapWrapperParamsPassed[0].size);
}
TEST(OSMemoryLinux, GivenProcSelfMapsFileExistsWhenGetMemoryMapsIsQueriedThenValidValueIsReturned) {
auto mockOSMemoryLinux = MockOSMemoryLinux::create();
std::string mapsFile(std::string(Os::sysFsProcPathPrefix) + "self/maps");
EXPECT_TRUE(fileExists(mapsFile));
OSMemory::MemoryMaps memoryMaps;
mockOSMemoryLinux->getMemoryMaps(memoryMaps);
static const OSMemory::MappedRegion referenceMaps[] = {
{0x564fcd1fa000, 0x564fcd202000}, {0x564fcd401000, 0x564fcd402000}, {0x564fcd402000, 0x564fcd403000}, {0x564fcdf40000, 0x564fcdf61000}, {0x7fded3d79000, 0x7fded4879000}, {0x7fded4879000, 0x7fded4a60000}, {0x7fded4a60000, 0x7fded4c60000}, {0x7fded4c60000, 0x7fded4c64000}, {0x7fded4c64000, 0x7fded4c66000}, {0x7fded4c66000, 0x7fded4c6a000}, {0x7fded4c6a000, 0x7fded4c91000}, {0x7fded4e54000, 0x7fded4e78000}, {0x7fded4e91000, 0x7fded4e92000}, {0x7fded4e92000, 0x7fded4e93000}, {0x7fded4e93000, 0x7fded4e94000}, {0x7ffd6dfa2000, 0x7ffd6dfc3000}, {0x7ffd6dfe8000, 0x7ffd6dfeb000}, {0x7ffd6dfeb000, 0x7ffd6dfec000}, {0xffffffffff600000, 0xffffffffff601000}};
EXPECT_FALSE(memoryMaps.empty());
EXPECT_EQ(memoryMaps.size(), GTEST_ARRAY_SIZE_(referenceMaps));
for (size_t i = 0; i < memoryMaps.size(); ++i) {
EXPECT_EQ(memoryMaps[i].start, referenceMaps[i].start);
EXPECT_EQ(memoryMaps[i].end, referenceMaps[i].end);
}
}
}; // namespace NEO

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,48 @@
/*
* Copyright (C) 2019-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/os_interface/linux/drm_memory_operations_handler_default.h"
#include "shared/test/common/mocks/mock_graphics_allocation.h"
#include "shared/test/common/test_macros/test.h"
#include <memory>
using namespace NEO;
struct MockDrmMemoryOperationsHandlerDefault : public DrmMemoryOperationsHandlerDefault {
using DrmMemoryOperationsHandlerDefault::residency;
};
struct DrmMemoryOperationsHandlerBaseTest : public ::testing::Test {
void SetUp() override {
drmMemoryOperationsHandler = std::make_unique<MockDrmMemoryOperationsHandlerDefault>();
allocationPtr = &graphicsAllocation;
}
MockGraphicsAllocation graphicsAllocation;
GraphicsAllocation *allocationPtr;
std::unique_ptr<MockDrmMemoryOperationsHandlerDefault> drmMemoryOperationsHandler;
};
TEST_F(DrmMemoryOperationsHandlerBaseTest, whenMakingAllocationResidentThenAllocationIsResident) {
EXPECT_EQ(drmMemoryOperationsHandler->makeResident(nullptr, ArrayRef<GraphicsAllocation *>(&allocationPtr, 1)), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(drmMemoryOperationsHandler->residency.size(), 1u);
EXPECT_TRUE(drmMemoryOperationsHandler->residency.find(allocationPtr) != drmMemoryOperationsHandler->residency.end());
EXPECT_EQ(drmMemoryOperationsHandler->isResident(nullptr, graphicsAllocation), MemoryOperationsStatus::SUCCESS);
}
TEST_F(DrmMemoryOperationsHandlerBaseTest, whenEvictingResidentAllocationThenAllocationIsNotResident) {
EXPECT_EQ(drmMemoryOperationsHandler->residency.size(), 0u);
EXPECT_EQ(drmMemoryOperationsHandler->makeResident(nullptr, ArrayRef<GraphicsAllocation *>(&allocationPtr, 1)), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(drmMemoryOperationsHandler->isResident(nullptr, graphicsAllocation), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(drmMemoryOperationsHandler->residency.size(), 1u);
EXPECT_TRUE(drmMemoryOperationsHandler->residency.find(allocationPtr) != drmMemoryOperationsHandler->residency.end());
EXPECT_EQ(drmMemoryOperationsHandler->evict(nullptr, graphicsAllocation), MemoryOperationsStatus::SUCCESS);
EXPECT_EQ(drmMemoryOperationsHandler->isResident(nullptr, graphicsAllocation), MemoryOperationsStatus::MEMORY_NOT_FOUND);
EXPECT_EQ(drmMemoryOperationsHandler->residency.size(), 0u);
}

View File

@@ -0,0 +1,173 @@
/*
* Copyright (C) 2020-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/os_interface/linux/system_info.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/helpers/default_hw_info.h"
#include "shared/test/common/libult/linux/drm_mock.h"
#include "shared/test/common/os_interface/linux/drm_mock_device_blob.h"
#include "shared/test/unit_test/helpers/gtest_helpers.h"
#include "gtest/gtest.h"
using namespace NEO;
TEST(DrmSystemInfoTest, whenQueryingSystemInfoThenSystemInfoIsNotCreatedAndIoctlsAreCalledOnce) {
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
executionEnvironment->prepareRootDeviceEnvironments(1);
DrmMock drm(*executionEnvironment->rootDeviceEnvironments[0]);
EXPECT_FALSE(drm.querySystemInfo());
EXPECT_EQ(nullptr, drm.getSystemInfo());
EXPECT_EQ(1u, drm.ioctlCallsCount);
}
TEST(DrmSystemInfoTest, givenSystemInfoCreatedWhenQueryingSpecificAtrributesThenReturnZero) {
std::vector<uint8_t> inputData{};
SystemInfo systemInfo(inputData);
EXPECT_EQ(0u, systemInfo.getMemoryType());
EXPECT_EQ(0u, systemInfo.getMaxMemoryChannels());
EXPECT_EQ(0u, systemInfo.getNumThreadsPerEu());
EXPECT_EQ(0u, systemInfo.getTotalVsThreads());
EXPECT_EQ(0u, systemInfo.getTotalHsThreads());
EXPECT_EQ(0u, systemInfo.getTotalDsThreads());
EXPECT_EQ(0u, systemInfo.getTotalGsThreads());
EXPECT_EQ(0u, systemInfo.getTotalPsThreads());
EXPECT_EQ(0u, systemInfo.getMaxEuPerDualSubSlice());
EXPECT_EQ(0u, systemInfo.getMaxSlicesSupported());
EXPECT_EQ(0u, systemInfo.getMaxDualSubSlicesSupported());
EXPECT_EQ(0u, systemInfo.getMaxRCS());
EXPECT_EQ(0u, systemInfo.getMaxCCS());
}
TEST(DrmSystemInfoTest, givenSetupHardwareInfoWhenQuerySystemInfoFalseThenSystemInfoIsNotCreatedAndDebugMessageIsNotPrinted) {
struct DrmMockToQuerySystemInfo : public DrmMock {
DrmMockToQuerySystemInfo(RootDeviceEnvironment &rootDeviceEnvironment)
: DrmMock(rootDeviceEnvironment) {}
bool querySystemInfo() override { return false; }
};
DebugManagerStateRestore restorer;
DebugManager.flags.PrintDebugMessages.set(true);
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
executionEnvironment->prepareRootDeviceEnvironments(1);
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
DrmMockToQuerySystemInfo drm(*executionEnvironment->rootDeviceEnvironments[0]);
HardwareInfo hwInfo = *defaultHwInfo;
auto setupHardwareInfo = [](HardwareInfo *, bool) {};
DeviceDescriptor device = {0, &hwInfo, setupHardwareInfo};
::testing::internal::CaptureStdout();
int ret = drm.setupHardwareInfo(&device, false);
EXPECT_EQ(ret, 0);
EXPECT_EQ(nullptr, drm.getSystemInfo());
EXPECT_TRUE(isEmpty(::testing::internal::GetCapturedStdout()));
}
TEST(DrmSystemInfoTest, whenQueryingSystemInfoThenSystemInfoIsCreatedAndReturnsNonZeros) {
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
executionEnvironment->prepareRootDeviceEnvironments(1);
DrmMockEngine drm(*executionEnvironment->rootDeviceEnvironments[0]);
EXPECT_TRUE(drm.querySystemInfo());
auto systemInfo = drm.getSystemInfo();
EXPECT_NE(nullptr, systemInfo);
EXPECT_NE(0u, systemInfo->getMaxMemoryChannels());
EXPECT_NE(0u, systemInfo->getMemoryType());
EXPECT_NE(0u, systemInfo->getTotalVsThreads());
EXPECT_NE(0u, systemInfo->getTotalHsThreads());
EXPECT_NE(0u, systemInfo->getTotalDsThreads());
EXPECT_NE(0u, systemInfo->getTotalGsThreads());
EXPECT_NE(0u, systemInfo->getTotalPsThreads());
EXPECT_NE(0u, systemInfo->getMaxEuPerDualSubSlice());
EXPECT_NE(0u, systemInfo->getMaxSlicesSupported());
EXPECT_NE(0u, systemInfo->getMaxDualSubSlicesSupported());
EXPECT_NE(0u, systemInfo->getMaxDualSubSlicesSupported());
EXPECT_NE(0u, systemInfo->getMaxRCS());
EXPECT_NE(0u, systemInfo->getMaxCCS());
EXPECT_EQ(2u, drm.ioctlCallsCount);
}
TEST(DrmSystemInfoTest, givenSystemInfoCreatedFromDeviceBlobWhenQueryingSpecificAtrributesThenReturnCorrectValues) {
SystemInfo systemInfo(inputBlobData);
EXPECT_EQ(0x0Au, systemInfo.getMaxMemoryChannels());
EXPECT_EQ(0x0Bu, systemInfo.getMemoryType());
EXPECT_EQ(0x10u, systemInfo.getTotalVsThreads());
EXPECT_EQ(0x12u, systemInfo.getTotalHsThreads());
EXPECT_EQ(0x13u, systemInfo.getTotalDsThreads());
EXPECT_EQ(0x11u, systemInfo.getTotalGsThreads());
EXPECT_EQ(0x15u, systemInfo.getTotalPsThreads());
EXPECT_EQ(0x03u, systemInfo.getMaxEuPerDualSubSlice());
EXPECT_EQ(0x01u, systemInfo.getMaxSlicesSupported());
EXPECT_EQ(0x02u, systemInfo.getMaxDualSubSlicesSupported());
EXPECT_EQ(0x02u, systemInfo.getMaxDualSubSlicesSupported());
EXPECT_EQ(0x17u, systemInfo.getMaxRCS());
EXPECT_EQ(0x18u, systemInfo.getMaxCCS());
}
TEST(DrmSystemInfoTest, givenSetupHardwareInfoWhenQuerySystemInfoFailsThenSystemInfoIsNotCreatedAndDebugMessageIsPrinted) {
DebugManagerStateRestore restorer;
DebugManager.flags.PrintDebugMessages.set(true);
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
executionEnvironment->prepareRootDeviceEnvironments(1);
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
DrmMockEngine drm(*executionEnvironment->rootDeviceEnvironments[0]);
HardwareInfo hwInfo = *defaultHwInfo;
auto setupHardwareInfo = [](HardwareInfo *, bool) {};
DeviceDescriptor device = {0, &hwInfo, setupHardwareInfo};
::testing::internal::CaptureStdout();
drm.failQueryDeviceBlob = true;
int ret = drm.setupHardwareInfo(&device, false);
EXPECT_EQ(ret, 0);
EXPECT_EQ(nullptr, drm.getSystemInfo());
EXPECT_TRUE(hasSubstr(::testing::internal::GetCapturedStdout(), "INFO: System Info query failed!\n"));
}
TEST(DrmSystemInfoTest, givenSetupHardwareInfoWhenQuerySystemInfoSucceedsThenSystemInfoIsCreatedAndUsedToSetHardwareInfoAttributes) {
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
executionEnvironment->prepareRootDeviceEnvironments(1);
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
DrmMockEngine drm(*executionEnvironment->rootDeviceEnvironments[0]);
HardwareInfo hwInfo = *defaultHwInfo;
auto setupHardwareInfo = [](HardwareInfo *, bool) {};
GT_SYSTEM_INFO &gtSystemInfo = hwInfo.gtSystemInfo;
DeviceDescriptor device = {0, &hwInfo, setupHardwareInfo};
int ret = drm.setupHardwareInfo(&device, false);
EXPECT_EQ(ret, 0);
EXPECT_NE(nullptr, drm.getSystemInfo());
EXPECT_GT(gtSystemInfo.TotalVsThreads, 0u);
EXPECT_GT(gtSystemInfo.TotalHsThreads, 0u);
EXPECT_GT(gtSystemInfo.TotalDsThreads, 0u);
EXPECT_GT(gtSystemInfo.TotalGsThreads, 0u);
EXPECT_GT(gtSystemInfo.TotalPsThreadsWindowerRange, 0u);
EXPECT_GT(gtSystemInfo.TotalDsThreads, 0u);
EXPECT_GT(gtSystemInfo.MaxEuPerSubSlice, 0u);
EXPECT_GT(gtSystemInfo.MaxSlicesSupported, 0u);
EXPECT_GT(gtSystemInfo.MaxSubSlicesSupported, 0u);
EXPECT_GT(gtSystemInfo.MaxDualSubSlicesSupported, 0u);
EXPECT_GT(gtSystemInfo.MemoryType, 0u);
}

View File

@@ -0,0 +1,81 @@
/*
* Copyright (C) 2020-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/os_interface/linux/drm_debug.h"
#include "shared/test/common/libult/linux/drm_mock.h"
#include "gtest/gtest.h"
using namespace NEO;
TEST(DrmUuidTest, GivenDrmWhenGeneratingUUIDThenCorrectStringsAreReturned) {
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
executionEnvironment->prepareRootDeviceEnvironments(1);
DrmMock drm{*executionEnvironment->rootDeviceEnvironments[0]};
auto uuid1 = drm.generateUUID();
auto uuid2 = drm.generateUUID();
std::string uuidff;
for (int i = 0; i < 0xff - 2; i++) {
uuidff = drm.generateUUID();
}
EXPECT_STREQ("00000000-0000-0000-0000-000000000001", uuid1.c_str());
EXPECT_STREQ("00000000-0000-0000-0000-000000000002", uuid2.c_str());
EXPECT_STREQ("00000000-0000-0000-0000-0000000000ff", uuidff.c_str());
}
TEST(DrmUuidTest, GivenDrmWhenGeneratingElfUUIDThenCorrectStringsAreReturned) {
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
executionEnvironment->prepareRootDeviceEnvironments(1);
DrmMock drm{*executionEnvironment->rootDeviceEnvironments[0]};
std::string elfClassUuid = classNamesToUuid[static_cast<uint32_t>(DrmResourceClass::Elf)].second;
std::string uuid1stElfClass = elfClassUuid.substr(0, 18);
char data[] = "abc";
auto uuid1 = drm.generateElfUUID(static_cast<const void *>(data));
std::string uuid1stElfBin1 = uuid1.substr(0, 18);
EXPECT_STREQ(uuid1stElfClass.c_str(), uuid1stElfBin1.c_str());
char data2[] = "123";
auto uuid2 = drm.generateElfUUID(static_cast<const void *>(data2));
std::string uuid1stElfBin2 = uuid2.substr(0, 18);
EXPECT_STREQ(uuid1stElfClass.c_str(), uuid1stElfBin2.c_str());
auto uuid3 = drm.generateElfUUID(reinterpret_cast<const void *>(0xFFFFFFFFFFFFFFFF));
std::string uuidElf = uuid1stElfClass + "-ffff-ffffffffffff";
EXPECT_STREQ(uuidElf.c_str(), uuid3.c_str());
}
TEST(DrmUuidTest, whenResourceClassIsUsedToIndexClassNamesThenCorrectNamesAreReturned) {
EXPECT_STREQ(classNamesToUuid[static_cast<uint32_t>(DrmResourceClass::Elf)].first, "I915_UUID_CLASS_ELF_BINARY");
EXPECT_STREQ(classNamesToUuid[static_cast<uint32_t>(DrmResourceClass::Isa)].first, "I915_UUID_CLASS_ISA_BYTECODE");
EXPECT_STREQ(classNamesToUuid[static_cast<uint32_t>(DrmResourceClass::ContextSaveArea)].first, "I915_UUID_L0_SIP_AREA");
EXPECT_STREQ(classNamesToUuid[static_cast<uint32_t>(DrmResourceClass::ModuleHeapDebugArea)].first, "I915_UUID_L0_MODULE_AREA");
EXPECT_STREQ(classNamesToUuid[static_cast<uint32_t>(DrmResourceClass::SbaTrackingBuffer)].first, "I915_UUID_L0_SBA_AREA");
EXPECT_STREQ(classNamesToUuid[static_cast<uint32_t>(DrmResourceClass::L0ZebinModule)].first, "L0_ZEBIN_MODULE");
}
TEST(DrmUuidTest, givenUuidStringWhenGettingClassIndexThenCorrectIndexForValidStringsIsReturned) {
uint32_t index = 100;
auto validUuid = DrmUuid::getClassUuidIndex(classNamesToUuid[static_cast<uint32_t>(DrmResourceClass::ContextSaveArea)].second, index);
EXPECT_TRUE(validUuid);
EXPECT_EQ(static_cast<uint32_t>(DrmResourceClass::ContextSaveArea), index);
validUuid = DrmUuid::getClassUuidIndex(classNamesToUuid[static_cast<uint32_t>(DrmResourceClass::ModuleHeapDebugArea)].second, index);
EXPECT_TRUE(validUuid);
EXPECT_EQ(static_cast<uint32_t>(DrmResourceClass::ModuleHeapDebugArea), index);
index = 100;
validUuid = DrmUuid::getClassUuidIndex("invalid", index);
EXPECT_FALSE(validUuid);
EXPECT_EQ(100u, index);
}

View File

@@ -0,0 +1,53 @@
/*
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/command_stream/preemption.h"
#include "shared/source/gmm_helper/gmm_lib.h"
#include "shared/source/helpers/hw_helper.h"
#include "shared/source/os_interface/linux/os_context_linux.h"
#include "shared/source/os_interface/os_interface.h"
#include "shared/test/common/libult/linux/drm_mock.h"
#include "shared/test/common/mocks/mock_execution_environment.h"
#include "gtest/gtest.h"
namespace NEO {
TEST(OsInterfaceTest, GivenLinuxWhenCallingAre64kbPagesEnabledThenReturnFalse) {
EXPECT_FALSE(OSInterface::are64kbPagesEnabled());
}
TEST(OsInterfaceTest, GivenLinuxOsInterfaceWhenDeviceHandleQueriedThenZeroIsReturned) {
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
executionEnvironment->prepareRootDeviceEnvironments(1);
auto drm = std::make_unique<DrmMock>(*executionEnvironment->rootDeviceEnvironments[0]);
OSInterface osInterface;
osInterface.setDriverModel(std::move(drm));
EXPECT_EQ(0u, osInterface.getDriverModel()->getDeviceHandle());
}
TEST(OsInterfaceTest, GivenLinuxOsWhenCheckForNewResourceImplicitFlushSupportThenReturnTrue) {
EXPECT_TRUE(OSInterface::newResourceImplicitFlush);
}
TEST(OsInterfaceTest, GivenLinuxOsWhenCheckForGpuIdleImplicitFlushSupportThenReturnFalse) {
EXPECT_TRUE(OSInterface::gpuIdleImplicitFlush);
}
TEST(OsInterfaceTest, GivenLinuxOsInterfaceWhenCallingIsDebugAttachAvailableThenFalseIsReturned) {
OSInterface osInterface;
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
executionEnvironment->prepareRootDeviceEnvironments(1);
DrmMock *drm = new DrmMock(*executionEnvironment->rootDeviceEnvironments[0]);
osInterface.setDriverModel(std::unique_ptr<DriverModel>(drm));
EXPECT_FALSE(osInterface.isDebugAttachAvailable());
}
} // namespace NEO

View File

@@ -0,0 +1,51 @@
/*
* Copyright (C) 2020-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/os_interface/linux/os_library_linux.h"
#include "shared/source/os_interface/linux/sys_calls.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/helpers/variable_backup.h"
#include "gtest/gtest.h"
#include <dlfcn.h>
namespace NEO {
namespace SysCalls {
extern int dlOpenFlags;
extern bool dlOpenCalled;
} // namespace SysCalls
TEST(OsLibraryTest, WhenCreatingFullSystemPathThenProperPathIsConstructed) {
auto fullPath = OsLibrary::createFullSystemPath("test");
EXPECT_STREQ("test", fullPath.c_str());
}
TEST(OsLibraryTest, GivenDisableDeepBindFlagWhenOpeningLibraryThenRtldDeepBindFlagIsNotPassed) {
DebugManagerStateRestore restorer;
VariableBackup<int> dlOpenFlagsBackup{&NEO::SysCalls::dlOpenFlags, 0};
VariableBackup<bool> dlOpenCalledBackup{&NEO::SysCalls::dlOpenCalled, false};
DebugManager.flags.DisableDeepBind.set(1);
auto lib = std::make_unique<Linux::OsLibrary>("_abc.so", nullptr);
EXPECT_TRUE(NEO::SysCalls::dlOpenCalled);
EXPECT_EQ(0, NEO::SysCalls::dlOpenFlags & RTLD_DEEPBIND);
}
TEST(OsLibraryTest, GivenInvalidLibraryWhenOpeningLibraryThenDlopenErrorIsReturned) {
VariableBackup<bool> dlOpenCalledBackup{&NEO::SysCalls::dlOpenCalled, false};
std::string errorValue;
auto lib = std::make_unique<Linux::OsLibrary>("_abc.so", &errorValue);
EXPECT_FALSE(errorValue.empty());
EXPECT_TRUE(NEO::SysCalls::dlOpenCalled);
}
} // namespace NEO

View File

@@ -0,0 +1,272 @@
/*
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/os_interface/linux/drm_neo.h"
#include "shared/source/os_interface/linux/os_time_linux.h"
#include "shared/source/os_interface/os_interface.h"
#include "shared/test/common/mocks/linux/mock_os_time_linux.h"
#include "shared/test/common/mocks/mock_execution_environment.h"
#include "shared/test/common/os_interface/linux/device_command_stream_fixture.h"
#include "shared/test/common/test_macros/test.h"
#include "gtest/gtest.h"
#include <dlfcn.h>
static int actualTime = 0;
int getTimeFuncFalse(clockid_t clkId, struct timespec *tp) throw() {
return -1;
}
int getTimeFuncTrue(clockid_t clkId, struct timespec *tp) throw() {
tp->tv_sec = 0;
tp->tv_nsec = ++actualTime;
return 0;
}
int resolutionFuncFalse(clockid_t clkId, struct timespec *res) throw() {
return -1;
}
int resolutionFuncTrue(clockid_t clkId, struct timespec *res) throw() {
res->tv_sec = 0;
res->tv_nsec = 5;
return 0;
}
using namespace NEO;
struct DrmTimeTest : public ::testing::Test {
public:
void SetUp() override {
osInterface = std::unique_ptr<OSInterface>(new OSInterface());
osTime = MockOSTimeLinux::create(osInterface.get());
osTime->setResolutionFunc(resolutionFuncTrue);
osTime->setGetTimeFunc(getTimeFuncTrue);
}
void TearDown() override {
}
std::unique_ptr<MockOSTimeLinux> osTime;
std::unique_ptr<OSInterface> osInterface;
MockExecutionEnvironment executionEnvironment;
};
TEST_F(DrmTimeTest, GivenMockOsTimeThenInitializes) {
}
TEST_F(DrmTimeTest, WhenGettingCpuTimeThenSucceeds) {
uint64_t time = 0;
auto error = osTime->getCpuTime(&time);
EXPECT_TRUE(error);
EXPECT_NE(0ULL, time);
}
TEST_F(DrmTimeTest, GivenFalseTimeFuncWhenGettingCpuTimeThenFails) {
uint64_t time = 0;
osTime->setGetTimeFunc(getTimeFuncFalse);
auto error = osTime->getCpuTime(&time);
EXPECT_FALSE(error);
}
TEST_F(DrmTimeTest, WhenGettingGpuTimeThenSuceeds) {
uint64_t time = 0;
auto pDrm = new DrmMockTime(mockFd, *executionEnvironment.rootDeviceEnvironments[0]);
osTime->updateDrm(pDrm);
auto error = osTime->getDeviceTime()->getGpuTime32(&time);
EXPECT_TRUE(error);
EXPECT_NE(0ULL, time);
error = osTime->getDeviceTime()->getGpuTime36(&time);
EXPECT_TRUE(error);
EXPECT_NE(0ULL, time);
error = osTime->getDeviceTime()->getGpuTimeSplitted(&time);
EXPECT_TRUE(error);
EXPECT_NE(0ULL, time);
}
TEST_F(DrmTimeTest, GivenInvalidDrmWhenGettingGpuTimeThenFails) {
uint64_t time = 0;
auto pDrm = new DrmMockFail(*executionEnvironment.rootDeviceEnvironments[0]);
osTime->updateDrm(pDrm);
auto error = osTime->getDeviceTime()->getGpuTime32(&time);
EXPECT_FALSE(error);
error = osTime->getDeviceTime()->getGpuTime36(&time);
EXPECT_FALSE(error);
error = osTime->getDeviceTime()->getGpuTimeSplitted(&time);
EXPECT_FALSE(error);
}
TEST_F(DrmTimeTest, WhenGettingCpuGpuTimeThenSucceeds) {
TimeStampData cpuGpuTime01 = {0, 0};
TimeStampData cpuGpuTime02 = {0, 0};
auto pDrm = new DrmMockTime(mockFd, *executionEnvironment.rootDeviceEnvironments[0]);
osTime->updateDrm(pDrm);
auto error = osTime->getCpuGpuTime(&cpuGpuTime01);
EXPECT_TRUE(error);
EXPECT_NE(0ULL, cpuGpuTime01.CPUTimeinNS);
EXPECT_NE(0ULL, cpuGpuTime01.GPUTimeStamp);
error = osTime->getCpuGpuTime(&cpuGpuTime02);
EXPECT_TRUE(error);
EXPECT_NE(0ULL, cpuGpuTime02.CPUTimeinNS);
EXPECT_NE(0ULL, cpuGpuTime02.GPUTimeStamp);
EXPECT_GT(cpuGpuTime02.GPUTimeStamp, cpuGpuTime01.GPUTimeStamp);
EXPECT_GT(cpuGpuTime02.CPUTimeinNS, cpuGpuTime01.CPUTimeinNS);
}
TEST_F(DrmTimeTest, GivenDrmWhenGettingCpuGpuTimeThenSucceeds) {
TimeStampData cpuGpuTime01 = {0, 0};
TimeStampData cpuGpuTime02 = {0, 0};
auto pDrm = new DrmMockTime(mockFd, *executionEnvironment.rootDeviceEnvironments[0]);
osTime->updateDrm(pDrm);
auto error = osTime->getCpuGpuTime(&cpuGpuTime01);
EXPECT_TRUE(error);
EXPECT_NE(0ULL, cpuGpuTime01.CPUTimeinNS);
EXPECT_NE(0ULL, cpuGpuTime01.GPUTimeStamp);
error = osTime->getCpuGpuTime(&cpuGpuTime02);
EXPECT_TRUE(error);
EXPECT_NE(0ULL, cpuGpuTime02.CPUTimeinNS);
EXPECT_NE(0ULL, cpuGpuTime02.GPUTimeStamp);
EXPECT_GT(cpuGpuTime02.GPUTimeStamp, cpuGpuTime01.GPUTimeStamp);
EXPECT_GT(cpuGpuTime02.CPUTimeinNS, cpuGpuTime01.CPUTimeinNS);
}
TEST_F(DrmTimeTest, givenGetCpuGpuTimeWhenItIsUnavailableThenReturnFalse) {
TimeStampData cpuGpuTime = {0, 0};
auto error = osTime->getCpuGpuTime(&cpuGpuTime);
EXPECT_FALSE(error);
}
TEST_F(DrmTimeTest, GivenInvalidDrmWhenGettingCpuGpuTimeThenFails) {
TimeStampData cpuGpuTime01 = {0, 0};
auto pDrm = new DrmMockFail(*executionEnvironment.rootDeviceEnvironments[0]);
osTime->updateDrm(pDrm);
auto error = osTime->getCpuGpuTime(&cpuGpuTime01);
EXPECT_FALSE(error);
}
TEST_F(DrmTimeTest, GivenInvalidFuncTimeWhenGettingCpuGpuTimeCpuThenFails) {
TimeStampData cpuGpuTime01 = {0, 0};
auto pDrm = new DrmMockTime(mockFd, *executionEnvironment.rootDeviceEnvironments[0]);
osTime->setGetTimeFunc(getTimeFuncFalse);
osTime->updateDrm(pDrm);
auto error = osTime->getCpuGpuTime(&cpuGpuTime01);
EXPECT_FALSE(error);
}
TEST_F(DrmTimeTest, WhenGettingTimeThenTimeIsCorrect) {
auto drm = new DrmMockCustom(*executionEnvironment.rootDeviceEnvironments[0]);
osTime->updateDrm(drm);
{
auto p = osTime->getDeviceTime()->getGpuTime;
EXPECT_EQ(p, &DeviceTimeDrm::getGpuTime36);
}
{
drm->ioctl_res = -1;
osTime->getDeviceTime()->timestampTypeDetect();
auto p = osTime->getDeviceTime()->getGpuTime;
EXPECT_EQ(p, &DeviceTimeDrm::getGpuTime32);
}
DrmMockCustom::IoctlResExt ioctlToPass = {1, 0};
{
drm->reset();
drm->ioctl_res = -1;
drm->ioctl_res_ext = &ioctlToPass; // 2nd ioctl is successful
osTime->getDeviceTime()->timestampTypeDetect();
auto p = osTime->getDeviceTime()->getGpuTime;
EXPECT_EQ(p, &DeviceTimeDrm::getGpuTimeSplitted);
drm->ioctl_res_ext = &drm->NONE;
}
}
TEST_F(DrmTimeTest, givenGpuTimestampResolutionQueryWhenIoctlFailsThenDefaultResolutionIsReturned) {
auto defaultResolution = defaultHwInfo->capabilityTable.defaultProfilingTimerResolution;
auto drm = new DrmMockCustom(*executionEnvironment.rootDeviceEnvironments[0]);
osTime->updateDrm(drm);
drm->getParamRetValue = 0;
drm->ioctl_res = -1;
auto result = osTime->getDynamicDeviceTimerResolution(*defaultHwInfo);
EXPECT_DOUBLE_EQ(result, defaultResolution);
}
TEST_F(DrmTimeTest, givenGetDynamicDeviceTimerClockWhenIoctlFailsThenDefaultClockIsReturned) {
auto defaultResolution = defaultHwInfo->capabilityTable.defaultProfilingTimerResolution;
auto drm = new DrmMockCustom(*executionEnvironment.rootDeviceEnvironments[0]);
osTime->updateDrm(drm);
drm->getParamRetValue = 0;
drm->ioctl_res = -1;
auto result = osTime->getDynamicDeviceTimerClock(*defaultHwInfo);
auto expectedResult = static_cast<uint64_t>(1000000000.0 / defaultResolution);
EXPECT_EQ(result, expectedResult);
}
TEST_F(DrmTimeTest, givenGetDynamicDeviceTimerClockWhenIoctlSucceedsThenNonDefaultClockIsReturned) {
auto drm = new DrmMockCustom(*executionEnvironment.rootDeviceEnvironments[0]);
osTime->updateDrm(drm);
uint64_t frequency = 1500;
drm->getParamRetValue = static_cast<int>(frequency);
auto result = osTime->getDynamicDeviceTimerClock(*defaultHwInfo);
EXPECT_EQ(result, frequency);
}
TEST_F(DrmTimeTest, givenGpuTimestampResolutionQueryWhenNoDrmThenDefaultResolutionIsReturned) {
osTime->updateDrm(nullptr);
auto defaultResolution = defaultHwInfo->capabilityTable.defaultProfilingTimerResolution;
auto result = osTime->getDynamicDeviceTimerResolution(*defaultHwInfo);
EXPECT_DOUBLE_EQ(result, defaultResolution);
}
TEST_F(DrmTimeTest, givenGpuTimestampResolutionQueryWhenIoctlSuccedsThenCorrectResolutionIsReturned) {
auto drm = new DrmMockCustom(*executionEnvironment.rootDeviceEnvironments[0]);
osTime->updateDrm(drm);
// 19200000 is frequency yelding 52.083ns resolution
drm->getParamRetValue = 19200000;
drm->ioctl_res = 0;
auto result = osTime->getDynamicDeviceTimerResolution(*defaultHwInfo);
EXPECT_DOUBLE_EQ(result, 52.08333333333333);
}
TEST_F(DrmTimeTest, givenAlwaysFailingResolutionFuncWhenGetHostTimerResolutionIsCalledThenReturnsZero) {
osTime->setResolutionFunc(resolutionFuncFalse);
auto retVal = osTime->getHostTimerResolution();
EXPECT_EQ(0, retVal);
}
TEST_F(DrmTimeTest, givenAlwaysPassingResolutionFuncWhenGetHostTimerResolutionIsCalledThenReturnsNonzero) {
osTime->setResolutionFunc(resolutionFuncTrue);
auto retVal = osTime->getHostTimerResolution();
EXPECT_EQ(5, retVal);
}
TEST_F(DrmTimeTest, givenAlwaysFailingResolutionFuncWhenGetCpuRawTimestampIsCalledThenReturnsZero) {
osTime->setResolutionFunc(resolutionFuncFalse);
auto retVal = osTime->getCpuRawTimestamp();
EXPECT_EQ(0ull, retVal);
}
TEST_F(DrmTimeTest, givenAlwaysFailingGetTimeFuncWhenGetCpuRawTimestampIsCalledThenReturnsZero) {
osTime->setGetTimeFunc(getTimeFuncFalse);
auto retVal = osTime->getCpuRawTimestamp();
EXPECT_EQ(0ull, retVal);
}
TEST_F(DrmTimeTest, givenAlwaysPassingResolutionFuncWhenGetCpuRawTimestampIsCalledThenReturnsNonzero) {
actualTime = 4;
auto retVal = osTime->getCpuRawTimestamp();
EXPECT_EQ(1ull, retVal);
}