@@ -50,7 +50,7 @@ using namespace OCLRT;
50
50
class DrmCommandStreamFixture {
51
51
public:
52
52
DeviceCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME> *csr = nullptr ;
53
- MemoryManager *mm = nullptr ;
53
+ DrmMemoryManager *mm = nullptr ;
54
54
DrmMockImpl *mock;
55
55
const int mockFd = 33 ;
56
56
@@ -62,13 +62,13 @@ class DrmCommandStreamFixture {
62
62
63
63
this ->mock = new DrmMockImpl (mockFd);
64
64
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 );
66
66
ASSERT_NE (nullptr , csr);
67
67
68
68
// Memory manager creates pinBB with ioctl, expect one call
69
69
EXPECT_CALL (*mock, ioctl (::testing::_, ::testing::_))
70
70
.Times (1 );
71
- mm = csr->createMemoryManager (false );
71
+ mm = static_cast <DrmMemoryManager *>( csr->createMemoryManager (false ) );
72
72
::testing::Mock::VerifyAndClearExpectations (mock);
73
73
74
74
// assert we have memory manager
@@ -77,6 +77,7 @@ class DrmCommandStreamFixture {
77
77
78
78
void TearDown () {
79
79
mm->waitForDeletions ();
80
+ mm->peekGemCloseWorker ()->close (true );
80
81
delete csr;
81
82
::testing::Mock::VerifyAndClearExpectations (mock);
82
83
// Memory manager closes pinBB with ioctl, expect one call
@@ -199,7 +200,7 @@ TEST_F(DrmCommandStreamTest, Flush) {
199
200
.WillRepeatedly (::testing::Return (0 ))
200
201
.RetiresOnSaturation ();
201
202
EXPECT_CALL (*mock, ioctl (DRM_IOCTL_I915_GEM_WAIT, ::testing::_))
202
- .Times (1 )
203
+ .Times (2 )
203
204
.RetiresOnSaturation ();
204
205
EXPECT_CALL (*mock, ioctl (DRM_IOCTL_GEM_CLOSE, ::testing::_))
205
206
.Times (1 )
@@ -235,7 +236,7 @@ TEST_F(DrmCommandStreamTest, FlushWithLowPriorityContext) {
235
236
.WillRepeatedly (::testing::Return (0 ))
236
237
.RetiresOnSaturation ();
237
238
EXPECT_CALL (*mock, ioctl (DRM_IOCTL_I915_GEM_WAIT, ::testing::_))
238
- .Times (1 )
239
+ .Times (2 )
239
240
.RetiresOnSaturation ();
240
241
EXPECT_CALL (*mock, ioctl (DRM_IOCTL_GEM_CLOSE, ::testing::_))
241
242
.Times (1 )
@@ -298,7 +299,7 @@ TEST_F(DrmCommandStreamTest, FlushNotEmptyBB) {
298
299
.WillRepeatedly (::testing::Return (0 ))
299
300
.RetiresOnSaturation ();
300
301
EXPECT_CALL (*mock, ioctl (DRM_IOCTL_I915_GEM_WAIT, ::testing::_))
301
- .Times (1 )
302
+ .Times (2 )
302
303
.RetiresOnSaturation ();
303
304
EXPECT_CALL (*mock, ioctl (DRM_IOCTL_GEM_CLOSE, ::testing::_))
304
305
.Times (1 )
@@ -327,7 +328,7 @@ TEST_F(DrmCommandStreamTest, FlushNotEmptyNotPaddedBB) {
327
328
.WillRepeatedly (::testing::Return (0 ))
328
329
.RetiresOnSaturation ();
329
330
EXPECT_CALL (*mock, ioctl (DRM_IOCTL_I915_GEM_WAIT, ::testing::_))
330
- .Times (1 )
331
+ .Times (2 )
331
332
.RetiresOnSaturation ();
332
333
EXPECT_CALL (*mock, ioctl (DRM_IOCTL_GEM_CLOSE, ::testing::_))
333
334
.Times (1 )
@@ -364,7 +365,7 @@ TEST_F(DrmCommandStreamTest, FlushNotAligned) {
364
365
EXPECT_CALL (*mock, ioctl (DRM_IOCTL_GEM_CLOSE, ::testing::_))
365
366
.Times (1 );
366
367
EXPECT_CALL (*mock, ioctl (DRM_IOCTL_I915_GEM_WAIT, ::testing::_))
367
- .Times (1 );
368
+ .Times (2 );
368
369
369
370
csr->addBatchBufferEnd (cs, nullptr );
370
371
csr->alignToCacheLine (cs);
@@ -447,7 +448,7 @@ TEST_F(DrmCommandStreamTest, CheckDrmFree) {
447
448
EXPECT_CALL (*mock, ioctl (DRM_IOCTL_GEM_CLOSE, GemCloseEq (17u )))
448
449
.Times (1 );
449
450
EXPECT_CALL (*mock, ioctl (DRM_IOCTL_I915_GEM_WAIT, ::testing::_))
450
- .Times (1 );
451
+ .Times (2 );
451
452
452
453
DrmAllocation allocation (nullptr , nullptr , 1024 );
453
454
@@ -489,7 +490,7 @@ TEST_F(DrmCommandStreamTest, CheckDrmFreeCloseFailed) {
489
490
.Times (1 )
490
491
.WillOnce (::testing::Return (-1 ));
491
492
EXPECT_CALL (*mock, ioctl (DRM_IOCTL_I915_GEM_WAIT, ::testing::_))
492
- .Times (1 );
493
+ .Times (2 );
493
494
DrmAllocation allocation (nullptr , nullptr , 1024 );
494
495
495
496
csr->makeResident (allocation);
@@ -787,17 +788,11 @@ TEST_F(DrmCommandStreamGemWorkerTests, givenDefaultDrmCSRWhenItIsCreatedThenGemC
787
788
EXPECT_EQ (gemCloseWorkerMode::gemCloseWorkerInactive, tCsr->peekGemCloseWorkerOperationMode ());
788
789
}
789
790
790
- TEST_F (DrmCommandStreamGemWorkerTests, givenCommandStreamWhenItIsFlushedWithGemCloseWorkerInactiveModeThenCsIsNotNulled) {
791
- tCsr->overrideGemCloseWorkerOperationMode (gemCloseWorkerMode::gemCloseWorkerInactive);
792
-
791
+ TEST_F (DrmCommandStreamGemWorkerTests, givenCommandStreamWhenItIsFlushedWithGemCloseWorkerInDefaultModeThenWorkerDecreasesTheRefCount) {
793
792
auto commandBuffer = mm->allocateGraphicsMemory (1024 , 4096 );
794
- auto dummyAllocation = mm->allocateGraphicsMemory (1024 , 4096 );
795
793
ASSERT_NE (nullptr , commandBuffer);
796
- ASSERT_EQ (0u , reinterpret_cast <uintptr_t >(commandBuffer->getUnderlyingBuffer ()) & 0xFFF );
797
794
LinearStream cs (commandBuffer);
798
795
799
- csr->makeResident (*dummyAllocation);
800
-
801
796
csr->addBatchBufferEnd (cs, nullptr );
802
797
csr->alignToCacheLine (cs);
803
798
auto storedBase = cs.getCpuBase ();
@@ -813,12 +808,14 @@ TEST_F(DrmCommandStreamGemWorkerTests, givenCommandStreamWhenItIsFlushedWithGemC
813
808
// no allocations should be connected
814
809
EXPECT_EQ (bo->getResidency ()->size (), 0u );
815
810
816
- mm->freeGraphicsMemory (dummyAllocation);
811
+ // spin until gem close worker finishes execution
812
+ while (bo->getRefCount () > 1 )
813
+ ;
814
+
817
815
mm->freeGraphicsMemory (commandBuffer);
818
816
}
819
817
820
818
TEST_F (DrmCommandStreamGemWorkerTests, givenTaskThatRequiresLargeResourceCountWhenItIsFlushedThenExecStorageIsResized) {
821
- tCsr->overrideGemCloseWorkerOperationMode (gemCloseWorkerMode::gemCloseWorkerInactive);
822
819
std::vector<GraphicsAllocation *> graphicsAllocations;
823
820
824
821
auto &execStorage = tCsr->getExecStorage ();
@@ -847,9 +844,6 @@ TEST_F(DrmCommandStreamGemWorkerTests, givenTaskThatRequiresLargeResourceCountWh
847
844
}
848
845
849
846
TEST_F (DrmCommandStreamGemWorkerTests, givenGemCloseWorkerInactiveModeWhenMakeResidentIsCalledThenRefCountsAreNotUpdated) {
850
-
851
- tCsr->overrideGemCloseWorkerOperationMode (gemCloseWorkerMode::gemCloseWorkerInactive);
852
-
853
847
auto dummyAllocation = mm->allocateGraphicsMemory (1024 , 4096 );
854
848
855
849
auto bo = dummyAllocation->getBO ();
@@ -867,8 +861,6 @@ TEST_F(DrmCommandStreamGemWorkerTests, givenGemCloseWorkerInactiveModeWhenMakeRe
867
861
}
868
862
869
863
TEST_F (DrmCommandStreamGemWorkerTests, givenCommandStreamWithDuplicatesWhenItIsFlushedWithGemCloseWorkerInactiveModeThenCsIsNotNulled) {
870
- tCsr->overrideGemCloseWorkerOperationMode (gemCloseWorkerMode::gemCloseWorkerInactive);
871
-
872
864
auto commandBuffer = mm->allocateGraphicsMemory (1024 , 4096 );
873
865
auto dummyAllocation = mm->allocateGraphicsMemory (1024 , 4096 );
874
866
ASSERT_NE (nullptr , commandBuffer);
@@ -917,7 +909,6 @@ class DrmCommandStreamBatchingTests : public Test<DrmCommandStreamEnhancedFixtur
917
909
};
918
910
919
911
TEST_F (DrmCommandStreamBatchingTests, givenCSRWhenFlushIsCalledThenProperFlagsArePassed) {
920
- tCsr->overrideGemCloseWorkerOperationMode (gemCloseWorkerMode::gemCloseWorkerInactive);
921
912
auto commandBuffer = mm->allocateGraphicsMemory (1024 , 4096 );
922
913
auto dummyAllocation = mm->allocateGraphicsMemory (1024 , 4096 );
923
914
ASSERT_NE (nullptr , commandBuffer);
@@ -944,7 +935,6 @@ TEST_F(DrmCommandStreamBatchingTests, givenCSRWhenFlushIsCalledThenProperFlagsAr
944
935
945
936
TEST_F (DrmCommandStreamBatchingTests, givenCsrWhenDispatchPolicyIsSetToBatchingThenCommandBufferIsNotSubmitted) {
946
937
tCsr->overrideDispatchPolicy (DispatchMode::BatchedDispatch);
947
- tCsr->overrideGemCloseWorkerOperationMode (gemCloseWorkerMode::gemCloseWorkerInactive);
948
938
949
939
auto mockedSubmissionsAggregator = new mockSubmissionsAggregator ();
950
940
tCsr->overrideSubmissionAggregator (mockedSubmissionsAggregator);
@@ -1005,7 +995,6 @@ TEST_F(DrmCommandStreamBatchingTests, givenCsrWhenDispatchPolicyIsSetToBatchingT
1005
995
1006
996
TEST_F (DrmCommandStreamBatchingTests, givenRecordedCommandBufferWhenItIsSubmittedThenFlushTaskIsProperlyCalled) {
1007
997
tCsr->overrideDispatchPolicy (DispatchMode::BatchedDispatch);
1008
- tCsr->overrideGemCloseWorkerOperationMode (gemCloseWorkerMode::gemCloseWorkerInactive);
1009
998
1010
999
auto mockedSubmissionsAggregator = new mockSubmissionsAggregator ();
1011
1000
tCsr->overrideSubmissionAggregator (mockedSubmissionsAggregator);
0 commit comments