1 /* 2 * Copyright (C) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "av_hardware_memory.h" 17 #include "av_shared_allocator.h" 18 #include "av_shared_memory_ext.h" 19 #include "av_surface_allocator.h" 20 #include "av_surface_memory.h" 21 #include "avbuffer_unit_test.h" 22 #include "avbuffer_utils.h" 23 #include "unittest_log.h" 24 25 using namespace std; 26 using namespace testing::ext; 27 using namespace OHOS; 28 using namespace OHOS::Media; 29 30 namespace OHOS { 31 namespace Media { 32 namespace AVBufferUT { 33 /** 34 * @tc.name: AVBuffer_Config_001 35 * @tc.desc: compare config structs of different type 36 * @tc.type: FUNC 37 */ 38 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Config_001, TestSize.Level1) 39 { 40 AVBufferConfig configFirst; 41 AVBufferConfig configSecond; 42 configFirst.memoryType = MemoryType::HARDWARE_MEMORY; 43 configSecond.memoryType = MemoryType::SURFACE_MEMORY; 44 EXPECT_FALSE(configFirst.memoryType <= configSecond.memoryType); 45 } 46 47 /** 48 * @tc.name: AVBuffer_Config_002 49 * @tc.desc: compare config structs of dmabuffer 50 * @tc.type: FUNC 51 */ 52 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Config_002, TestSize.Level1) 53 { 54 AVBufferConfig configFirst; 55 AVBufferConfig configSecond; 56 configFirst.memoryType = configSecond.memoryType = MemoryType::HARDWARE_MEMORY; 57 configFirst.size = 0; 58 configSecond.capacity = 1; 59 EXPECT_TRUE(configFirst <= configSecond); 60 61 configFirst.size = 0; 62 configSecond.capacity = 0; 63 EXPECT_TRUE(configFirst <= configSecond); 64 65 configFirst.size = 1; 66 configSecond.capacity = 0; 67 EXPECT_FALSE(configFirst <= configSecond); 68 69 configFirst.size = 0; 70 configSecond.capacity = 1; 71 configFirst.memoryFlag = MemoryFlag::MEMORY_READ_ONLY; 72 configSecond.memoryFlag = MemoryFlag::MEMORY_READ_ONLY; 73 EXPECT_TRUE(configFirst <= configSecond); 74 75 configFirst.size = 0; 76 configSecond.capacity = 1; 77 configFirst.memoryFlag = MemoryFlag::MEMORY_READ_ONLY; 78 configSecond.memoryFlag = MemoryFlag::MEMORY_READ_WRITE; 79 EXPECT_TRUE(configFirst <= configSecond); 80 81 configFirst.size = 0; 82 configSecond.capacity = 1; 83 configFirst.memoryFlag = MemoryFlag::MEMORY_READ_WRITE; 84 configSecond.memoryFlag = MemoryFlag::MEMORY_READ_ONLY; 85 EXPECT_FALSE(configFirst <= configSecond); 86 } 87 88 /** 89 * @tc.name: AVBuffer_Config_003 90 * @tc.desc: compare config structs of shared memory 91 * @tc.type: FUNC 92 */ 93 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Config_003, TestSize.Level1) 94 { 95 AVBufferConfig configFirst; 96 AVBufferConfig configSecond; 97 configFirst.memoryType = configSecond.memoryType = MemoryType::SHARED_MEMORY; 98 configFirst.size = 0; 99 configSecond.capacity = 1; 100 EXPECT_TRUE(configFirst <= configSecond); 101 102 configFirst.size = 0; 103 configSecond.capacity = 0; 104 EXPECT_TRUE(configFirst <= configSecond); 105 106 configFirst.size = 2; // 2: first size 107 configSecond.capacity = 1; 108 configSecond.align = 2; // 2: align size 109 EXPECT_TRUE(configFirst <= configSecond); 110 configSecond.align = 0; 111 112 configFirst.size = 1; 113 configSecond.capacity = 0; 114 EXPECT_FALSE(configFirst <= configSecond); 115 116 configFirst.size = 0; 117 configSecond.capacity = 1; 118 configFirst.memoryFlag = MemoryFlag::MEMORY_READ_ONLY; 119 configSecond.memoryFlag = MemoryFlag::MEMORY_READ_ONLY; 120 EXPECT_TRUE(configFirst <= configSecond); 121 122 configFirst.size = 0; 123 configSecond.capacity = 1; 124 configFirst.memoryFlag = MemoryFlag::MEMORY_READ_ONLY; 125 configSecond.memoryFlag = MemoryFlag::MEMORY_READ_WRITE; 126 EXPECT_TRUE(configFirst <= configSecond); 127 128 configFirst.size = 0; 129 configSecond.capacity = 1; 130 configFirst.memoryFlag = MemoryFlag::MEMORY_READ_WRITE; 131 configSecond.memoryFlag = MemoryFlag::MEMORY_READ_ONLY; 132 EXPECT_FALSE(configFirst <= configSecond); 133 } 134 135 /** 136 * @tc.name: AVBuffer_Config_004 137 * @tc.desc: compare config structs of surface memory 138 * @tc.type: FUNC 139 */ 140 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Config_004, TestSize.Level1) 141 { 142 AVBufferConfig configFirst; 143 AVBufferConfig configSecond; 144 configFirst.memoryType = configSecond.memoryType = MemoryType::SURFACE_MEMORY; 145 configFirst.size = 1; 146 configSecond.capacity = 0; 147 EXPECT_TRUE(configFirst <= configSecond); 148 149 configFirst.memoryFlag = MemoryFlag::MEMORY_READ_WRITE; 150 configSecond.memoryFlag = MemoryFlag::MEMORY_READ_ONLY; 151 EXPECT_TRUE(configFirst <= configSecond); 152 153 *(configFirst.surfaceBufferConfig) = DEFAULT_CONFIG; 154 EXPECT_FALSE(configFirst <= configSecond); 155 156 *(configFirst.surfaceBufferConfig) = DEFAULT_CONFIG; 157 *(configSecond.surfaceBufferConfig) = DEFAULT_CONFIG; 158 EXPECT_TRUE(configFirst <= configSecond); 159 } 160 161 /** 162 * @tc.name: AVBuffer_Config_005 163 * @tc.desc: compare config structs of virual memory 164 * @tc.type: FUNC 165 */ 166 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Config_005, TestSize.Level1) 167 { 168 AVBufferConfig configFirst; 169 AVBufferConfig configSecond; 170 configFirst.memoryType = configSecond.memoryType = MemoryType::VIRTUAL_MEMORY; 171 configFirst.size = 0; 172 configSecond.capacity = 1; 173 EXPECT_TRUE(configFirst <= configSecond); 174 175 configFirst.size = 0; 176 configSecond.capacity = 0; 177 EXPECT_TRUE(configFirst <= configSecond); 178 179 configFirst.size = 1; 180 configSecond.capacity = 0; 181 EXPECT_FALSE(configFirst <= configSecond); 182 183 configFirst.size = 0; 184 configSecond.capacity = 1; 185 configFirst.memoryFlag = MemoryFlag::MEMORY_READ_WRITE; 186 configSecond.memoryFlag = MemoryFlag::MEMORY_READ_ONLY; 187 EXPECT_TRUE(configFirst <= configSecond); 188 189 configFirst.size = 0; 190 configFirst.capacity = 1; 191 configSecond.size = 1; 192 configSecond.capacity = 1; 193 EXPECT_TRUE(configFirst <= configSecond); 194 195 configFirst.size = 1; 196 configFirst.capacity = 0; 197 configSecond.size = 0; 198 configSecond.capacity = 1; 199 EXPECT_TRUE(configFirst <= configSecond); 200 201 configFirst.size = 1; 202 configFirst.capacity = 0; 203 configSecond.size = 1; 204 configSecond.capacity = 0; 205 EXPECT_FALSE(configFirst <= configSecond); 206 } 207 208 /** 209 * @tc.name: AVBuffer_Config_006 210 * @tc.desc: marshalled and unmarshalled config struct 211 * @tc.type: FUNC 212 */ 213 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Config_006, TestSize.Level1) 214 { 215 AVBufferConfig configRemote; 216 configRemote.size = MEMSIZE; 217 configRemote.align = POSITION_ONE; 218 configRemote.memoryType = MemoryType::HARDWARE_MEMORY; 219 configRemote.memoryFlag = MemoryFlag::MEMORY_READ_WRITE; 220 configRemote.capacity = TEST_BUFFER_SIZE; 221 configRemote.dmaFd = 1; 222 223 MessageParcel parcel; 224 *(configRemote.surfaceBufferConfig) = DEFAULT_CONFIG; 225 EXPECT_TRUE(MarshallingConfig(parcel, configRemote)); 226 227 AVBufferConfig configLocal; 228 EXPECT_TRUE(UnmarshallingConfig(parcel, configLocal)); 229 230 EXPECT_EQ(configRemote.size, configLocal.size); 231 EXPECT_EQ(configRemote.align, configLocal.align); 232 EXPECT_EQ(configRemote.memoryType, configLocal.memoryType); 233 EXPECT_EQ(configRemote.memoryFlag, configLocal.memoryFlag); 234 EXPECT_EQ(configRemote.capacity, configLocal.capacity); 235 EXPECT_EQ(configRemote.dmaFd, configLocal.dmaFd); 236 237 EXPECT_EQ(configRemote.surfaceBufferConfig->width, configLocal.surfaceBufferConfig->width); 238 EXPECT_EQ(configRemote.surfaceBufferConfig->height, configLocal.surfaceBufferConfig->height); 239 EXPECT_EQ(configRemote.surfaceBufferConfig->strideAlignment, configLocal.surfaceBufferConfig->strideAlignment); 240 EXPECT_EQ(configRemote.surfaceBufferConfig->format, configLocal.surfaceBufferConfig->format); 241 EXPECT_EQ(configRemote.surfaceBufferConfig->usage, configLocal.surfaceBufferConfig->usage); 242 EXPECT_EQ(configRemote.surfaceBufferConfig->timeout, configLocal.surfaceBufferConfig->timeout); 243 EXPECT_EQ(configRemote.surfaceBufferConfig->colorGamut, configLocal.surfaceBufferConfig->colorGamut); 244 EXPECT_EQ(configRemote.surfaceBufferConfig->transform, configLocal.surfaceBufferConfig->transform); 245 } 246 247 /** 248 * @tc.name: AVBuffer_CreateWithInvalid_001 249 * @tc.desc: create memory with invalid parcel 250 * @tc.type: FUNC 251 */ 252 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_CreateWithInvalid_001, TestSize.Level1) 253 { 254 parcel_ = std::make_shared<MessageParcel>(); 255 buffer_ = AVBuffer::CreateAVBuffer(); 256 ASSERT_FALSE(buffer_->ReadFromMessageParcel(*parcel_)); 257 ASSERT_EQ(buffer_->memory_, nullptr); 258 } 259 260 /** 261 * @tc.name: AVBuffer_CreateWithInvalid_002 262 * @tc.desc: create buffer with null allocator 263 * @tc.type: FUNC 264 */ 265 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_CreateWithInvalid_002, TestSize.Level1) 266 { 267 buffer_ = AVBuffer::CreateAVBuffer(std::shared_ptr<AVAllocator>(nullptr)); 268 EXPECT_EQ(nullptr, buffer_); 269 } 270 271 /** 272 * @tc.name: AVBuffer_CreateWithInvalid_003 273 * @tc.desc: create virtual memory with invalid allocator 274 * @tc.type: FUNC 275 */ 276 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_CreateWithInvalid_003, TestSize.Level1) 277 { 278 allocator_ = AVAllocatorFactory::CreateVirtualAllocator(); 279 buffer_ = AVBuffer::CreateAVBuffer(allocator_, -1); 280 EXPECT_EQ(nullptr, buffer_); 281 282 buffer_ = AVBuffer::CreateAVBuffer(allocator_, 0); 283 EXPECT_NE(nullptr, buffer_); 284 } 285 286 /** 287 * @tc.name: AVBuffer_CreateWithInvalid_004 288 * @tc.desc: create hardware memory with invalid allocator 289 * @tc.type: FUNC 290 */ 291 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_CreateWithInvalid_004, TestSize.Level1) 292 { 293 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 294 DmabufHeapBuffer dmaBuffer = {.size = capacity_, .heapFlags = 0}; 295 int32_t dmaHeapFd = HardwareHeapFactory::GetInstance().GetHardwareHeapFd(); 296 DmabufHeapBufferAlloc(dmaHeapFd, &dmaBuffer); 297 dmaBufferLst_.push_back(dmaBuffer); 298 299 allocator_ = AVAllocatorFactory::CreateHardwareAllocator(0, capacity_, memFlag_); 300 buffer_ = AVBuffer::CreateAVBuffer(allocator_); 301 EXPECT_EQ(nullptr, buffer_); 302 303 allocator_ = AVAllocatorFactory::CreateHardwareAllocator(dmaBuffer.fd, -1, memFlag_); 304 buffer_ = AVBuffer::CreateAVBuffer(allocator_); 305 EXPECT_EQ(nullptr, buffer_); 306 307 allocator_ = AVAllocatorFactory::CreateHardwareAllocator(dmaBuffer.fd, 0, memFlag_); 308 buffer_ = AVBuffer::CreateAVBuffer(allocator_); 309 EXPECT_EQ(nullptr, buffer_); 310 } 311 312 /** 313 * @tc.name: AVBuffer_CreateWithInvalid_005 314 * @tc.desc: create surface memory with invalid surface buffer 315 * @tc.type: FUNC 316 */ 317 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_CreateWithInvalid_005, TestSize.Level1) 318 { 319 buffer_ = AVBuffer::CreateAVBuffer(sptr<SurfaceBuffer>(nullptr)); 320 EXPECT_EQ(nullptr, buffer_); 321 322 auto surfaceBuffer = SurfaceBuffer::Create(); 323 surfaceBuffer->Alloc(DEFAULT_CONFIG); 324 surfaceBuffer->DecStrongRef(surfaceBuffer.GetRefPtr()); 325 buffer_ = AVBuffer::CreateAVBuffer(surfaceBuffer); 326 EXPECT_EQ(nullptr, buffer_); 327 } 328 329 /** 330 * @tc.name: AVBuffer_Create_Local_SharedMemory_001 331 * @tc.desc: create local shared memory with allocator and align_ = 2 332 * @tc.type: FUNC 333 */ 334 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Create_Local_SharedMemory_001, TestSize.Level1) 335 { 336 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 337 capacity_ = MEMSIZE; 338 align_ = 2; // test align 339 CreateLocalSharedMem(); 340 ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 341 int32_t offset = static_cast<size_t>( 342 AlignUp(reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()), static_cast<uintptr_t>(align_)) - 343 reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr())); 344 EXPECT_EQ(std::static_pointer_cast<AVSharedMemoryExt>(buffer_->memory_)->allocator_->GetMemoryType(), 345 MemoryType::SHARED_MEMORY); 346 EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::SHARED_MEMORY); 347 EXPECT_EQ(buffer_->memory_->capacity_, capacity_); 348 EXPECT_EQ(buffer_->memory_->offset_, offset); 349 EXPECT_EQ(std::static_pointer_cast<AVSharedAllocator>(allocator_)->memFlag_, memFlag_); 350 } 351 352 /** 353 * @tc.name: AVBuffer_Create_Local_SharedMemory_002 354 * @tc.desc: create local shared memory with allocator 355 * @tc.type: FUNC 356 */ 357 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Create_Local_SharedMemory_002, TestSize.Level1) 358 { 359 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 360 capacity_ = MEMSIZE; 361 align_ = 0; 362 allocator_ = AVAllocatorFactory::CreateSharedAllocator(memFlag_); 363 ASSERT_NE(nullptr, allocator_); 364 remoteBuffer_ = buffer_ = AVBuffer::CreateAVBuffer(allocator_, capacity_, align_); 365 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 366 EXPECT_EQ(buffer_->memory_->GetCapacity(), capacity_); 367 } 368 369 /** 370 * @tc.name: AVBuffer_Create_Local_SharedMemory_003 371 * @tc.desc: create local shared memory with config 372 * @tc.type: FUNC 373 */ 374 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Create_Local_SharedMemory_003, TestSize.Level1) 375 { 376 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 377 capacity_ = MEMSIZE; 378 align_ = 0; 379 CreateLocalSharedMemByConfig(); 380 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 381 int32_t offset = static_cast<size_t>( 382 AlignUp(reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()), static_cast<uintptr_t>(align_)) - 383 reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr())); 384 EXPECT_EQ(std::static_pointer_cast<AVSharedMemoryExt>(buffer_->memory_)->allocator_->GetMemoryType(), 385 MemoryType::SHARED_MEMORY); 386 EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::SHARED_MEMORY); 387 EXPECT_EQ(buffer_->memory_->capacity_, capacity_); 388 EXPECT_EQ(buffer_->memory_->offset_, offset); 389 } 390 391 /** 392 * @tc.name: AVBuffer_SharedMemory_GetConfig_001 393 * @tc.desc: get avbuffer's config 394 * @tc.type: FUNC 395 */ 396 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SharedMemory_GetConfig_001, TestSize.Level1) 397 { 398 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 399 capacity_ = MEMSIZE; 400 align_ = 1; 401 CreateLocalSharedMem(); 402 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 403 AVBufferConfig config = buffer_->GetConfig(); 404 EXPECT_EQ(config.memoryType, MemoryType::SHARED_MEMORY); 405 EXPECT_EQ(config.memoryFlag, memFlag_); 406 EXPECT_EQ(config.capacity, capacity_); 407 EXPECT_EQ(config.align, align_); 408 } 409 410 /** 411 * @tc.name: AVBuffer_Create_Remote_SharedMemory_001 412 * @tc.desc: create avbuffer of shared memory by reading parcel 413 * @tc.type: FUNC 414 */ 415 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Create_Remote_SharedMemory_001, TestSize.Level1) 416 { 417 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 418 capacity_ = MEMSIZE; 419 align_ = 0; 420 CreateRemoteSharedMem(); 421 ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 422 GetRemoteBuffer(); 423 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 424 ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId()); 425 int32_t offset = static_cast<size_t>( 426 AlignUp(reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()), static_cast<uintptr_t>(align_)) - 427 reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr())); 428 EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::SHARED_MEMORY); 429 EXPECT_EQ(buffer_->memory_->capacity_, capacity_); 430 EXPECT_EQ(buffer_->memory_->offset_, offset); 431 EXPECT_EQ(std::static_pointer_cast<AVSharedAllocator>(allocator_)->memFlag_, memFlag_); 432 EXPECT_GT(std::static_pointer_cast<AVSharedMemoryExt>(buffer_->memory_)->fd_, 0); 433 } 434 435 /** 436 * @tc.name: AVBuffer_SharedMemory_SetParams_001 437 * @tc.desc: set and get parameters 438 * @tc.type: FUNC 439 */ 440 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SharedMemory_SetParams_001, TestSize.Level1) 441 { 442 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 443 capacity_ = MEMSIZE; 444 align_ = 0; 445 CreateLocalSharedMem(); 446 ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 447 CheckMetaSetAndGet(); 448 } 449 450 /** 451 * @tc.name: AVBuffer_SharedMemory_SetParams_002 452 * @tc.desc: set and get parameters after reading parcel 453 * @tc.type: FUNC 454 */ 455 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SharedMemory_SetParams_002, TestSize.Level1) 456 { 457 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 458 capacity_ = MEMSIZE; 459 align_ = 0; 460 CreateRemoteSharedMem(); 461 ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 462 CheckMetaSetAndGet(); 463 } 464 465 /** 466 * @tc.name: AVBuffer_SharedMemory_WriteAndRead_001 467 * @tc.desc: shared memory write and read 468 * @tc.type: FUNC 469 */ 470 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SharedMemory_WriteAndRead_001, TestSize.Level1) 471 { 472 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 473 capacity_ = MEMSIZE; 474 align_ = 0; 475 CreateLocalSharedMem(); 476 ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 477 CheckMemTrans(); 478 } 479 480 /** 481 * @tc.name: AVBuffer_SharedMemory_WriteAndRead_002 482 * @tc.desc: shared memory write and read after reading parcel 483 * @tc.type: FUNC 484 */ 485 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SharedMemory_WriteAndRead_002, TestSize.Level1) 486 { 487 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 488 capacity_ = MEMSIZE; 489 align_ = 0; 490 CreateRemoteSharedMem(); 491 ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 492 CheckMemTrans(); 493 } 494 495 /** 496 * @tc.name: AVBuffer_SharedMemory_WriteAndRead_003 497 * @tc.desc: shared memory write and read with valid position after reading parcel 498 * @tc.type: FUNC 499 */ 500 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SharedMemory_WriteAndRead_003, TestSize.Level1) 501 { 502 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 503 capacity_ = MEMSIZE; 504 align_ = 0; 505 CreateRemoteSharedMem(); 506 ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 507 CheckMemTransPos(POSITION_ONE); 508 } 509 510 /** 511 * @tc.name: AVBuffer_SharedMemory_WriteAndRead_004 512 * @tc.desc: shared memory write and read with invalid position after reading parcel 513 * @tc.type: FUNC 514 */ 515 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SharedMemory_WriteAndRead_004, TestSize.Level1) 516 { 517 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 518 capacity_ = MEMSIZE; 519 align_ = 0; 520 CreateRemoteSharedMem(); 521 ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 522 CheckMemTransOutOfRange(POSITION_ONE); 523 } 524 525 /** 526 * @tc.name: AVBuffer_SharedMemory_GetCapacity_001 527 * @tc.desc: shared memory get capacity 528 * @tc.type: FUNC 529 */ 530 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SharedMemory_GetCapacity_001, TestSize.Level1) 531 { 532 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 533 capacity_ = MEMSIZE; 534 align_ = 0; 535 CreateLocalSharedMem(); 536 ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 537 EXPECT_EQ(buffer_->memory_->GetCapacity(), capacity_); 538 } 539 540 /** 541 * @tc.name: AVBuffer_SharedMemory_GetCapacity_002 542 * @tc.desc: shared memory get capacity after reading parcel 543 * @tc.type: FUNC 544 */ 545 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SharedMemory_GetCapacity_002, TestSize.Level1) 546 { 547 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 548 capacity_ = MEMSIZE; 549 align_ = 0; 550 CreateRemoteSharedMem(); 551 ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 552 GetRemoteBuffer(); 553 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 554 ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId()); 555 EXPECT_EQ(buffer_->memory_->GetCapacity(), capacity_); 556 } 557 558 /** 559 * @tc.name: AVBuffer_SharedMemory_CheckDataSize_001 560 * @tc.desc: shared memory check dataSize 561 * @tc.type: FUNC 562 */ 563 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SharedMemory_CheckDataSize_001, TestSize.Level1) 564 { 565 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 566 capacity_ = MEMSIZE; 567 align_ = 0; 568 CreateLocalSharedMem(); 569 ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 570 CheckDataSize(); 571 } 572 573 /** 574 * @tc.name: AVBuffer_SharedMemory_CheckDataSize_002 575 * @tc.desc: shared memory check dataSize after reading parcel 576 * @tc.type: FUNC 577 */ 578 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SharedMemory_CheckDataSize_002, TestSize.Level1) 579 { 580 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 581 capacity_ = MEMSIZE; 582 align_ = 0; 583 CreateRemoteSharedMem(); 584 ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 585 CheckDataSize(); 586 } 587 588 /** 589 * @tc.name: AVBuffer_SharedMemory_GetMemoryType_001 590 * @tc.desc: shared memory get memory type 591 * @tc.type: FUNC 592 */ 593 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SharedMemory_GetMemoryType_001, TestSize.Level1) 594 { 595 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 596 capacity_ = MEMSIZE; 597 align_ = 0; 598 CreateLocalSharedMem(); 599 ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 600 EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::SHARED_MEMORY); 601 } 602 603 /** 604 * @tc.name: AVBuffer_SharedMemory_GetMemoryType_002 605 * @tc.desc: shared memory get memory type after reading parcel 606 * @tc.type: FUNC 607 */ 608 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SharedMemory_GetMemoryType_002, TestSize.Level1) 609 { 610 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 611 capacity_ = MEMSIZE; 612 align_ = 0; 613 CreateRemoteSharedMem(); 614 ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 615 GetRemoteBuffer(); 616 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 617 ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId()); 618 EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::SHARED_MEMORY); 619 } 620 621 /** 622 * @tc.name: AVBuffer_SharedMemory_GetFileDescriptor_001 623 * @tc.desc: shared memory get memory file descriptor 624 * @tc.type: FUNC 625 */ 626 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SharedMemory_GetFileDescriptor_001, TestSize.Level1) 627 { 628 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 629 capacity_ = MEMSIZE; 630 align_ = 0; 631 CreateLocalSharedMem(); 632 ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 633 EXPECT_GT(buffer_->memory_->GetFileDescriptor(), 0); 634 } 635 636 /** 637 * @tc.name: AVBuffer_SharedMemory_GetFileDescriptor_002 638 * @tc.desc: shared memory get memory file descriptor after reading parcel 639 * @tc.type: FUNC 640 */ 641 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SharedMemory_GetFileDescriptor_002, TestSize.Level1) 642 { 643 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 644 capacity_ = MEMSIZE; 645 align_ = 0; 646 CreateRemoteSharedMem(); 647 ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 648 GetRemoteBuffer(); 649 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 650 ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId()); 651 EXPECT_GT(buffer_->memory_->GetFileDescriptor(), 0); 652 } 653 654 /** 655 * @tc.name: AVBuffer_SharedMemory_Reset_001 656 * @tc.desc: shared memory reset 657 * @tc.type: FUNC 658 */ 659 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SharedMemory_Reset_001, TestSize.Level1) 660 { 661 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 662 capacity_ = MEMSIZE; 663 align_ = 0; 664 CreateLocalSharedMem(); 665 ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 666 buffer_->memory_->SetSize(MEMSIZE); 667 EXPECT_EQ(buffer_->memory_->size_, MEMSIZE); 668 buffer_->memory_->Reset(); 669 EXPECT_EQ(buffer_->memory_->size_, 0); 670 } 671 672 /** 673 * @tc.name: AVBuffer_SharedMemory_Reset_002 674 * @tc.desc: shared memory reset after reading parcel 675 * @tc.type: FUNC 676 */ 677 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SharedMemory_Reset_002, TestSize.Level1) 678 { 679 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 680 capacity_ = MEMSIZE; 681 align_ = 0; 682 CreateRemoteSharedMem(); 683 ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 684 remoteBuffer_->memory_->SetSize(MEMSIZE); 685 EXPECT_EQ(remoteBuffer_->memory_->size_, MEMSIZE); 686 remoteBuffer_->memory_->Reset(); 687 EXPECT_EQ(remoteBuffer_->memory_->size_, 0); 688 GetRemoteBuffer(); 689 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 690 ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId()); 691 buffer_->memory_->Reset(); 692 EXPECT_EQ(buffer_->memory_->size_, 0); 693 } 694 695 /** 696 * @tc.name: AVBuffer_SharedMemory_ReadFromMessageParcel_001 697 * @tc.desc: shared memory read from message parcel 698 * @tc.type: FUNC 699 */ 700 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SharedMemory_ReadFromMessageParcel_001, TestSize.Level1) 701 { 702 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 703 capacity_ = MEMSIZE; 704 align_ = 0; 705 CreateRemoteSharedMem(); 706 CheckAttrTrans(); 707 } 708 709 /** 710 * @tc.name: AVBuffer_Create_Local_SurfaceMemory_001 711 * @tc.desc: create avbuffer of surface memory with allocator 712 * @tc.type: FUNC 713 */ 714 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Create_Local_SurfaceMemory_001, TestSize.Level1) 715 { 716 align_ = 0; 717 CreateLocalSurfaceMem(); 718 ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 719 int32_t offset = static_cast<size_t>( 720 AlignUp(reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()), static_cast<uintptr_t>(align_)) - 721 reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr())); 722 EXPECT_EQ(std::static_pointer_cast<AVSurfaceMemory>(buffer_->memory_)->allocator_->GetMemoryType(), 723 MemoryType::SURFACE_MEMORY); 724 EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::SURFACE_MEMORY); 725 EXPECT_EQ(buffer_->memory_->offset_, offset); 726 } 727 728 /** 729 * @tc.name: AVBuffer_Create_Local_SurfaceMemory_002 730 * @tc.desc: create avbuffer of surface memory with parcel getting from SurfaceBuffer 731 * @tc.type: FUNC 732 */ 733 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Create_Local_SurfaceMemory_002, TestSize.Level1) 734 { 735 align_ = 0; 736 CreateLocalSurfaceMemByParcel(); 737 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 738 int32_t offset = static_cast<size_t>( 739 AlignUp(reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()), static_cast<uintptr_t>(align_)) - 740 reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr())); 741 EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::SURFACE_MEMORY); 742 EXPECT_EQ(buffer_->memory_->offset_, offset); 743 } 744 745 /** 746 * @tc.name: AVBuffer_Create_Local_SurfaceMemory_003 747 * @tc.desc: create avbuffer of surface memory with config struct 748 * @tc.type: FUNC 749 */ 750 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Create_Local_SurfaceMemory_003, TestSize.Level1) 751 { 752 align_ = 0; 753 CreateLocalSurfaceMemByConfig(); 754 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 755 int32_t offset = static_cast<size_t>( 756 AlignUp(reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()), static_cast<uintptr_t>(align_)) - 757 reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr())); 758 EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::SURFACE_MEMORY); 759 EXPECT_EQ(buffer_->memory_->offset_, offset); 760 } 761 762 /** 763 * @tc.name: AVBuffer_SurfaceMemory_GetConfig_001 764 * @tc.desc: create local surface memory with allocator, and get config 765 * @tc.type: FUNC 766 */ 767 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_GetConfig_001, TestSize.Level1) 768 { 769 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 770 CreateLocalSurfaceMem(); 771 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 772 AVBufferConfig config = buffer_->GetConfig(); 773 EXPECT_EQ(config.memoryType, MemoryType::SURFACE_MEMORY); 774 EXPECT_EQ(config.surfaceBufferConfig->width, DEFAULT_CONFIG.width); 775 EXPECT_EQ(config.surfaceBufferConfig->height, DEFAULT_CONFIG.height); 776 EXPECT_EQ(config.surfaceBufferConfig->format, DEFAULT_CONFIG.format); 777 EXPECT_EQ(config.surfaceBufferConfig->usage, DEFAULT_CONFIG.usage); 778 } 779 780 /** 781 * @tc.name: AVBuffer_SurfaceMemory_GetConfig_002 782 * @tc.desc: create local surface memory with config struct, and get config 783 * @tc.type: FUNC 784 */ 785 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_GetConfig_002, TestSize.Level1) 786 { 787 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 788 CreateLocalSurfaceMemByConfig(); 789 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 790 AVBufferConfig config = buffer_->GetConfig(); 791 EXPECT_TRUE(config <= config_); 792 } 793 794 /** 795 * @tc.name: AVBuffer_Create_Remote_SurfaceMemory_001 796 * @tc.desc: create avbuffer of surface memory by reading parcel 797 * @tc.type: FUNC 798 */ 799 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Create_Remote_SurfaceMemory_001, TestSize.Level1) 800 { 801 align_ = 0; 802 CreateRemoteSurfaceMem(); 803 ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 804 GetRemoteBuffer(); 805 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 806 ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId()); 807 int32_t offset = static_cast<size_t>( 808 AlignUp(reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()), static_cast<uintptr_t>(align_)) - 809 reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr())); 810 EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::SURFACE_MEMORY); 811 EXPECT_EQ(buffer_->memory_->offset_, offset); 812 uint8_t *addr = buffer_->memory_->GetAddr(); 813 auto surfaceBuffer = buffer_->memory_->GetSurfaceBuffer(); 814 buffer_ = nullptr; 815 EXPECT_EQ(addr, surfaceBuffer->GetVirAddr()); 816 } 817 818 /** 819 * @tc.name: AVBuffer_Create_Remote_SurfaceMemory_002 820 * @tc.desc: create avbuffer of surface memory by reading parcel getting from SurfaceBuffer 821 * @tc.type: FUNC 822 */ 823 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Create_Remote_SurfaceMemory_002, TestSize.Level1) 824 { 825 align_ = 0; 826 CreateRemoteSurfaceMemByParcel(); 827 ASSERT_FALSE((remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 828 GetRemoteBuffer(); 829 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 830 ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId()); 831 int32_t offset = static_cast<size_t>( 832 AlignUp(reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()), static_cast<uintptr_t>(align_)) - 833 reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr())); 834 EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::SURFACE_MEMORY); 835 EXPECT_EQ(buffer_->memory_->offset_, offset); 836 } 837 838 /** 839 * @tc.name: AVBuffer_Create_Remote_SurfaceMemory_003 840 * @tc.desc: create avbuffer of surface memory by sptr of SurfaceBuffer 841 * @tc.type: FUNC 842 */ 843 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Create_Remote_SurfaceMemory_003, TestSize.Level1) 844 { 845 align_ = 0; 846 CreateRemoteSurfaceMemBySptr(); 847 ASSERT_FALSE((remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 848 GetRemoteBuffer(); 849 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 850 ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId()); 851 int32_t offset = static_cast<size_t>( 852 AlignUp(reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()), static_cast<uintptr_t>(align_)) - 853 reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr())); 854 EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::SURFACE_MEMORY); 855 EXPECT_EQ(buffer_->memory_->offset_, offset); 856 } 857 858 /** 859 * @tc.name: AVBuffer_SurfaceMemory_SetParams_001 860 * @tc.desc: surface memory get and set params 861 * @tc.type: FUNC 862 */ 863 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_SetParams_001, TestSize.Level1) 864 { 865 capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE; 866 align_ = 0; 867 CreateLocalSurfaceMem(); 868 ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 869 CheckMetaSetAndGet(); 870 } 871 872 /** 873 * @tc.name: AVBuffer_SurfaceMemory_SetParams_002 874 * @tc.desc: surface memory get and set params after reading parcel 875 * @tc.type: FUNC 876 */ 877 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_SetParams_002, TestSize.Level1) 878 { 879 capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE; 880 align_ = 0; 881 CreateRemoteSurfaceMem(); 882 ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 883 CheckMetaSetAndGet(); 884 } 885 886 /** 887 * @tc.name: AVBuffer_SurfaceMemory_SetParams_003 888 * @tc.desc: surface memory get and set params 889 * @tc.type: FUNC 890 */ 891 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_SetParams_003, TestSize.Level1) 892 { 893 capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE; 894 align_ = 0; 895 CreateLocalSurfaceMemByParcel(); 896 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 897 CheckMetaSetAndGet(); 898 } 899 900 /** 901 * @tc.name: AVBuffer_SurfaceMemory_SetParams_004 902 * @tc.desc: surface memory get and set params after reading parcel 903 * @tc.type: FUNC 904 */ 905 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_SetParams_004, TestSize.Level1) 906 { 907 capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE; 908 align_ = 0; 909 CreateRemoteSurfaceMemByParcel(); 910 ASSERT_FALSE((remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 911 CheckMetaSetAndGet(); 912 } 913 914 /** 915 * @tc.name: AVBuffer_SurfaceMemory_WriteAndRead_001 916 * @tc.desc: surface memory write and read 917 * @tc.type: FUNC 918 */ 919 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_WriteAndRead_001, TestSize.Level1) 920 { 921 capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE; 922 align_ = 0; 923 CreateLocalSurfaceMem(); 924 ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 925 CheckMemTrans(); 926 } 927 928 /** 929 * @tc.name: AVBuffer_SurfaceMemory_WriteAndRead_002 930 * @tc.desc: surface memory write and read after reading parcel 931 * @tc.type: FUNC 932 */ 933 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_WriteAndRead_002, TestSize.Level1) 934 { 935 capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE; 936 align_ = 0; 937 CreateRemoteSurfaceMem(); 938 ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 939 CheckMemTrans(); 940 } 941 942 /** 943 * @tc.name: AVBuffer_SurfaceMemory_WriteAndRead_003 944 * @tc.desc: surface memory write and read with valid position after reading parcel 945 * @tc.type: FUNC 946 */ 947 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_WriteAndRead_003, TestSize.Level1) 948 { 949 capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE; 950 align_ = 0; 951 CreateRemoteSurfaceMem(); 952 ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 953 CheckMemTransPos(POSITION_ONE); 954 } 955 956 /** 957 * @tc.name: AVBuffer_SurfaceMemory_WriteAndRead_004 958 * @tc.desc: surface memory write and read with invalid position after reading parcel 959 * @tc.type: FUNC 960 */ 961 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_WriteAndRead_004, TestSize.Level1) 962 { 963 capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE; 964 align_ = 0; 965 CreateRemoteSurfaceMem(); 966 ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 967 CheckMemTransOutOfRange(POSITION_ONE); 968 } 969 970 /** 971 * @tc.name: AVBuffer_SurfaceMemory_WriteAndRead_005 972 * @tc.desc: 1. create surface memory with parcel getting from SurfaceBuffer 973 * 2. surface memory write and read 974 * @tc.type: FUNC 975 */ 976 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_WriteAndRead_005, TestSize.Level1) 977 { 978 capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE; 979 align_ = 0; 980 CreateLocalSurfaceMemByParcel(); 981 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 982 CheckMemTrans(); 983 } 984 985 /** 986 * @tc.name: AVBuffer_SurfaceMemory_WriteAndRead_006 987 * @tc.desc: 1. create surface memory with parcel getting from SurfaceBuffer 988 * 2. surface memory write and read after reading parcel 989 * @tc.type: FUNC 990 */ 991 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_WriteAndRead_006, TestSize.Level1) 992 { 993 capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE; 994 align_ = 0; 995 CreateRemoteSurfaceMemByParcel(); 996 ASSERT_FALSE((remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 997 CheckMemTrans(); 998 } 999 1000 /** 1001 * @tc.name: AVBuffer_SurfaceMemory_WriteAndRead_007 1002 * @tc.desc: 1. create surface memory with parcel getting from SurfaceBuffer 1003 * 2. surface memory write and read with valid position after reading parcel 1004 * @tc.type: FUNC 1005 */ 1006 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_WriteAndRead_007, TestSize.Level1) 1007 { 1008 capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE; 1009 align_ = 0; 1010 CreateRemoteSurfaceMemByParcel(); 1011 ASSERT_FALSE((remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 1012 CheckMemTransPos(POSITION_ONE); 1013 } 1014 1015 /** 1016 * @tc.name: AVBuffer_SurfaceMemory_WriteAndRead_008 1017 * @tc.desc: 1. create surface memory with parcel getting from SurfaceBuffer 1018 * 2. surface memory write and read with invalid position after reading parcel 1019 * @tc.type: FUNC 1020 */ 1021 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_WriteAndRead_008, TestSize.Level1) 1022 { 1023 capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE; 1024 align_ = 0; 1025 CreateRemoteSurfaceMemByParcel(); 1026 ASSERT_FALSE((remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 1027 CheckMemTransOutOfRange(POSITION_ONE); 1028 } 1029 1030 /** 1031 * @tc.name: AVBuffer_SurfaceMemory_WriteAndRead_009 1032 * @tc.desc: 1. create surface memory with parcel sptr of SurfaceBuffer 1033 * 2. surface memory write and read after reading parcel 1034 * @tc.type: FUNC 1035 */ 1036 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_WriteAndRead_009, TestSize.Level1) 1037 { 1038 capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE; 1039 align_ = 0; 1040 CreateRemoteSurfaceMemBySptr(); 1041 ASSERT_FALSE((remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 1042 CheckMemTrans(); 1043 } 1044 1045 /** 1046 * @tc.name: AVBuffer_SurfaceMemory_WriteAndRead_010 1047 * @tc.desc: 1. create surface memory with parcel sptr of SurfaceBuffer 1048 * 2. surface memory write and read with valid position after reading parcel 1049 * @tc.type: FUNC 1050 */ 1051 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_WriteAndRead_010, TestSize.Level1) 1052 { 1053 capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE; 1054 align_ = 0; 1055 CreateRemoteSurfaceMemBySptr(); 1056 ASSERT_FALSE((remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 1057 CheckMemTransPos(POSITION_ONE); 1058 } 1059 1060 /** 1061 * @tc.name: AVBuffer_SurfaceMemory_WriteAndRead_011 1062 * @tc.desc: 1. create surface memory with sptr of SurfaceBuffer 1063 * 2. surface memory write and read with invalid position after reading parcel 1064 * @tc.type: FUNC 1065 */ 1066 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_WriteAndRead_011, TestSize.Level1) 1067 { 1068 capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE; 1069 align_ = 0; 1070 CreateRemoteSurfaceMemBySptr(); 1071 ASSERT_FALSE((remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 1072 CheckMemTransOutOfRange(POSITION_ONE); 1073 } 1074 1075 /** 1076 * @tc.name: AVBuffer_SurfaceMemory_GetCapacity_001 1077 * @tc.desc: surface memory get capacity 1078 * @tc.type: FUNC 1079 */ 1080 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_GetCapacity_001, TestSize.Level1) 1081 { 1082 align_ = 0; 1083 CreateLocalSurfaceMem(); 1084 ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1085 } 1086 1087 /** 1088 * @tc.name: AVBuffer_SurfaceMemory_GetCapacity_002 1089 * @tc.desc: surface memory get capacity after reading parcel 1090 * @tc.type: FUNC 1091 */ 1092 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_GetCapacity_002, TestSize.Level1) 1093 { 1094 align_ = 0; 1095 CreateRemoteSurfaceMem(); 1096 ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 1097 GetRemoteBuffer(); 1098 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1099 ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId()); 1100 } 1101 1102 /** 1103 * @tc.name: AVBuffer_SurfaceMemory_GetCapacity_003 1104 * @tc.desc: surface memory get capacity with parcel getting from SurfaceBuffer 1105 * @tc.type: FUNC 1106 */ 1107 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_GetCapacity_003, TestSize.Level1) 1108 { 1109 align_ = 0; 1110 CreateLocalSurfaceMemByParcel(); 1111 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1112 } 1113 1114 /** 1115 * @tc.name: AVBuffer_SurfaceMemory_GetCapacity_004 1116 * @tc.desc: 1. create surface memory with parcel getting from SurfaceBuffer 1117 * 2. surface memory get capacity after reading parcel 1118 * @tc.type: FUNC 1119 */ 1120 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_GetCapacity_004, TestSize.Level1) 1121 { 1122 align_ = 0; 1123 CreateRemoteSurfaceMemByParcel(); 1124 ASSERT_FALSE((remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 1125 GetRemoteBuffer(); 1126 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1127 ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId()); 1128 } 1129 1130 /** 1131 * @tc.name: AVBuffer_SurfaceMemory_CheckDataSize_001 1132 * @tc.desc: surface memory check dataSize 1133 * @tc.type: FUNC 1134 */ 1135 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_CheckDataSize_001, TestSize.Level1) 1136 { 1137 capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE; 1138 align_ = 0; 1139 CreateLocalSurfaceMem(); 1140 ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1141 CheckDataSize(); 1142 } 1143 1144 /** 1145 * @tc.name: AVBuffer_SurfaceMemory_CheckDataSize_002 1146 * @tc.desc: surface memory check dataSize after reading parcel 1147 * @tc.type: FUNC 1148 */ 1149 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_CheckDataSize_002, TestSize.Level1) 1150 { 1151 capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE; 1152 align_ = 0; 1153 CreateRemoteSurfaceMem(); 1154 ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 1155 CheckDataSize(); 1156 } 1157 1158 /** 1159 * @tc.name: AVBuffer_SurfaceMemory_CheckDataSize_003 1160 * @tc.desc: surface memory check dataSize with parcel getting from SurfaceBuffer 1161 * @tc.type: FUNC 1162 */ 1163 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_CheckDataSize_003, TestSize.Level1) 1164 { 1165 capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE; 1166 align_ = 0; 1167 CreateLocalSurfaceMemByParcel(); 1168 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1169 CheckDataSize(); 1170 } 1171 1172 /** 1173 * @tc.name: AVBuffer_SurfaceMemory_CheckDataSize_004 1174 * @tc.desc: 1. create surface memory with parcel getting from SurfaceBuffer 1175 * 2. surface memory check dataSize after reading parcel 1176 * @tc.type: FUNC 1177 */ 1178 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_CheckDataSize_004, TestSize.Level1) 1179 { 1180 capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE; 1181 align_ = 0; 1182 CreateRemoteSurfaceMemByParcel(); 1183 ASSERT_FALSE((remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 1184 CheckDataSize(); 1185 } 1186 1187 /** 1188 * @tc.name: AVBuffer_SurfaceMemory_GetMemoryType_001 1189 * @tc.desc: surface memory get memory type 1190 * @tc.type: FUNC 1191 */ 1192 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_GetMemoryType_001, TestSize.Level1) 1193 { 1194 capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE; 1195 align_ = 0; 1196 CreateLocalSurfaceMem(); 1197 ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1198 EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::SURFACE_MEMORY); 1199 } 1200 1201 /** 1202 * @tc.name: AVBuffer_SurfaceMemory_GetMemoryType_002 1203 * @tc.desc: surface memory get memory type after reading parcel 1204 * @tc.type: FUNC 1205 */ 1206 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_GetMemoryType_002, TestSize.Level1) 1207 { 1208 capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE; 1209 align_ = 0; 1210 CreateRemoteSurfaceMem(); 1211 ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 1212 GetRemoteBuffer(); 1213 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1214 ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId()); 1215 EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::SURFACE_MEMORY); 1216 } 1217 1218 /** 1219 * @tc.name: AVBuffer_SurfaceMemory_GetMemoryType_003 1220 * @tc.desc: surface memory get memory type with parcel getting from SurfaceBuffer 1221 * @tc.type: FUNC 1222 */ 1223 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_GetMemoryType_003, TestSize.Level1) 1224 { 1225 capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE; 1226 align_ = 0; 1227 CreateLocalSurfaceMemByParcel(); 1228 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1229 EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::SURFACE_MEMORY); 1230 } 1231 1232 /** 1233 * @tc.name: AVBuffer_SurfaceMemory_GetMemoryType_004 1234 * @tc.desc: 1. create surface memory with parcel getting from SurfaceBuffer 1235 * 2. surface memory get memory type after reading parcel 1236 * @tc.type: FUNC 1237 */ 1238 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_GetMemoryType_004, TestSize.Level1) 1239 { 1240 capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE; 1241 align_ = 0; 1242 CreateRemoteSurfaceMemByParcel(); 1243 ASSERT_FALSE((remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 1244 GetRemoteBuffer(); 1245 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1246 ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId()); 1247 EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::SURFACE_MEMORY); 1248 } 1249 1250 /** 1251 * @tc.name: AVBuffer_SurfaceMemory_GetFileDescriptor_001 1252 * @tc.desc: surface memory get memory file descriptor 1253 * @tc.type: FUNC 1254 */ 1255 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_GetFileDescriptor_001, TestSize.Level1) 1256 { 1257 capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE; 1258 align_ = 0; 1259 CreateLocalSurfaceMem(); 1260 ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1261 EXPECT_GT(buffer_->memory_->GetFileDescriptor(), 0); 1262 } 1263 1264 /** 1265 * @tc.name: AVBuffer_SurfaceMemory_GetFileDescriptor_002 1266 * @tc.desc: surface memory get memory file descriptor after reading parcel 1267 * @tc.type: FUNC 1268 */ 1269 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_GetFileDescriptor_002, TestSize.Level1) 1270 { 1271 capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE; 1272 align_ = 0; 1273 CreateRemoteSurfaceMem(); 1274 ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 1275 GetRemoteBuffer(); 1276 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1277 ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId()); 1278 EXPECT_GT(buffer_->memory_->GetFileDescriptor(), 0); 1279 } 1280 1281 /** 1282 * @tc.name: AVBuffer_SurfaceMemory_GetFileDescriptor_003 1283 * @tc.desc: surface memory get memory file descriptor with parcel getting from SurfaceBuffer 1284 * @tc.type: FUNC 1285 */ 1286 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_GetFileDescriptor_003, TestSize.Level1) 1287 { 1288 capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE; 1289 align_ = 0; 1290 CreateLocalSurfaceMemByParcel(); 1291 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1292 EXPECT_GT(buffer_->memory_->GetFileDescriptor(), 0); 1293 } 1294 1295 /** 1296 * @tc.name: AVBuffer_SurfaceMemory_GetFileDescriptor_004 1297 * @tc.desc: 1. create surface memory with parcel getting from SurfaceBuffer 1298 * 2. surface memory get memory file descriptor after reading parcel 1299 * @tc.type: FUNC 1300 */ 1301 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_GetFileDescriptor_004, TestSize.Level1) 1302 { 1303 capacity_ = DEFAULT_CONFIG.width * DEFAULT_CONFIG.height * DEFAULT_PIXELSIZE; 1304 align_ = 0; 1305 CreateRemoteSurfaceMemByParcel(); 1306 ASSERT_FALSE((remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 1307 GetRemoteBuffer(); 1308 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1309 ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId()); 1310 EXPECT_GT(buffer_->memory_->GetFileDescriptor(), 0); 1311 } 1312 1313 /** 1314 * @tc.name: AVBuffer_SurfaceMemory_Reset_001 1315 * @tc.desc: surface memory reset 1316 * @tc.type: FUNC 1317 */ 1318 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_Reset_001, TestSize.Level1) 1319 { 1320 capacity_ = MEMSIZE; 1321 align_ = 0; 1322 CreateLocalSurfaceMem(); 1323 ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1324 buffer_->memory_->SetSize(MEMSIZE); 1325 EXPECT_EQ(buffer_->memory_->size_, MEMSIZE); 1326 buffer_->memory_->Reset(); 1327 EXPECT_EQ(buffer_->memory_->size_, 0); 1328 } 1329 1330 /** 1331 * @tc.name: AVBuffer_SurfaceMemory_Reset_002 1332 * @tc.desc: surface memory reset after reading parcel 1333 * @tc.type: FUNC 1334 */ 1335 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_Reset_002, TestSize.Level1) 1336 { 1337 capacity_ = MEMSIZE; 1338 align_ = 0; 1339 CreateRemoteSurfaceMem(); 1340 ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 1341 remoteBuffer_->memory_->SetSize(MEMSIZE); 1342 EXPECT_EQ(remoteBuffer_->memory_->size_, MEMSIZE); 1343 remoteBuffer_->memory_->Reset(); 1344 EXPECT_EQ(remoteBuffer_->memory_->size_, 0); 1345 GetRemoteBuffer(); 1346 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1347 ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId()); 1348 buffer_->memory_->Reset(); 1349 EXPECT_EQ(buffer_->memory_->size_, 0); 1350 } 1351 1352 /** 1353 * @tc.name: AVBuffer_SurfaceMemory_Reset_003 1354 * @tc.desc: surface memory reset with parcel getting from SurfaceBuffer 1355 * @tc.type: FUNC 1356 */ 1357 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_Reset_003, TestSize.Level1) 1358 { 1359 capacity_ = MEMSIZE; 1360 align_ = 0; 1361 CreateLocalSurfaceMemByParcel(); 1362 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1363 buffer_->memory_->SetSize(MEMSIZE); 1364 EXPECT_EQ(buffer_->memory_->size_, MEMSIZE); 1365 buffer_->memory_->Reset(); 1366 EXPECT_EQ(buffer_->memory_->size_, 0); 1367 } 1368 1369 /** 1370 * @tc.name: AVBuffer_SurfaceMemory_Reset_004 1371 * @tc.desc: 1. create surface memory with parcel getting from SurfaceBuffer 1372 * 2. surface memory reset after reading parcel 1373 * @tc.type: FUNC 1374 */ 1375 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_Reset_004, TestSize.Level1) 1376 { 1377 capacity_ = MEMSIZE; 1378 align_ = 0; 1379 CreateRemoteSurfaceMemByParcel(); 1380 ASSERT_FALSE((remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 1381 remoteBuffer_->memory_->SetSize(MEMSIZE); 1382 EXPECT_EQ(remoteBuffer_->memory_->size_, MEMSIZE); 1383 remoteBuffer_->memory_->Reset(); 1384 EXPECT_EQ(remoteBuffer_->memory_->size_, 0); 1385 GetRemoteBuffer(); 1386 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1387 ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId()); 1388 buffer_->memory_->Reset(); 1389 EXPECT_EQ(buffer_->memory_->size_, 0); 1390 } 1391 1392 /** 1393 * @tc.name: AVBuffer_SurfaceMemory_ReadFromMessageParcel_001 1394 * @tc.desc: surface memory read from message parcel 1395 * @tc.type: FUNC 1396 */ 1397 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_SurfaceMemory_ReadFromMessageParcel_001, TestSize.Level1) 1398 { 1399 capacity_ = MEMSIZE; 1400 align_ = 0; 1401 CreateRemoteSurfaceMem(); 1402 CheckAttrTrans(); 1403 } 1404 1405 /** 1406 * @tc.name: AVBuffer_Create_Local_HardwareMemory_001 1407 * @tc.desc: create local hardware memory 1408 * @tc.type: FUNC 1409 */ 1410 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Create_Local_HardwareMemory_001, TestSize.Level1) 1411 { 1412 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 1413 capacity_ = MEMSIZE; 1414 align_ = 0; 1415 CreateLocalHardwareMem(); 1416 ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1417 int32_t offset = static_cast<size_t>( 1418 AlignUp(reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()), static_cast<uintptr_t>(align_)) - 1419 reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr())); 1420 EXPECT_EQ(std::static_pointer_cast<AVHardwareMemory>(buffer_->memory_)->allocator_->GetMemoryType(), 1421 MemoryType::HARDWARE_MEMORY); 1422 EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::HARDWARE_MEMORY); 1423 EXPECT_EQ(buffer_->memory_->capacity_, capacity_); 1424 EXPECT_EQ(buffer_->memory_->offset_, offset); 1425 EXPECT_EQ(std::static_pointer_cast<AVHardwareAllocator>(allocator_)->memFlag_, memFlag_); 1426 } 1427 1428 /** 1429 * @tc.name: AVBuffer_Create_Local_HardwareMemory_002 1430 * @tc.desc: create local hardware memory with config struct 1431 * @tc.type: FUNC 1432 */ 1433 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Create_Local_HardwareMemory_002, TestSize.Level1) 1434 { 1435 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 1436 capacity_ = MEMSIZE; 1437 align_ = 0; 1438 CreateLocalHardwareMemByConfig(); 1439 int32_t offset = static_cast<size_t>( 1440 AlignUp(reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()), static_cast<uintptr_t>(align_)) - 1441 reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr())); 1442 EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::HARDWARE_MEMORY); 1443 EXPECT_EQ(buffer_->memory_->capacity_, capacity_); 1444 EXPECT_EQ(buffer_->memory_->offset_, offset); 1445 } 1446 1447 /** 1448 * @tc.name: AVBuffer_HardwareMemory_GetConfig_001 1449 * @tc.desc: create local hardware memory, and get config 1450 * @tc.type: FUNC 1451 */ 1452 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_HardwareMemory_GetConfig_001, TestSize.Level1) 1453 { 1454 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 1455 capacity_ = MEMSIZE; 1456 CreateLocalHardwareMem(); 1457 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1458 AVBufferConfig config = buffer_->GetConfig(); 1459 EXPECT_EQ(config.memoryType, MemoryType::HARDWARE_MEMORY); 1460 EXPECT_EQ(config.memoryFlag, memFlag_); 1461 EXPECT_EQ(config.capacity, capacity_); 1462 } 1463 1464 /** 1465 * @tc.name: AVBuffer_Create_Remote_HardwareMemory_001 1466 * @tc.desc: create remote hardware memory after reading parcel 1467 * @tc.type: FUNC 1468 */ 1469 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Create_Remote_HardwareMemory_001, TestSize.Level1) 1470 { 1471 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 1472 capacity_ = MEMSIZE; 1473 align_ = 0; 1474 CreateRemoteHardwareMem(); 1475 ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 1476 GetRemoteBuffer(); 1477 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1478 ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId()); 1479 int32_t offset = static_cast<size_t>( 1480 AlignUp(reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()), static_cast<uintptr_t>(align_)) - 1481 reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr())); 1482 EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::HARDWARE_MEMORY); 1483 EXPECT_EQ(buffer_->memory_->capacity_, capacity_); 1484 EXPECT_EQ(buffer_->memory_->offset_, offset); 1485 EXPECT_EQ(std::static_pointer_cast<AVHardwareAllocator>(allocator_)->memFlag_, memFlag_); 1486 EXPECT_GT(std::static_pointer_cast<AVHardwareMemory>(buffer_->memory_)->fd_, 0); 1487 } 1488 1489 /** 1490 * @tc.name: AVBuffer_HardwareMemory_SetParams_001 1491 * @tc.desc: hardware memory set params 1492 * @tc.type: FUNC 1493 */ 1494 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_HardwareMemory_SetParams_001, TestSize.Level1) 1495 { 1496 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 1497 capacity_ = MEMSIZE; 1498 align_ = 0; 1499 CreateLocalHardwareMem(); 1500 ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1501 CheckMetaSetAndGet(); 1502 } 1503 1504 /** 1505 * @tc.name: AVBuffer_HardwareMemory_SetParams_002 1506 * @tc.desc: hardware memory set params after reading parcel 1507 * @tc.type: FUNC 1508 */ 1509 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_HardwareMemory_SetParams_002, TestSize.Level1) 1510 { 1511 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 1512 capacity_ = MEMSIZE; 1513 align_ = 0; 1514 CreateRemoteHardwareMem(); 1515 ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 1516 CheckMetaSetAndGet(); 1517 } 1518 1519 /** 1520 * @tc.name: AVBuffer_HardwareMemory_WriteAndRead_001 1521 * @tc.desc: hardware memory write and read 1522 * @tc.type: FUNC 1523 */ 1524 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_HardwareMemory_WriteAndRead_001, TestSize.Level1) 1525 { 1526 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 1527 capacity_ = MEMSIZE; 1528 align_ = 0; 1529 CreateLocalHardwareMem(); 1530 ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1531 CheckMemTrans(); 1532 } 1533 1534 /** 1535 * @tc.name: AVBuffer_HardwareMemory_WriteAndRead_002 1536 * @tc.desc: hardware memory write and read after reading parcel 1537 * @tc.type: FUNC 1538 */ 1539 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_HardwareMemory_WriteAndRead_002, TestSize.Level1) 1540 { 1541 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 1542 capacity_ = MEMSIZE; 1543 align_ = 0; 1544 CreateRemoteHardwareMem(); 1545 ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 1546 CheckMemTrans(); 1547 } 1548 1549 /** 1550 * @tc.name: AVBuffer_HardwareMemory_WriteAndRead_003 1551 * @tc.desc: hardware memory write and read with valid position after reading parcel 1552 * @tc.type: FUNC 1553 */ 1554 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_HardwareMemory_WriteAndRead_003, TestSize.Level1) 1555 { 1556 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 1557 capacity_ = MEMSIZE; 1558 align_ = 0; 1559 CreateRemoteHardwareMem(); 1560 ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 1561 CheckMemTransPos(POSITION_ONE); 1562 } 1563 1564 /** 1565 * @tc.name: AVBuffer_HardwareMemory_WriteAndRead_004 1566 * @tc.desc: hardware memory write and read with invalid position after reading parcel 1567 * @tc.type: FUNC 1568 */ 1569 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_HardwareMemory_WriteAndRead_004, TestSize.Level1) 1570 { 1571 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 1572 capacity_ = MEMSIZE; 1573 align_ = 0; 1574 CreateRemoteHardwareMem(); 1575 ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 1576 CheckMemTransOutOfRange(POSITION_ONE); 1577 } 1578 1579 /** 1580 * @tc.name: AVBuffer_HardwareMemory_GetCapacity_001 1581 * @tc.desc: hardware memory get capacity 1582 * @tc.type: FUNC 1583 */ 1584 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_HardwareMemory_GetCapacity_001, TestSize.Level1) 1585 { 1586 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 1587 capacity_ = MEMSIZE; 1588 align_ = 0; 1589 CreateLocalHardwareMem(); 1590 ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1591 EXPECT_EQ(buffer_->memory_->GetCapacity(), capacity_); 1592 } 1593 1594 /** 1595 * @tc.name: AVBuffer_HardwareMemory_GetCapacity_002 1596 * @tc.desc: hardware memory get capacity after reading parcel 1597 * @tc.type: FUNC 1598 */ 1599 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_HardwareMemory_GetCapacity_002, TestSize.Level1) 1600 { 1601 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 1602 capacity_ = MEMSIZE; 1603 align_ = 0; 1604 CreateRemoteHardwareMem(); 1605 ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 1606 GetRemoteBuffer(); 1607 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1608 ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId()); 1609 EXPECT_EQ(buffer_->memory_->GetCapacity(), capacity_); 1610 } 1611 1612 /** 1613 * @tc.name: AVBuffer_HardwareMemory_CheckDataSize_001 1614 * @tc.desc: hardware memory check dataSize 1615 * @tc.type: FUNC 1616 */ 1617 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_HardwareMemory_CheckDataSize_001, TestSize.Level1) 1618 { 1619 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 1620 capacity_ = MEMSIZE; 1621 align_ = 0; 1622 CreateLocalHardwareMem(); 1623 ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1624 CheckDataSize(); 1625 } 1626 1627 /** 1628 * @tc.name: AVBuffer_HardwareMemory_CheckDataSize_002 1629 * @tc.desc: hardware memory check dataSize after reading parcel 1630 * @tc.type: FUNC 1631 */ 1632 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_HardwareMemory_CheckDataSize_002, TestSize.Level1) 1633 { 1634 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 1635 capacity_ = MEMSIZE; 1636 align_ = 0; 1637 CreateRemoteHardwareMem(); 1638 ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 1639 CheckDataSize(); 1640 } 1641 1642 /** 1643 * @tc.name: AVBuffer_HardwareMemory_GetMemoryType_001 1644 * @tc.desc: hardware memory get memory type 1645 * @tc.type: FUNC 1646 */ 1647 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_HardwareMemory_GetMemoryType_001, TestSize.Level1) 1648 { 1649 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 1650 capacity_ = MEMSIZE; 1651 align_ = 0; 1652 CreateLocalHardwareMem(); 1653 ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1654 EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::HARDWARE_MEMORY); 1655 } 1656 1657 /** 1658 * @tc.name: AVBuffer_HardwareMemory_GetMemoryType_002 1659 * @tc.desc: hardware memory get memory type after reading parcel 1660 * @tc.type: FUNC 1661 */ 1662 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_HardwareMemory_GetMemoryType_002, TestSize.Level1) 1663 { 1664 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 1665 capacity_ = MEMSIZE; 1666 align_ = 0; 1667 CreateRemoteHardwareMem(); 1668 ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 1669 GetRemoteBuffer(); 1670 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1671 ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId()); 1672 EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::HARDWARE_MEMORY); 1673 } 1674 1675 /** 1676 * @tc.name: AVBuffer_HardwareMemory_GetFileDescriptor_001 1677 * @tc.desc: hardware memory get file descriptor 1678 * @tc.type: FUNC 1679 */ 1680 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_HardwareMemory_GetFileDescriptor_001, TestSize.Level1) 1681 { 1682 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 1683 capacity_ = MEMSIZE; 1684 align_ = 0; 1685 CreateLocalHardwareMem(); 1686 ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1687 EXPECT_GT(buffer_->memory_->GetFileDescriptor(), 0); 1688 } 1689 1690 /** 1691 * @tc.name: AVBuffer_HardwareMemory_GetFileDescriptor_002 1692 * @tc.desc: hardware memory get file descriptor after reading parcel 1693 * @tc.type: FUNC 1694 */ 1695 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_HardwareMemory_GetFileDescriptor_002, TestSize.Level1) 1696 { 1697 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 1698 capacity_ = MEMSIZE; 1699 align_ = 0; 1700 CreateRemoteHardwareMem(); 1701 ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 1702 GetRemoteBuffer(); 1703 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1704 ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId()); 1705 EXPECT_GT(buffer_->memory_->GetFileDescriptor(), 0); 1706 } 1707 1708 /** 1709 * @tc.name: AVBuffer_HardwareMemory_GetFileDescriptor_003 1710 * @tc.desc: hardware memory get file descriptor 1711 * @tc.type: FUNC 1712 */ 1713 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_HardwareMemory_GetFileDescriptor_003, TestSize.Level1) 1714 { 1715 capacity_ = MEMSIZE; 1716 align_ = 0; 1717 CreateLocalHardwareMemSecure(); 1718 ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1719 EXPECT_GT(buffer_->memory_->GetFileDescriptor(), 0); 1720 MessageParcel parcel; 1721 EXPECT_FALSE(buffer_->WriteToMessageParcel(parcel)); 1722 } 1723 1724 /** 1725 * @tc.name: AVBuffer_HardwareMemory_Reset_001 1726 * @tc.desc: hardware memory reset 1727 * @tc.type: FUNC 1728 */ 1729 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_HardwareMemory_Reset_001, TestSize.Level1) 1730 { 1731 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 1732 capacity_ = MEMSIZE; 1733 align_ = 0; 1734 CreateLocalHardwareMem(); 1735 ASSERT_FALSE((allocator_ == nullptr) || (buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1736 buffer_->memory_->SetSize(MEMSIZE); 1737 EXPECT_EQ(buffer_->memory_->size_, MEMSIZE); 1738 buffer_->memory_->Reset(); 1739 EXPECT_EQ(buffer_->memory_->size_, 0); 1740 } 1741 1742 /** 1743 * @tc.name: AVBuffer_HardwareMemory_Reset_002 1744 * @tc.desc: hardware memory reset after reading parcel 1745 * @tc.type: FUNC 1746 */ 1747 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_HardwareMemory_Reset_002, TestSize.Level1) 1748 { 1749 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 1750 capacity_ = MEMSIZE; 1751 align_ = 0; 1752 CreateRemoteHardwareMem(); 1753 ASSERT_FALSE((allocator_ == nullptr) || (remoteBuffer_ == nullptr) || (remoteBuffer_->memory_ == nullptr)); 1754 remoteBuffer_->memory_->SetSize(MEMSIZE); 1755 EXPECT_EQ(remoteBuffer_->memory_->size_, MEMSIZE); 1756 remoteBuffer_->memory_->Reset(); 1757 EXPECT_EQ(remoteBuffer_->memory_->size_, 0); 1758 GetRemoteBuffer(); 1759 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1760 ASSERT_EQ(remoteBuffer_->GetUniqueId(), buffer_->GetUniqueId()); 1761 buffer_->memory_->Reset(); 1762 EXPECT_EQ(buffer_->memory_->size_, 0); 1763 } 1764 1765 /** 1766 * @tc.name: AVBuffer_HardwareMemory_ReadFromMessageParcel_001 1767 * @tc.desc: hardware memory read from message parcel 1768 * @tc.type: FUNC 1769 */ 1770 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_HardwareMemory_ReadFromMessageParcel_001, TestSize.Level1) 1771 { 1772 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 1773 capacity_ = MEMSIZE; 1774 align_ = 0; 1775 CreateRemoteHardwareMem(); 1776 CheckAttrTrans(); 1777 } 1778 1779 /** 1780 * @tc.name: AVBuffer_Create_Local_VirtualMemory_001 1781 * @tc.desc: create local virtual memory 1782 * @tc.type: FUNC 1783 */ 1784 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Create_Local_VirtualMemory_001, TestSize.Level1) 1785 { 1786 capacity_ = MEMSIZE; 1787 align_ = 0; 1788 CreateLocalVirtualMem(); 1789 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1790 int32_t offset = static_cast<size_t>( 1791 AlignUp(reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()), static_cast<uintptr_t>(align_)) - 1792 reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr())); 1793 EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::VIRTUAL_MEMORY); 1794 EXPECT_EQ(buffer_->memory_->capacity_, capacity_); 1795 EXPECT_EQ(buffer_->memory_->offset_, offset); 1796 } 1797 1798 /** 1799 * @tc.name: AVBuffer_Create_Local_VirtualMemory_002 1800 * @tc.desc: create local virtual memory with no parameters 1801 * @tc.type: FUNC 1802 */ 1803 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Create_Local_VirtualMemory_002, TestSize.Level1) 1804 { 1805 CreateLocalNullMem(); 1806 ASSERT_NE(nullptr, remoteBuffer_); 1807 ASSERT_NE(nullptr, remoteBuffer_->meta_); 1808 ASSERT_EQ(nullptr, remoteBuffer_->memory_); 1809 remoteBuffer_->pts_ = DEFAULT_PTS; 1810 remoteBuffer_->dts_ = DEFAULT_DTS; 1811 remoteBuffer_->duration_ = DEFAULT_DURATION; 1812 remoteBuffer_->flag_ = DEFAULT_FLAG; 1813 1814 GetRemoteBuffer(); 1815 ASSERT_NE(nullptr, buffer_); 1816 ASSERT_NE(nullptr, buffer_->meta_); 1817 ASSERT_EQ(nullptr, buffer_->memory_); 1818 EXPECT_EQ(remoteBuffer_->pts_, buffer_->pts_); 1819 EXPECT_EQ(remoteBuffer_->dts_, buffer_->dts_); 1820 EXPECT_EQ(remoteBuffer_->duration_, buffer_->duration_); 1821 EXPECT_EQ(remoteBuffer_->flag_, buffer_->flag_); 1822 } 1823 1824 /** 1825 * @tc.name: AVBuffer_Create_Local_VirtualMemory_003 1826 * @tc.desc: create local virtual memory with pointer 1827 * @tc.type: FUNC 1828 */ 1829 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Create_Local_VirtualMemory_003, TestSize.Level1) 1830 { 1831 // create loacal 1832 capacity_ = MEMSIZE; 1833 uint8_t *array = new uint8_t[capacity_]; 1834 auto error = memcpy_s(array, capacity_, inputBuffer_.data(), capacity_); 1835 ASSERT_EQ(error, EOK); 1836 buffer_ = AVBuffer::CreateAVBuffer(array, capacity_, capacity_); 1837 ASSERT_NE(nullptr, buffer_); 1838 ASSERT_NE(nullptr, buffer_->memory_); 1839 ASSERT_NE(nullptr, buffer_->memory_->GetAddr()); 1840 uint8_t *addr = buffer_->memory_->GetAddr(); 1841 ASSERT_NE(addr, nullptr); 1842 EXPECT_EQ(memcmp(static_cast<void *>(addr), inputBuffer_.data(), capacity_), 0); 1843 // write and read 1844 outputBuffer_.resize(MEMSIZE, 0); 1845 EXPECT_EQ(buffer_->memory_->Read(outputBuffer_.data(), capacity_, 0), capacity_); 1846 EXPECT_EQ(buffer_->memory_->GetSize(), capacity_); 1847 EXPECT_EQ(memcmp(inputBuffer_.data(), outputBuffer_.data(), capacity_), 0); 1848 EXPECT_EQ(memcmp(static_cast<void *>(addr), inputBuffer_.data(), capacity_), 0); 1849 EXPECT_EQ(memcmp(static_cast<void *>(addr), outputBuffer_.data(), capacity_), 0); 1850 delete[] array; 1851 } 1852 1853 /** 1854 * @tc.name: AVBuffer_Create_Local_VirtualMemory_004 1855 * @tc.desc: create local virtual memory with config struct 1856 * @tc.type: FUNC 1857 */ 1858 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_Create_Local_VirtualMemory_004, TestSize.Level1) 1859 { 1860 capacity_ = MEMSIZE; 1861 align_ = 0; 1862 CreateLocalVirtualMemByConfig(); 1863 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1864 int32_t offset = static_cast<size_t>( 1865 AlignUp(reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr()), static_cast<uintptr_t>(align_)) - 1866 reinterpret_cast<uintptr_t>(buffer_->memory_->GetAddr())); 1867 EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::VIRTUAL_MEMORY); 1868 EXPECT_EQ(buffer_->memory_->capacity_, capacity_); 1869 EXPECT_EQ(buffer_->memory_->offset_, offset); 1870 } 1871 1872 /** 1873 * @tc.name: AVBuffer_VirtualMemory_GetConfig_001 1874 * @tc.desc: create local virtual memory, and get config 1875 * @tc.type: FUNC 1876 */ 1877 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_VirtualMemory_GetConfig_001, TestSize.Level1) 1878 { 1879 capacity_ = MEMSIZE; 1880 align_ = 1; 1881 CreateLocalVirtualMem(); 1882 AVBufferConfig config = buffer_->GetConfig(); 1883 EXPECT_EQ(config.memoryType, MemoryType::VIRTUAL_MEMORY); 1884 EXPECT_EQ(config.capacity, capacity_); 1885 EXPECT_EQ(config.align, align_); 1886 } 1887 1888 /** 1889 * @tc.name: AVBuffer_VirtualMemory_SetParams_001 1890 * @tc.desc: virtual memory set params 1891 * @tc.type: FUNC 1892 */ 1893 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_VirtualMemory_SetParams_001, TestSize.Level1) 1894 { 1895 capacity_ = MEMSIZE; 1896 align_ = 0; 1897 CreateLocalVirtualMem(); 1898 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1899 CheckMetaSetAndGet(); 1900 } 1901 1902 /** 1903 * @tc.name: AVBuffer_VirtualMemory_WriteAndRead_001 1904 * @tc.desc: virtual memory write and read 1905 * @tc.type: FUNC 1906 */ 1907 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_VirtualMemory_WriteAndRead_001, TestSize.Level1) 1908 { 1909 capacity_ = MEMSIZE; 1910 align_ = 0; 1911 CreateLocalVirtualMem(); 1912 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1913 CheckMemTrans(); 1914 } 1915 1916 /** 1917 * @tc.name: AVBuffer_VirtualMemory_GetCapacity_001 1918 * @tc.desc: virtual memory get capacity 1919 * @tc.type: FUNC 1920 */ 1921 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_VirtualMemory_GetCapacity_001, TestSize.Level1) 1922 { 1923 capacity_ = MEMSIZE; 1924 align_ = 0; 1925 CreateLocalVirtualMem(); 1926 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1927 EXPECT_EQ(buffer_->memory_->GetCapacity(), capacity_); 1928 } 1929 1930 /** 1931 * @tc.name: AVBuffer_VirtualMemory_CheckDataSize_001 1932 * @tc.desc: virtual memory check dataSize 1933 * @tc.type: FUNC 1934 */ 1935 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_VirtualMemory_CheckDataSize_001, TestSize.Level1) 1936 { 1937 capacity_ = MEMSIZE; 1938 align_ = 0; 1939 CreateLocalVirtualMem(); 1940 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1941 CheckDataSize(); 1942 } 1943 1944 /** 1945 * @tc.name: AVBuffer_VirtualMemory_GetMemoryType_001 1946 * @tc.desc: virtual memory get memory type 1947 * @tc.type: FUNC 1948 */ 1949 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_VirtualMemory_GetMemoryType_001, TestSize.Level1) 1950 { 1951 capacity_ = MEMSIZE; 1952 align_ = 0; 1953 CreateLocalVirtualMem(); 1954 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1955 EXPECT_EQ(buffer_->memory_->GetMemoryType(), MemoryType::VIRTUAL_MEMORY); 1956 } 1957 1958 /** 1959 * @tc.name: AVBuffer_VirtualMemory_GetFileDescriptor_001 1960 * @tc.desc: virtual memory get memory file descriptor 1961 * @tc.type: FUNC 1962 */ 1963 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_VirtualMemory_GetFileDescriptor_001, TestSize.Level1) 1964 { 1965 capacity_ = MEMSIZE; 1966 align_ = 0; 1967 CreateLocalVirtualMem(); 1968 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1969 EXPECT_EQ(buffer_->memory_->GetFileDescriptor(), -1); 1970 } 1971 1972 /** 1973 * @tc.name: AVBuffer_VirtualMemory_Reset_001 1974 * @tc.desc: virtual memory reset 1975 * @tc.type: FUNC 1976 */ 1977 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_VirtualMemory_Reset_001, TestSize.Level1) 1978 { 1979 memFlag_ = MemoryFlag::MEMORY_READ_WRITE; 1980 capacity_ = MEMSIZE; 1981 align_ = 0; 1982 CreateLocalVirtualMem(); 1983 ASSERT_FALSE((buffer_ == nullptr) || (buffer_->memory_ == nullptr)); 1984 buffer_->memory_->SetSize(MEMSIZE); 1985 EXPECT_EQ(buffer_->memory_->size_, MEMSIZE); 1986 buffer_->memory_->Reset(); 1987 EXPECT_EQ(buffer_->memory_->size_, 0); 1988 } 1989 1990 /** 1991 * @tc.name: AVBuffer_VirtualMemory_ReadFromMessageParcel_001 1992 * @tc.desc: null memory read from message parcel 1993 * @tc.type: FUNC 1994 */ 1995 HWTEST_F(AVBufferInnerUnitTest, AVBuffer_VirtualMemory_ReadFromMessageParcel_001, TestSize.Level1) 1996 { 1997 CreateLocalNullMem(); 1998 CreateRemoteHardwareMem(); 1999 CheckAttrTrans(); 2000 } 2001 } // namespace AVBufferUT 2002 } // namespace Media 2003 } // namespace OHOS