@@ -133,7 +133,7 @@ TEST_F(DrmBufferObjectTest, givenAddressThatWhenSizeIsAddedWithin32BitBoundaryWh
133133 EXPECT_TRUE (execObject.flags & EXEC_OBJECT_SUPPORTS_48B_ADDRESS);
134134}
135135
136- TEST_F (DrmBufferObjectTest, onPinIoctlFailed ) {
136+ TEST_F (DrmBufferObjectTest, whenExecFailsThenPinFails ) {
137137 std::unique_ptr<uint32_t []> buff (new uint32_t [1024 ]);
138138
139139 mock->ioctl_expected .total = 1 ;
@@ -145,7 +145,23 @@ TEST_F(DrmBufferObjectTest, onPinIoctlFailed) {
145145
146146 bo->setAddress (reinterpret_cast <uint64_t >(buff.get ()));
147147 BufferObject *boArray[1 ] = {boToPin.get ()};
148- auto ret = bo->pin (boArray, 1 , osContext.get (), 0 , 1 , true );
148+ auto ret = bo->pin (boArray, 1 , osContext.get (), 0 , 1 );
149+ EXPECT_EQ (EINVAL, ret);
150+ }
151+
152+ TEST_F (DrmBufferObjectTest, whenExecFailsThenValidateHostPtrFails) {
153+ std::unique_ptr<uint32_t []> buff (new uint32_t [1024 ]);
154+
155+ mock->ioctl_expected .total = 1 ;
156+ mock->ioctl_res = -1 ;
157+ this ->mock ->errnoValue = EINVAL;
158+
159+ std::unique_ptr<BufferObject> boToPin (new TestedBufferObject (this ->mock .get ()));
160+ ASSERT_NE (nullptr , boToPin.get ());
161+
162+ bo->setAddress (reinterpret_cast <uint64_t >(buff.get ()));
163+ BufferObject *boArray[1 ] = {boToPin.get ()};
164+ auto ret = bo->validateHostPtr (boArray, 1 , osContext.get (), 0 , 1 );
149165 EXPECT_EQ (EINVAL, ret);
150166}
151167
@@ -161,7 +177,7 @@ TEST_F(DrmBufferObjectTest, givenResidentBOWhenPrintExecutionBufferIsSetToTrueTh
161177 BufferObject *boArray[1 ] = {bo.get ()};
162178
163179 testing::internal::CaptureStdout ();
164- auto ret = bo->pin (boArray, 1 , osContext.get (), 0 , 1 , true );
180+ auto ret = bo->pin (boArray, 1 , osContext.get (), 0 , 1 );
165181 EXPECT_EQ (0 , ret);
166182
167183 std::string output = testing::internal::GetCapturedStdout ();
@@ -207,6 +223,29 @@ TEST_F(DrmBufferObjectTest, whenPrintExecutionBufferIsSetToTrueThenMessageFoundI
207223 EXPECT_EQ (expectedValue, idx);
208224}
209225
226+ TEST (DrmBufferObjectSimpleTest, givenInvalidBoWhenValidateHostptrIsCalledThenErrorIsReturned) {
227+ std::unique_ptr<uint32_t []> buff (new uint32_t [256 ]);
228+ std::unique_ptr<DrmMockCustom> mock (new DrmMockCustom);
229+ OsContextLinux osContext (*mock, 0u , 1 , aub_stream::ENGINE_RCS, PreemptionMode::Disabled, false , false , false );
230+ ASSERT_NE (nullptr , mock.get ());
231+ std::unique_ptr<TestedBufferObject> bo (new TestedBufferObject (mock.get ()));
232+ ASSERT_NE (nullptr , bo.get ());
233+
234+ // fail DRM_IOCTL_I915_GEM_EXECBUFFER2 in pin
235+ mock->ioctl_res = -1 ;
236+
237+ std::unique_ptr<BufferObject> boToPin (new TestedBufferObject (mock.get ()));
238+ ASSERT_NE (nullptr , boToPin.get ());
239+
240+ bo->setAddress (reinterpret_cast <uint64_t >(buff.get ()));
241+ mock->errnoValue = EFAULT;
242+
243+ BufferObject *boArray[1 ] = {boToPin.get ()};
244+ auto ret = bo->pin (boArray, 1 , &osContext, 0 , 1 );
245+ EXPECT_EQ (EFAULT, ret);
246+ mock->ioctl_res = 0 ;
247+ }
248+
210249TEST (DrmBufferObjectSimpleTest, givenInvalidBoWhenPinIsCalledThenErrorIsReturned) {
211250 std::unique_ptr<uint32_t []> buff (new uint32_t [256 ]);
212251 std::unique_ptr<DrmMockCustom> mock (new DrmMockCustom);
@@ -225,7 +264,7 @@ TEST(DrmBufferObjectSimpleTest, givenInvalidBoWhenPinIsCalledThenErrorIsReturned
225264 mock->errnoValue = EFAULT;
226265
227266 BufferObject *boArray[1 ] = {boToPin.get ()};
228- auto ret = bo->pin (boArray, 1 , &osContext, 0 , 1 , true );
267+ auto ret = bo->validateHostPtr (boArray, 1 , &osContext, 0 , 1 );
229268 EXPECT_EQ (EFAULT, ret);
230269 mock->ioctl_res = 0 ;
231270}
@@ -258,7 +297,40 @@ TEST(DrmBufferObjectSimpleTest, givenArrayOfBosWhenPinnedThenAllBosArePinned) {
258297 BufferObject *array[3 ] = {boToPin.get (), boToPin2.get (), boToPin3.get ()};
259298
260299 bo->setAddress (reinterpret_cast <uint64_t >(buff.get ()));
261- auto ret = bo->pin (array, 3 , &osContext, 0 , 1 , true );
300+ auto ret = bo->pin (array, 3 , &osContext, 0 , 1 );
301+ EXPECT_EQ (mock->ioctl_res , ret);
302+
303+ EXPECT_LT (0u , mock->execBuffer .batch_len );
304+ EXPECT_EQ (4u , mock->execBuffer .buffer_count ); // 3 bos to pin plus 1 exec bo
305+ EXPECT_EQ (reinterpret_cast <uintptr_t >(boToPin->execObjectPointerFilled ), mock->execBuffer .buffers_ptr );
306+ EXPECT_NE (nullptr , boToPin2->execObjectPointerFilled );
307+ EXPECT_NE (nullptr , boToPin3->execObjectPointerFilled );
308+
309+ bo->setAddress (0llu);
310+ }
311+
312+ TEST (DrmBufferObjectSimpleTest, givenArrayOfBosWhenValidatedThenAllBosArePinned) {
313+ std::unique_ptr<uint32_t []> buff (new uint32_t [256 ]);
314+ std::unique_ptr<DrmMockCustom> mock (new DrmMockCustom);
315+ ASSERT_NE (nullptr , mock.get ());
316+ OsContextLinux osContext (*mock, 0u , 1 , aub_stream::ENGINE_RCS, PreemptionMode::Disabled, false , false , false );
317+
318+ std::unique_ptr<TestedBufferObject> bo (new TestedBufferObject (mock.get ()));
319+ ASSERT_NE (nullptr , bo.get ());
320+ mock->ioctl_res = 0 ;
321+
322+ std::unique_ptr<TestedBufferObject> boToPin (new TestedBufferObject (mock.get ()));
323+ std::unique_ptr<TestedBufferObject> boToPin2 (new TestedBufferObject (mock.get ()));
324+ std::unique_ptr<TestedBufferObject> boToPin3 (new TestedBufferObject (mock.get ()));
325+
326+ ASSERT_NE (nullptr , boToPin.get ());
327+ ASSERT_NE (nullptr , boToPin2.get ());
328+ ASSERT_NE (nullptr , boToPin3.get ());
329+
330+ BufferObject *array[3 ] = {boToPin.get (), boToPin2.get (), boToPin3.get ()};
331+
332+ bo->setAddress (reinterpret_cast <uint64_t >(buff.get ()));
333+ auto ret = bo->validateHostPtr (array, 3 , &osContext, 0 , 1 );
262334 EXPECT_EQ (mock->ioctl_res , ret);
263335
264336 EXPECT_LT (0u , mock->execBuffer .batch_len );
0 commit comments