• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "fence_fd_test.h"
17 
18 #include <chrono>
19 #include <sys/stat.h>
20 #include <unistd.h>
21 #include <thread>
22 
23 #include <linux/sync_file.h>
24 #include "test_header.h"
25 
26 namespace OHOS {
SetUpTestCase()27 void FenceFdTest::SetUpTestCase()
28 {
29 }
30 
TearDownTestCase()31 void FenceFdTest::TearDownTestCase()
32 {
33     csurf = nullptr;
34     producer = nullptr;
35     psurf = nullptr;
36 }
37 
OnBufferAvailable()38 void FenceFdTest::OnBufferAvailable()
39 {
40 }
41 
42 namespace {
43 HWTEST_F(FenceFdTest, BufferQueueFenceItem, testing::ext::TestSize.Level0) {
44     PART("EnvConditions") {
45         STEP("surf create success.") {
46             csurf = IConsumerSurface::Create();
47             STEP_ASSERT_NE(csurf, nullptr);
48             csurf->RegisterConsumerListener(this);
49             producer = csurf->GetProducer();
50             STEP_ASSERT_NE(producer, nullptr);
51             psurf = Surface::CreateSurfaceAsProducer(producer);
52             STEP_ASSERT_NE(psurf, nullptr);
53         }
54     }
55 
56     PART("CaseDescription") {
57         sptr<SurfaceBuffer> buffer = nullptr;
58         int32_t releaseFence = 0;
59         GSError ret = GSERROR_INTERNAL;
60 
61         STEP("1. Check release fence fd") {
62             ret = psurf->RequestBuffer(buffer, releaseFence, requestConfig);
63             STEP_ASSERT_EQ(ret, GSERROR_OK);
64             STEP_ASSERT_EQ(releaseFence, -1);
65             STEP_ASSERT_NE(buffer, nullptr);
66         }
67 
68         STEP("2. Check acquire fence from FlushBuffer to AcquireBuffer") {
69             int32_t acquireFence = 1;
70             ret = psurf->FlushBuffer(buffer, acquireFence, flushConfig);
71             STEP_ASSERT_EQ(ret, GSERROR_OK);
72 
73             int32_t outAcquireFence = 0;
74             ret = csurf->AcquireBuffer(buffer, outAcquireFence, timestamp, damage);
75             STEP_ASSERT_EQ(ret, GSERROR_OK);
76             STEP_ASSERT_EQ(outAcquireFence, acquireFence);
77         }
78 
79         STEP("3. Check this release fence and the release fence of the next RequestBuffer") {
80             int32_t newReleaseFence = 2;
81             ret = csurf->ReleaseBuffer(buffer, newReleaseFence);
82             STEP_ASSERT_EQ(ret, GSERROR_OK);
83 
84             int32_t outReleaseFence = 0;
85             ret = psurf->RequestBuffer(buffer, outReleaseFence, requestConfig);
86             STEP_ASSERT_EQ(ret, GSERROR_OK);
87             STEP_ASSERT_NE(buffer, nullptr);
88             STEP_ASSERT_EQ(outReleaseFence, newReleaseFence);
89         }
90     }
91 }
92 } // namespace
93 } // namespace OHOS
94