blob: d6407820ffc8abee49e9bef4646b46c6f3af98fe [file] [log] [blame]
Jim Shargo550dbaa2024-07-22 22:19:55 +00001/*
2 * Copyright (C) 2024 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <gtest/gtest.h>
18
19#include <SurfaceFlingerProperties.h>
20#include <android/gui/IDisplayEventConnection.h>
21#include <android/gui/ISurfaceComposer.h>
22#include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h>
23#include <android/hardware_buffer.h>
24#include <binder/ProcessState.h>
25#include <com_android_graphics_libgui_flags.h>
26#include <configstore/Utils.h>
Alec Mouri924f9502024-08-15 20:01:08 +000027#include <gui/AidlUtil.h>
Jim Shargo550dbaa2024-07-22 22:19:55 +000028#include <gui/BufferItemConsumer.h>
29#include <gui/BufferQueue.h>
30#include <gui/CpuConsumer.h>
31#include <gui/IConsumerListener.h>
32#include <gui/IGraphicBufferConsumer.h>
33#include <gui/IGraphicBufferProducer.h>
34#include <gui/ISurfaceComposer.h>
35#include <gui/Surface.h>
36#include <gui/SurfaceComposerClient.h>
37#include <gui/SyncScreenCaptureListener.h>
38#include <private/gui/ComposerService.h>
39#include <private/gui/ComposerServiceAIDL.h>
40#include <sys/types.h>
41#include <system/window.h>
42#include <ui/BufferQueueDefs.h>
43#include <ui/DisplayMode.h>
44#include <ui/GraphicBuffer.h>
45#include <ui/Rect.h>
46#include <utils/Errors.h>
47#include <utils/String8.h>
48
49#include <cstddef>
50#include <limits>
51#include <thread>
52
53#include "binder/IInterface.h"
54#include "testserver/TestServerClient.h"
55
56namespace android {
57
58namespace {
59
60class TestServerTest : public ::testing::Test {
61protected:
62 TestServerTest() { ProcessState::self()->startThreadPool(); }
63};
64
65} // namespace
66
67TEST_F(TestServerTest, Create) {
68 EXPECT_NE(nullptr, TestServerClient::Create());
69}
70
71TEST_F(TestServerTest, CreateProducer) {
72 sp<TestServerClient> client = TestServerClient::Create();
73 EXPECT_NE(nullptr, client->CreateProducer());
74}
75
76TEST_F(TestServerTest, KillServer) {
77 class DeathWaiter : public IBinder::DeathRecipient {
78 public:
79 virtual void binderDied(const wp<IBinder>&) override { mPromise.set_value(true); }
80 std::future<bool> getFuture() { return mPromise.get_future(); }
81
82 std::promise<bool> mPromise;
83 };
84
85 sp<TestServerClient> client = TestServerClient::Create();
86 sp<IGraphicBufferProducer> producer = client->CreateProducer();
87 EXPECT_NE(nullptr, producer);
88
89 sp<DeathWaiter> deathWaiter = sp<DeathWaiter>::make();
90 EXPECT_EQ(OK, IInterface::asBinder(producer)->linkToDeath(deathWaiter));
91
92 auto deathWaiterFuture = deathWaiter->getFuture();
93 EXPECT_EQ(OK, client->Kill());
94 EXPECT_EQ(nullptr, client->CreateProducer());
95
96 EXPECT_TRUE(deathWaiterFuture.get());
97}
98
99} // namespace android