/* * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include #include "buffer_consumer_listener.h" #include "buffer_extra_data_impl.h" #include "sync_fence.h" using namespace testing; using namespace testing::ext; namespace OHOS::Rosen { class BufferQueueConsumerTest : public testing::Test { public: static void SetUpTestCase(); static void TearDownTestCase(); static inline BufferRequestConfig requestConfig = { .width = 0x100, .height = 0x100, .strideAlignment = 0x8, .format = GRAPHIC_PIXEL_FMT_RGBA_8888, .usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA, .timeout = 0, }; static inline BufferFlushConfigWithDamages flushConfig = { .damages = { { .w = 0x100, .h = 0x100, } }, }; static inline int64_t timestamp = 0; static inline std::vector damages = {}; static inline sptr bq = nullptr; static inline sptr bqc = nullptr; static inline sptr bedata = nullptr; }; void BufferQueueConsumerTest::SetUpTestCase() { bq = new BufferQueue("test"); bq->Init(); bqc = new BufferQueueConsumer(bq); sptr listener = new BufferConsumerListener(); bqc->RegisterConsumerListener(listener); bedata = new BufferExtraDataImpl; } void BufferQueueConsumerTest::TearDownTestCase() { bq = nullptr; bqc = nullptr; } /* * Function: AcquireBuffer and ReleaseBuffer * Type: Function * Rank: Important(2) * EnvConditions: N/A * CaseDescription: 1. call RequestBuffer and FlushBuffer * 2. call AcquireBuffer and ReleaseBuffer * 3. check ret */ HWTEST_F(BufferQueueConsumerTest, AcqRel001, Function | MediumTest | Level2) { IBufferProducer::RequestBufferReturnValue retval; GSError ret = bq->RequestBuffer(requestConfig, bedata, retval); ASSERT_EQ(ret, OHOS::GSERROR_OK); ASSERT_GE(retval.sequence, 0); ASSERT_NE(retval.buffer, nullptr); uint8_t *addr1 = reinterpret_cast(retval.buffer->GetVirAddr()); ASSERT_NE(addr1, nullptr); sptr acquireFence = SyncFence::INVALID_FENCE; ret = bq->FlushBuffer(retval.sequence, bedata, acquireFence, flushConfig); ASSERT_EQ(ret, OHOS::GSERROR_OK); ret = bqc->AcquireBuffer(retval.buffer, retval.fence, timestamp, damages); ASSERT_EQ(ret, OHOS::GSERROR_OK); sptr releaseFence = SyncFence::INVALID_FENCE; ret = bqc->ReleaseBuffer(retval.buffer, releaseFence); ASSERT_EQ(ret, OHOS::GSERROR_OK); } /* * Function: AcquireBuffer and ReleaseBuffer * Type: Function * Rank: Important(2) * EnvConditions: N/A * CaseDescription: 1. call RequestBuffer and FlushBuffer * 2. call AcquireBuffer and ReleaseBuffer * 3. call ReleaseBuffer again * 4. check ret */ HWTEST_F(BufferQueueConsumerTest, AcqRel002, Function | MediumTest | Level2) { IBufferProducer::RequestBufferReturnValue retval; GSError ret = bq->RequestBuffer(requestConfig, bedata, retval); ASSERT_EQ(ret, OHOS::GSERROR_OK); ASSERT_GE(retval.sequence, 0); ASSERT_EQ(retval.buffer, nullptr); sptr acquireFence = SyncFence::INVALID_FENCE; ret = bq->FlushBuffer(retval.sequence, bedata, acquireFence, flushConfig); ASSERT_EQ(ret, OHOS::GSERROR_OK); sptr& buffer = retval.buffer; ret = bqc->AcquireBuffer(buffer, retval.fence, timestamp, damages); ASSERT_EQ(ret, OHOS::GSERROR_OK); sptr releaseFence = SyncFence::INVALID_FENCE; ret = bqc->ReleaseBuffer(buffer, releaseFence); ASSERT_EQ(ret, OHOS::GSERROR_OK); ret = bqc->ReleaseBuffer(buffer, releaseFence); ASSERT_NE(ret, OHOS::GSERROR_OK); } }