feature: set error description in os_interface/linux

Added setErrorDescription for drm_buffer_object, drm_memory_manager,
and ioctl_helper_prelim

Related-To: NEO-12456

Signed-off-by: Chandio, Bibrak Qamar <bibrak.qamar.chandio@intel.com>
This commit is contained in:
Chandio, Bibrak Qamar
2024-08-29 22:35:24 +00:00
committed by Compute-Runtime-Automation
parent 05250e7460
commit 27c7fbc611
7 changed files with 188 additions and 11 deletions

View File

@@ -102,6 +102,40 @@ TEST_F(DrmDebugPrelimTest, GivenDrmWhenRegisteringResourceWithoutDataThenRegiste
EXPECT_EQ(ioctlHelper->classHandles[static_cast<uint32_t>(DrmResourceClass::isa)], receivedUuid->uuidClass);
}
TEST_F(DrmDebugPrelimTest, GivenDrmWhenRegisteringResourceWithoutDataThenRegisterUUIDIoctlReturnsWithError) {
DrmQueryMock drm(*executionEnvironment->rootDeviceEnvironments[0]);
auto ioctlHelper = std::make_unique<MockIoctlHelperPrelimResourceRegistration>(drm);
const auto result = ioctlHelper->registerResourceClasses();
EXPECT_TRUE(result);
const auto handle = drm.context.uuidHandle;
// To induce the error at IoctlHelperPrelim20::registerUuid()
drm.context.uuidControlReturn = -2;
auto registeredHandle = ioctlHelper->registerResource(DrmResourceClass::isa, nullptr, 0);
const char *systemErrorDescription = nullptr;
executionEnvironment->getErrorDescription(&systemErrorDescription);
char expectedErrorDescription[256];
snprintf(expectedErrorDescription, 256, "ioctl(PRELIM_DRM_IOCTL_I915_UUID_REGISTER) failed with %d. errno=%d(%s)\n", drm.context.uuidControlReturn, drm.getErrno(), strerror(drm.getErrno()));
EXPECT_STREQ(expectedErrorDescription, systemErrorDescription);
EXPECT_EQ(handle + 1, drm.context.uuidHandle);
EXPECT_EQ(handle, registeredHandle);
const auto &receivedUuid = drm.context.receivedRegisterUuid;
ASSERT_TRUE(receivedUuid);
EXPECT_EQ(nullptr, receivedUuid->ptr);
EXPECT_EQ(0u, receivedUuid->size);
EXPECT_TRUE(hasSubstr(std::string(receivedUuid->uuid), std::string("00000000-0000-0000")));
EXPECT_EQ(ioctlHelper->classHandles[static_cast<uint32_t>(DrmResourceClass::isa)], receivedUuid->uuidClass);
}
TEST_F(DrmDebugPrelimTest, GivenDrmWhenRegisteringResourceWithDataThenRegisterUUIDIoctlIsCalledWithCorrectData) {
DrmQueryMock drm(*executionEnvironment->rootDeviceEnvironments[0]);
auto ioctlHelper = std::make_unique<MockIoctlHelperPrelimResourceRegistration>(drm);
@@ -150,6 +184,39 @@ TEST_F(DrmDebugPrelimTest, GivenDrmWhenUnregisteringResourceThenUnregisterUUIDIo
EXPECT_EQ(0u, receivedUuid->extensions);
}
TEST_F(DrmDebugPrelimTest, GivenDrmWhenUnregisteringResourceThenUnregisterUUIDIoctlReturnsWithError) {
DrmQueryMock drm(*executionEnvironment->rootDeviceEnvironments[0]);
auto result = drm.registerResourceClasses();
EXPECT_TRUE(result);
uint64_t data = 0x12345678;
auto registeredHandle = drm.registerResource(DrmResourceClass::isa, &data, sizeof(uint64_t));
// To induce the error at IoctlHelperPrelim20::registerUuid()
drm.context.uuidControlReturn = -2;
drm.unregisterResource(registeredHandle);
const char *systemErrorDescription = nullptr;
executionEnvironment->getErrorDescription(&systemErrorDescription);
char expectedErrorDescription[256];
snprintf(expectedErrorDescription, 256, "ioctl(PRELIM_DRM_IOCTL_I915_UUID_UNREGISTER) failed with %d. errno=%d(%s)\n", drm.context.uuidControlReturn, drm.getErrno(), strerror(drm.getErrno()));
EXPECT_STREQ(expectedErrorDescription, systemErrorDescription);
const auto &receivedUuid = drm.context.receivedUnregisterUuid;
ASSERT_TRUE(receivedUuid);
EXPECT_EQ(registeredHandle, receivedUuid->handle);
EXPECT_EQ(nullptr, receivedUuid->ptr);
EXPECT_EQ(0u, receivedUuid->size);
EXPECT_EQ(0u, receivedUuid->uuidClass);
EXPECT_EQ(0u, receivedUuid->flags);
EXPECT_EQ(0u, receivedUuid->extensions);
}
TEST_F(DrmDebugPrelimTest, GivenDrmWhenNotifyFirstCommandQueueCreatedCalledThenCorrectUuidIsRegisteredWithCorrectData) {
DrmQueryMock drm(*executionEnvironment->rootDeviceEnvironments[0]);
@@ -187,6 +254,31 @@ TEST_F(DrmDebugPrelimTest, GivenDrmWhenRegisteringIsaCookieThenRegisterUUIDIoctl
EXPECT_EQ(3u, drm.context.receivedRegisterUuid->uuidClass);
}
TEST_F(DrmDebugPrelimTest, GivenDrmWhenRegisteringIsaCookieThenRegisterUUIDIoctlReturnsError) {
DrmQueryMock drm(*executionEnvironment->rootDeviceEnvironments[0]);
auto result = drm.registerResourceClasses();
EXPECT_TRUE(result);
// To induce the error at IoctlHelperPrelim20::registerUuid()
drm.context.uuidControlReturn = -2;
auto prevIoctls = drm.ioctlCallsCount;
auto registeredHandle = drm.registerIsaCookie(3);
const char *systemErrorDescription = nullptr;
executionEnvironment->getErrorDescription(&systemErrorDescription);
char expectedErrorDescription[256];
snprintf(expectedErrorDescription, 256, "ioctl(PRELIM_DRM_IOCTL_I915_UUID_REGISTER) failed with %d. errno=%d(%s)\n", drm.context.uuidControlReturn, drm.getErrno(), strerror(drm.getErrno()));
EXPECT_STREQ(expectedErrorDescription, systemErrorDescription);
EXPECT_EQ(prevIoctls + 1u, drm.ioctlCallsCount);
EXPECT_EQ(drm.context.uuidHandle - 1, registeredHandle);
EXPECT_EQ(3u, drm.context.receivedRegisterUuid->uuidClass);
}
TEST_F(DrmDebugPrelimTest, GivenDrmWhenRegisteringElfResourceWithoutDataThenRegisterUUIDIoctlIsCalled) {
DrmQueryMock drm(*executionEnvironment->rootDeviceEnvironments[0]);

View File

@@ -250,6 +250,15 @@ TEST_F(DrmMemoryManagerUsmSharedHandlePrelimTest, givenMultiRootDeviceEnvironmen
AllocationProperties properties(rootDeviceIndex, true, size, AllocationType::bufferHostMemory, false, {});
auto ptr = memoryManager->createUSMHostAllocationFromSharedHandle(1, properties, nullptr, true);
const char *systemErrorDescription = nullptr;
executionEnvironment->getErrorDescription(&systemErrorDescription);
char expectedErrorDescription[256];
snprintf(expectedErrorDescription, 256, "ioctl(PRIME_FD_TO_HANDLE) failed with %d. errno=%d(%s)\n", mock->fdToHandleRetVal, mock->getErrno(), strerror(mock->getErrno()));
EXPECT_FALSE(strncmp(expectedErrorDescription, systemErrorDescription, 256));
EXPECT_EQ(ptr, nullptr);
executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(osInterface);

View File

@@ -280,6 +280,14 @@ TEST_F(DrmMemoryManagerUsmSharedHandleTest, givenMultiRootDeviceEnvironmentAndMe
auto ptr = memoryManager->createUSMHostAllocationFromSharedHandle(1, properties, nullptr, true);
const char *systemErrorDescription = nullptr;
executionEnvironment->getErrorDescription(&systemErrorDescription);
char expectedErrorDescription[256];
snprintf(expectedErrorDescription, 256, "ioctl(PRIME_FD_TO_HANDLE) failed with %d. errno=%d(%s)\n", mock->fdToHandleRetVal, mock->getErrno(), strerror(mock->getErrno()));
EXPECT_FALSE(strncmp(expectedErrorDescription, systemErrorDescription, 256));
EXPECT_EQ(ptr, nullptr);
executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(osInterface);

View File

@@ -7385,6 +7385,28 @@ TEST_F(DrmMemoryManagerWithLocalMemoryTest, givenDrmWhenRetrieveMmapOffsetForBuf
EXPECT_FALSE(ret);
}
TEST_F(DrmMemoryManagerWithLocalMemoryTest, givenDrmWhenRetrieveMmapOffsetForBufferObjectFailsThenReturnFalseTestErrorDescription) {
mock->ioctlExpected.gemMmapOffset = 2;
BufferObject bo(rootDeviceIndex, mock, 3, 1, 1024, 0);
mock->failOnMmapOffset = true;
// To set the error value used to create the debug string in retrieveMmapOffsetForBufferObject()
mock->errnoValue = -2;
uint64_t offset = 0;
auto ret = memoryManager->retrieveMmapOffsetForBufferObject(rootDeviceIndex, bo, 0, offset);
const char *systemErrorDescription = nullptr;
executionEnvironment->getErrorDescription(&systemErrorDescription);
char expectedErrorDescription[256];
snprintf(expectedErrorDescription, 256, "ioctl(DRM_IOCTL_I915_GEM_MMAP_OFFSET) failed with %d. errno=%d(%s)\n", -1, mock->getErrno(), strerror(mock->getErrno()));
EXPECT_STREQ(expectedErrorDescription, systemErrorDescription);
EXPECT_FALSE(ret);
}
TEST_F(DrmMemoryManagerWithLocalMemoryTest, givenDrmWhenRetrieveMmapOffsetForBufferObjectIsCalledForLocalMemoryThenApplyCorrectFlags) {
mock->ioctlExpected.gemMmapOffset = 5;
BufferObject bo(rootDeviceIndex, mock, 3, 1, 1024, 0);