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 {
45 PART("EnvConditions") {
46 STEP("surf create success.") {
47 csurf = IConsumerSurface::Create();
48 STEP_ASSERT_NE(csurf, nullptr);
49 csurf->RegisterConsumerListener(this);
50 producer = csurf->GetProducer();
51 STEP_ASSERT_NE(producer, nullptr);
52 psurf = Surface::CreateSurfaceAsProducer(producer);
53 STEP_ASSERT_NE(psurf, nullptr);
54 }
55 }
56
57 PART("CaseDescription") {
58 sptr<SurfaceBuffer> buffer = nullptr;
59 int32_t releaseFence = 0;
60 GSError ret = GSERROR_INTERNAL;
61
62 STEP("1. Check release fence fd") {
63 ret = psurf->RequestBuffer(buffer, releaseFence, requestConfig);
64 STEP_ASSERT_EQ(ret, GSERROR_OK);
65 STEP_ASSERT_EQ(releaseFence, -1);
66 STEP_ASSERT_NE(buffer, nullptr);
67 }
68
69 STEP("2. Check acquire fence from FlushBuffer to AcquireBuffer") {
70 int32_t acquireFence = 1;
71 ret = psurf->FlushBuffer(buffer, acquireFence, flushConfig);
72 STEP_ASSERT_EQ(ret, GSERROR_OK);
73
74 int32_t outAcquireFence = 0;
75 ret = csurf->AcquireBuffer(buffer, outAcquireFence, timestamp, damage);
76 STEP_ASSERT_EQ(ret, GSERROR_OK);
77 STEP_ASSERT_EQ(outAcquireFence, acquireFence);
78 }
79
80 STEP("3. Check this release fence and the release fence of the next RequestBuffer") {
81 int32_t newReleaseFence = 2;
82 ret = csurf->ReleaseBuffer(buffer, newReleaseFence);
83 STEP_ASSERT_EQ(ret, GSERROR_OK);
84
85 int32_t outReleaseFence = 0;
86 ret = psurf->RequestBuffer(buffer, outReleaseFence, requestConfig);
87 STEP_ASSERT_EQ(ret, GSERROR_OK);
88 STEP_ASSERT_NE(buffer, nullptr);
89 STEP_ASSERT_EQ(outReleaseFence, newReleaseFence);
90 }
91 }
92 }
93 } // namespace
94 } // namespace OHOS
95