@@ -143,3 +143,66 @@ HWTEST_F(AUBReadBuffer, reserveCanonicalGpuAddress) {
143143
144144 AUBCommandStreamFixture::expectMemory<FamilyType>(dstGpuAddress, srcMemory, sizeof (dstMemory));
145145}
146+
147+ struct AUBReadBufferUnaligned
148+ : public CommandEnqueueAUBFixture,
149+ public ::testing::Test {
150+
151+ void SetUp () override {
152+ CommandEnqueueAUBFixture::SetUp ();
153+ }
154+
155+ void TearDown () override {
156+ CommandEnqueueAUBFixture::TearDown ();
157+ }
158+
159+ template <typename FamilyType>
160+ void testReadBufferUnaligned (size_t offset, size_t size) {
161+ MockContext context (&pCmdQ->getDevice ());
162+
163+ char srcMemory[] = " ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
164+ const auto bufferSize = sizeof (srcMemory);
165+ char dstMemory[bufferSize] = {0 };
166+
167+ auto retVal = CL_INVALID_VALUE;
168+
169+ auto buffer = std::unique_ptr<Buffer>(Buffer::create (
170+ &context,
171+ CL_MEM_USE_HOST_PTR,
172+ bufferSize,
173+ srcMemory,
174+ retVal));
175+ ASSERT_NE (nullptr , buffer);
176+
177+ buffer->forceDisallowCPUCopy = true ;
178+
179+ // Map destination memory to GPU
180+ GraphicsAllocation *allocation = createResidentAllocationAndStoreItInCsr (dstMemory, bufferSize);
181+ auto dstMemoryGPUPtr = reinterpret_cast <char *>(allocation->getGpuAddress ());
182+
183+ // Do unaligned read
184+ retVal = pCmdQ->enqueueReadBuffer (
185+ buffer.get (),
186+ CL_TRUE,
187+ offset,
188+ size,
189+ ptrOffset (dstMemory, offset),
190+ 0 ,
191+ nullptr ,
192+ nullptr );
193+ EXPECT_EQ (CL_SUCCESS, retVal);
194+
195+ // Check the memory
196+ AUBCommandStreamFixture::expectMemory<FamilyType>(ptrOffset (dstMemoryGPUPtr, offset), ptrOffset (srcMemory, offset), size);
197+ }
198+ };
199+
200+ HWTEST_F (AUBReadBufferUnaligned, all) {
201+ const std::vector<size_t > offsets = {0 , 1 , 2 , 3 };
202+ const std::vector<size_t > sizes = {4 , 3 , 2 , 1 };
203+ for (auto offset : offsets) {
204+ for (auto size : sizes) {
205+ testReadBufferUnaligned<FamilyType>(offset, size);
206+ }
207+ }
208+ }
0 commit comments