mirror of
https://github.com/intel/compute-runtime.git
synced 2025-11-10 05:49:51 +08:00
Split buffer object validation and early pinning
Change-Id: If1b136807dc8593179ce743c8e0187ee80c3e95f Signed-off-by: Lukasz Jobczyk <lukasz.jobczyk@intel.com>
This commit is contained in:
@@ -133,7 +133,7 @@ TEST_F(DrmBufferObjectTest, givenAddressThatWhenSizeIsAddedWithin32BitBoundaryWh
|
||||
EXPECT_TRUE(execObject.flags & EXEC_OBJECT_SUPPORTS_48B_ADDRESS);
|
||||
}
|
||||
|
||||
TEST_F(DrmBufferObjectTest, onPinIoctlFailed) {
|
||||
TEST_F(DrmBufferObjectTest, whenExecFailsThenPinFails) {
|
||||
std::unique_ptr<uint32_t[]> buff(new uint32_t[1024]);
|
||||
|
||||
mock->ioctl_expected.total = 1;
|
||||
@@ -145,7 +145,23 @@ TEST_F(DrmBufferObjectTest, onPinIoctlFailed) {
|
||||
|
||||
bo->setAddress(reinterpret_cast<uint64_t>(buff.get()));
|
||||
BufferObject *boArray[1] = {boToPin.get()};
|
||||
auto ret = bo->pin(boArray, 1, osContext.get(), 0, 1, true);
|
||||
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 = 1;
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -161,7 +177,7 @@ TEST_F(DrmBufferObjectTest, givenResidentBOWhenPrintExecutionBufferIsSetToTrueTh
|
||||
BufferObject *boArray[1] = {bo.get()};
|
||||
|
||||
testing::internal::CaptureStdout();
|
||||
auto ret = bo->pin(boArray, 1, osContext.get(), 0, 1, true);
|
||||
auto ret = bo->pin(boArray, 1, osContext.get(), 0, 1);
|
||||
EXPECT_EQ(0, ret);
|
||||
|
||||
std::string output = testing::internal::GetCapturedStdout();
|
||||
@@ -207,6 +223,29 @@ TEST_F(DrmBufferObjectTest, whenPrintExecutionBufferIsSetToTrueThenMessageFoundI
|
||||
EXPECT_EQ(expectedValue, idx);
|
||||
}
|
||||
|
||||
TEST(DrmBufferObjectSimpleTest, givenInvalidBoWhenValidateHostptrIsCalledThenErrorIsReturned) {
|
||||
std::unique_ptr<uint32_t[]> buff(new uint32_t[256]);
|
||||
std::unique_ptr<DrmMockCustom> mock(new DrmMockCustom);
|
||||
OsContextLinux osContext(*mock, 0u, 1, aub_stream::ENGINE_RCS, PreemptionMode::Disabled, false, false, false);
|
||||
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]);
|
||||
std::unique_ptr<DrmMockCustom> mock(new DrmMockCustom);
|
||||
@@ -225,7 +264,7 @@ TEST(DrmBufferObjectSimpleTest, givenInvalidBoWhenPinIsCalledThenErrorIsReturned
|
||||
mock->errnoValue = EFAULT;
|
||||
|
||||
BufferObject *boArray[1] = {boToPin.get()};
|
||||
auto ret = bo->pin(boArray, 1, &osContext, 0, 1, true);
|
||||
auto ret = bo->validateHostPtr(boArray, 1, &osContext, 0, 1);
|
||||
EXPECT_EQ(EFAULT, ret);
|
||||
mock->ioctl_res = 0;
|
||||
}
|
||||
@@ -258,7 +297,40 @@ TEST(DrmBufferObjectSimpleTest, givenArrayOfBosWhenPinnedThenAllBosArePinned) {
|
||||
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, true);
|
||||
auto ret = bo->pin(array, 3, &osContext, 0, 1);
|
||||
EXPECT_EQ(mock->ioctl_res, ret);
|
||||
|
||||
EXPECT_LT(0u, mock->execBuffer.batch_len);
|
||||
EXPECT_EQ(4u, mock->execBuffer.buffer_count); // 3 bos to pin plus 1 exec bo
|
||||
EXPECT_EQ(reinterpret_cast<uintptr_t>(boToPin->execObjectPointerFilled), mock->execBuffer.buffers_ptr);
|
||||
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]);
|
||||
std::unique_ptr<DrmMockCustom> mock(new DrmMockCustom);
|
||||
ASSERT_NE(nullptr, mock.get());
|
||||
OsContextLinux osContext(*mock, 0u, 1, aub_stream::ENGINE_RCS, PreemptionMode::Disabled, false, false, false);
|
||||
|
||||
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.batch_len);
|
||||
|
||||
@@ -3118,7 +3118,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDisabledForcePinAndEna
|
||||
PinBufferObject(Drm *drm) : BufferObject(drm, 1, 0, 1) {
|
||||
}
|
||||
|
||||
int pin(BufferObject *const boToPin[], size_t numberOfBos, OsContext *osContext, uint32_t vmHandleId, uint32_t drmContextId, bool validateHostptr) override {
|
||||
int validateHostPtr(BufferObject *const boToPin[], size_t numberOfBos, OsContext *osContext, uint32_t vmHandleId, uint32_t drmContextId) override {
|
||||
for (size_t i = 0; i < numberOfBos; i++) {
|
||||
pinnedBoArray[i] = boToPin[i];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user