1414#include " test.h"
1515#include " unit_tests/mocks/mock_gmm.h"
1616
17+ #include < memory>
18+
1719extern GFXCORE_FAMILY renderCoreFamily;
1820
1921using namespace OCLRT ;
@@ -95,7 +97,7 @@ HWTEST_P(AUBCreateImageArray, CheckArrayImages) {
9597 auto pixelSize = 4 ;
9698 auto storageSize = imageDesc.image_array_size * pixelSize * imageDesc.image_width * imageDesc.image_height ;
9799
98- int * hostPtr = new int [storageSize];
100+ std::unique_ptr< int []> hostPtr ( new int [storageSize]) ;
99101
100102 for (auto i = 0u ; i < storageSize; i++) {
101103 hostPtr[i] = i;
@@ -106,7 +108,7 @@ HWTEST_P(AUBCreateImageArray, CheckArrayImages) {
106108 flags,
107109 surfaceFormat,
108110 &imageDesc,
109- hostPtr,
111+ hostPtr. get () ,
110112 retVal);
111113
112114 ASSERT_EQ (CL_SUCCESS, retVal);
@@ -119,29 +121,41 @@ HWTEST_P(AUBCreateImageArray, CheckArrayImages) {
119121 EXPECT_EQ (image->getQPitch (), imgInfo.qPitch );
120122 EXPECT_EQ (image->getCubeFaceIndex (), static_cast <uint32_t >(__GMM_NO_CUBE_MAP));
121123
122- auto address = (int *)image->getCpuAddress ();
124+ auto imageHeight = imageDesc.image_height ;
125+ std::unique_ptr<uint32_t []> readMemory (new uint32_t [image->getSize () / sizeof (uint32_t )]);
126+ auto allocation = createResidentAllocationAndStoreItInCsr (readMemory.get (), image->getSize ());
123127
124- ASSERT_NE (nullptr , address);
128+ size_t imgOrigin[] = {0 , 0 , 0 };
129+ size_t imgRegion[] = {imageDesc.image_width , 1 , 1 };
125130
126- auto imageHeight = imageDesc.image_height ;
131+ if (imageDesc.image_type == CL_MEM_OBJECT_IMAGE1D_ARRAY) {
132+ imgRegion[1 ] = imageDesc.image_array_size ;
133+ } else if (imageDesc.image_type == CL_MEM_OBJECT_IMAGE2D_ARRAY) {
134+ imgRegion[1 ] = imageDesc.image_height ;
135+ imgRegion[2 ] = imageDesc.image_array_size ;
136+ } else {
137+ ASSERT_TRUE (false );
138+ }
139+ retVal = pCmdQ->enqueueReadImage (image, CL_FALSE, imgOrigin, imgRegion, imgInfo.rowPitch , imgInfo.slicePitch ,
140+ readMemory.get (), 0 , nullptr , nullptr );
141+ EXPECT_EQ (CL_SUCCESS, retVal);
127142
128- uint32_t *readMemory = nullptr ;
129- if (image->allowTiling ()) {
130- readMemory = new uint32_t [image->getSize ()];
131- size_t imgOrigin[] = {0 , 0 , 0 };
132- size_t imgRegion[] = {imageDesc.image_width , imageDesc.image_height , imageDesc.image_array_size };
133- retVal = pCmdQ->enqueueReadImage (image, CL_TRUE, imgOrigin, imgRegion, imgInfo.rowPitch , imgInfo.slicePitch ,
134- readMemory, 0 , nullptr , nullptr );
135- EXPECT_EQ (CL_SUCCESS, retVal);
143+ allocation = pCommandStreamReceiver->getTemporaryAllocations ().peekHead ();
144+ while (allocation && allocation->getUnderlyingBuffer () != readMemory.get ()) {
145+ allocation = allocation->next ;
136146 }
137147
148+ auto destGpuAddress = reinterpret_cast <uint32_t *>(allocation->getGpuAddress ());
149+ pCmdQ->flush ();
150+
151+ auto address = (int *)image->getCpuAddress ();
138152 auto currentCounter = 0 ;
139153 for (auto array = 0u ; array < imageDesc.image_array_size ; array++) {
140154 for (auto height = 0u ; height < imageHeight; height++) {
141155 for (auto element = 0u ; element < imageDesc.image_width ; element++) {
142156 auto offset = (array * imgInfo.slicePitch + element * pixelSize + height * imgInfo.rowPitch ) / 4 ;
143- if (image->allowTiling () ) {
144- AUBCommandStreamFixture::expectMemory<FamilyType>(&readMemory [offset], ¤tCounter, pixelSize);
157+ if (MemoryPool::isSystemMemoryPool ( image->getGraphicsAllocation ()-> getMemoryPool ()) == false ) {
158+ AUBCommandStreamFixture::expectMemory<FamilyType>(&destGpuAddress [offset], ¤tCounter, pixelSize);
145159 } else {
146160 EXPECT_EQ (currentCounter, address[offset]);
147161 }
@@ -150,13 +164,8 @@ HWTEST_P(AUBCreateImageArray, CheckArrayImages) {
150164 }
151165 }
152166
153- if (readMemory) {
154- delete readMemory;
155- }
156167 delete image;
157- delete[] hostPtr;
158168}
159-
160169struct AUBCreateImageHostPtr : public AUBCreateImage ,
161170 public ::testing::WithParamInterface<uint64_t /* cl_mem_object_type*/ > {
162171 void SetUp () override {
0 commit comments