@@ -50,7 +50,7 @@ using namespace OCLRT;
5050class DrmCommandStreamFixture {
5151 public:
5252 DeviceCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME> *csr = nullptr ;
53- MemoryManager *mm = nullptr ;
53+ DrmMemoryManager *mm = nullptr ;
5454 DrmMockImpl *mock;
5555 const int mockFd = 33 ;
5656
@@ -62,13 +62,13 @@ class DrmCommandStreamFixture {
6262
6363 this ->mock = new DrmMockImpl (mockFd);
6464
65- csr = new DrmCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME>(*platformDevices[0 ], mock, gemCloseWorkerMode::gemCloseWorkerInactive );
65+ csr = new DrmCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME>(*platformDevices[0 ], mock, gemCloseWorkerMode::gemCloseWorkerActive );
6666 ASSERT_NE (nullptr , csr);
6767
6868 // Memory manager creates pinBB with ioctl, expect one call
6969 EXPECT_CALL (*mock, ioctl (::testing::_, ::testing::_))
7070 .Times (1 );
71- mm = csr->createMemoryManager (false );
71+ mm = static_cast <DrmMemoryManager *>( csr->createMemoryManager (false ) );
7272 ::testing::Mock::VerifyAndClearExpectations (mock);
7373
7474 // assert we have memory manager
@@ -77,6 +77,7 @@ class DrmCommandStreamFixture {
7777
7878 void TearDown () {
7979 mm->waitForDeletions ();
80+ mm->peekGemCloseWorker ()->close (true );
8081 delete csr;
8182 ::testing::Mock::VerifyAndClearExpectations (mock);
8283 // Memory manager closes pinBB with ioctl, expect one call
@@ -199,7 +200,7 @@ TEST_F(DrmCommandStreamTest, Flush) {
199200 .WillRepeatedly (::testing::Return (0 ))
200201 .RetiresOnSaturation ();
201202 EXPECT_CALL (*mock, ioctl (DRM_IOCTL_I915_GEM_WAIT, ::testing::_))
202- .Times (1 )
203+ .Times (2 )
203204 .RetiresOnSaturation ();
204205 EXPECT_CALL (*mock, ioctl (DRM_IOCTL_GEM_CLOSE, ::testing::_))
205206 .Times (1 )
@@ -235,7 +236,7 @@ TEST_F(DrmCommandStreamTest, FlushWithLowPriorityContext) {
235236 .WillRepeatedly (::testing::Return (0 ))
236237 .RetiresOnSaturation ();
237238 EXPECT_CALL (*mock, ioctl (DRM_IOCTL_I915_GEM_WAIT, ::testing::_))
238- .Times (1 )
239+ .Times (2 )
239240 .RetiresOnSaturation ();
240241 EXPECT_CALL (*mock, ioctl (DRM_IOCTL_GEM_CLOSE, ::testing::_))
241242 .Times (1 )
@@ -298,7 +299,7 @@ TEST_F(DrmCommandStreamTest, FlushNotEmptyBB) {
298299 .WillRepeatedly (::testing::Return (0 ))
299300 .RetiresOnSaturation ();
300301 EXPECT_CALL (*mock, ioctl (DRM_IOCTL_I915_GEM_WAIT, ::testing::_))
301- .Times (1 )
302+ .Times (2 )
302303 .RetiresOnSaturation ();
303304 EXPECT_CALL (*mock, ioctl (DRM_IOCTL_GEM_CLOSE, ::testing::_))
304305 .Times (1 )
@@ -327,7 +328,7 @@ TEST_F(DrmCommandStreamTest, FlushNotEmptyNotPaddedBB) {
327328 .WillRepeatedly (::testing::Return (0 ))
328329 .RetiresOnSaturation ();
329330 EXPECT_CALL (*mock, ioctl (DRM_IOCTL_I915_GEM_WAIT, ::testing::_))
330- .Times (1 )
331+ .Times (2 )
331332 .RetiresOnSaturation ();
332333 EXPECT_CALL (*mock, ioctl (DRM_IOCTL_GEM_CLOSE, ::testing::_))
333334 .Times (1 )
@@ -364,7 +365,7 @@ TEST_F(DrmCommandStreamTest, FlushNotAligned) {
364365 EXPECT_CALL (*mock, ioctl (DRM_IOCTL_GEM_CLOSE, ::testing::_))
365366 .Times (1 );
366367 EXPECT_CALL (*mock, ioctl (DRM_IOCTL_I915_GEM_WAIT, ::testing::_))
367- .Times (1 );
368+ .Times (2 );
368369
369370 csr->addBatchBufferEnd (cs, nullptr );
370371 csr->alignToCacheLine (cs);
@@ -447,7 +448,7 @@ TEST_F(DrmCommandStreamTest, CheckDrmFree) {
447448 EXPECT_CALL (*mock, ioctl (DRM_IOCTL_GEM_CLOSE, GemCloseEq (17u )))
448449 .Times (1 );
449450 EXPECT_CALL (*mock, ioctl (DRM_IOCTL_I915_GEM_WAIT, ::testing::_))
450- .Times (1 );
451+ .Times (2 );
451452
452453 DrmAllocation allocation (nullptr , nullptr , 1024 );
453454
@@ -489,7 +490,7 @@ TEST_F(DrmCommandStreamTest, CheckDrmFreeCloseFailed) {
489490 .Times (1 )
490491 .WillOnce (::testing::Return (-1 ));
491492 EXPECT_CALL (*mock, ioctl (DRM_IOCTL_I915_GEM_WAIT, ::testing::_))
492- .Times (1 );
493+ .Times (2 );
493494 DrmAllocation allocation (nullptr , nullptr , 1024 );
494495
495496 csr->makeResident (allocation);
@@ -787,17 +788,11 @@ TEST_F(DrmCommandStreamGemWorkerTests, givenDefaultDrmCSRWhenItIsCreatedThenGemC
787788 EXPECT_EQ (gemCloseWorkerMode::gemCloseWorkerInactive, tCsr->peekGemCloseWorkerOperationMode ());
788789}
789790
790- TEST_F (DrmCommandStreamGemWorkerTests, givenCommandStreamWhenItIsFlushedWithGemCloseWorkerInactiveModeThenCsIsNotNulled) {
791- tCsr->overrideGemCloseWorkerOperationMode (gemCloseWorkerMode::gemCloseWorkerInactive);
792-
791+ TEST_F (DrmCommandStreamGemWorkerTests, givenCommandStreamWhenItIsFlushedWithGemCloseWorkerInDefaultModeThenWorkerDecreasesTheRefCount) {
793792 auto commandBuffer = mm->allocateGraphicsMemory (1024 , 4096 );
794- auto dummyAllocation = mm->allocateGraphicsMemory (1024 , 4096 );
795793 ASSERT_NE (nullptr , commandBuffer);
796- ASSERT_EQ (0u , reinterpret_cast <uintptr_t >(commandBuffer->getUnderlyingBuffer ()) & 0xFFF );
797794 LinearStream cs (commandBuffer);
798795
799- csr->makeResident (*dummyAllocation);
800-
801796 csr->addBatchBufferEnd (cs, nullptr );
802797 csr->alignToCacheLine (cs);
803798 auto storedBase = cs.getCpuBase ();
@@ -813,12 +808,14 @@ TEST_F(DrmCommandStreamGemWorkerTests, givenCommandStreamWhenItIsFlushedWithGemC
813808 // no allocations should be connected
814809 EXPECT_EQ (bo->getResidency ()->size (), 0u );
815810
816- mm->freeGraphicsMemory (dummyAllocation);
811+ // spin until gem close worker finishes execution
812+ while (bo->getRefCount () > 1 )
813+ ;
814+
817815 mm->freeGraphicsMemory (commandBuffer);
818816}
819817
820818TEST_F (DrmCommandStreamGemWorkerTests, givenTaskThatRequiresLargeResourceCountWhenItIsFlushedThenExecStorageIsResized) {
821- tCsr->overrideGemCloseWorkerOperationMode (gemCloseWorkerMode::gemCloseWorkerInactive);
822819 std::vector<GraphicsAllocation *> graphicsAllocations;
823820
824821 auto &execStorage = tCsr->getExecStorage ();
@@ -847,9 +844,6 @@ TEST_F(DrmCommandStreamGemWorkerTests, givenTaskThatRequiresLargeResourceCountWh
847844}
848845
849846TEST_F (DrmCommandStreamGemWorkerTests, givenGemCloseWorkerInactiveModeWhenMakeResidentIsCalledThenRefCountsAreNotUpdated) {
850-
851- tCsr->overrideGemCloseWorkerOperationMode (gemCloseWorkerMode::gemCloseWorkerInactive);
852-
853847 auto dummyAllocation = mm->allocateGraphicsMemory (1024 , 4096 );
854848
855849 auto bo = dummyAllocation->getBO ();
@@ -867,8 +861,6 @@ TEST_F(DrmCommandStreamGemWorkerTests, givenGemCloseWorkerInactiveModeWhenMakeRe
867861}
868862
869863TEST_F (DrmCommandStreamGemWorkerTests, givenCommandStreamWithDuplicatesWhenItIsFlushedWithGemCloseWorkerInactiveModeThenCsIsNotNulled) {
870- tCsr->overrideGemCloseWorkerOperationMode (gemCloseWorkerMode::gemCloseWorkerInactive);
871-
872864 auto commandBuffer = mm->allocateGraphicsMemory (1024 , 4096 );
873865 auto dummyAllocation = mm->allocateGraphicsMemory (1024 , 4096 );
874866 ASSERT_NE (nullptr , commandBuffer);
@@ -917,7 +909,6 @@ class DrmCommandStreamBatchingTests : public Test<DrmCommandStreamEnhancedFixtur
917909};
918910
919911TEST_F (DrmCommandStreamBatchingTests, givenCSRWhenFlushIsCalledThenProperFlagsArePassed) {
920- tCsr->overrideGemCloseWorkerOperationMode (gemCloseWorkerMode::gemCloseWorkerInactive);
921912 auto commandBuffer = mm->allocateGraphicsMemory (1024 , 4096 );
922913 auto dummyAllocation = mm->allocateGraphicsMemory (1024 , 4096 );
923914 ASSERT_NE (nullptr , commandBuffer);
@@ -944,7 +935,6 @@ TEST_F(DrmCommandStreamBatchingTests, givenCSRWhenFlushIsCalledThenProperFlagsAr
944935
945936TEST_F (DrmCommandStreamBatchingTests, givenCsrWhenDispatchPolicyIsSetToBatchingThenCommandBufferIsNotSubmitted) {
946937 tCsr->overrideDispatchPolicy (DispatchMode::BatchedDispatch);
947- tCsr->overrideGemCloseWorkerOperationMode (gemCloseWorkerMode::gemCloseWorkerInactive);
948938
949939 auto mockedSubmissionsAggregator = new mockSubmissionsAggregator ();
950940 tCsr->overrideSubmissionAggregator (mockedSubmissionsAggregator);
@@ -1005,7 +995,6 @@ TEST_F(DrmCommandStreamBatchingTests, givenCsrWhenDispatchPolicyIsSetToBatchingT
1005995
1006996TEST_F (DrmCommandStreamBatchingTests, givenRecordedCommandBufferWhenItIsSubmittedThenFlushTaskIsProperlyCalled) {
1007997 tCsr->overrideDispatchPolicy (DispatchMode::BatchedDispatch);
1008- tCsr->overrideGemCloseWorkerOperationMode (gemCloseWorkerMode::gemCloseWorkerInactive);
1009998
1010999 auto mockedSubmissionsAggregator = new mockSubmissionsAggregator ();
10111000 tCsr->overrideSubmissionAggregator (mockedSubmissionsAggregator);
0 commit comments