blob: e9b6ba0f64b5d844f85cbcbbc90d738bfa9c5c6f [file] [log] [blame]
Robert Carreb893992017-03-10 13:09:00 -08001/*
2 * Copyright (C) 2017 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
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -080017// TODO(b/129481165): remove the #pragma below and fix conversion issues
18#pragma clang diagnostic push
19#pragma clang diagnostic ignored "-Wconversion"
20
Robert Carreb893992017-03-10 13:09:00 -080021#include <gtest/gtest.h>
22
23#include <gui/SurfaceComposerClient.h>
24
25#include <utils/String8.h>
26
27#include <thread>
28#include <functional>
chaviw7ba019b2018-03-14 13:28:39 -070029#include <layerproto/LayerProtoParser.h>
Robert Carreb893992017-03-10 13:09:00 -080030
31namespace android {
32
33TEST(SurfaceFlingerStress, create_and_destroy) {
34 auto do_stress = []() {
35 sp<SurfaceComposerClient> client = new SurfaceComposerClient;
36 ASSERT_EQ(NO_ERROR, client->initCheck());
37 for (int j = 0; j < 1000; j++) {
38 auto surf = client->createSurface(String8("t"), 100, 100,
39 PIXEL_FORMAT_RGBA_8888, 0);
40 ASSERT_TRUE(surf != nullptr);
Robert Carr87246532019-02-04 15:20:26 -080041 surf.clear();
Robert Carreb893992017-03-10 13:09:00 -080042 }
43 };
44
45 std::vector<std::thread> threads;
46 for (int i = 0; i < 10; i++) {
47 threads.push_back(std::thread(do_stress));
48 }
49 for (auto& thread : threads) {
50 thread.join();
51 }
52}
53
chaviw7ba019b2018-03-14 13:28:39 -070054surfaceflinger::LayersProto generateLayerProto() {
55 surfaceflinger::LayersProto layersProto;
56 std::array<surfaceflinger::LayerProto*, 10> layers = {};
57 for (size_t i = 0; i < layers.size(); ++i) {
58 layers[i] = layersProto.add_layers();
59 layers[i]->set_id(i);
60 }
61
62 layers[0]->add_children(1);
63 layers[1]->set_parent(0);
64 layers[0]->add_children(2);
65 layers[2]->set_parent(0);
66 layers[0]->add_children(3);
67 layers[3]->set_parent(0);
68 layers[2]->add_children(4);
69 layers[4]->set_parent(2);
70 layers[3]->add_children(5);
71 layers[5]->set_parent(3);
72 layers[5]->add_children(6);
73 layers[6]->set_parent(5);
74 layers[5]->add_children(7);
75 layers[7]->set_parent(5);
76 layers[6]->add_children(8);
77 layers[8]->set_parent(6);
78
79 layers[4]->set_z_order_relative_of(3);
80 layers[3]->add_relatives(4);
81 layers[8]->set_z_order_relative_of(9);
82 layers[9]->add_relatives(8);
83 layers[3]->set_z_order_relative_of(1);
84 layers[1]->add_relatives(3);
85
86/* ----------------------------
87 * - 0 - - 9 -
88 * / | \
89 * 1 2 3(1)
90 * | |
91 * 4(3) 5
92 * / \
93 * 6 7
94 * |
95 * 8(9)
96 * -------------------------- */
97
98 return layersProto;
99}
100
101TEST(LayerProtoStress, mem_info) {
102 std::string cmd = "dumpsys meminfo ";
103 cmd += std::to_string(getpid());
104 system(cmd.c_str());
105 for (int i = 0; i < 100000; i++) {
106 surfaceflinger::LayersProto layersProto = generateLayerProto();
107 auto layerTree = surfaceflinger::LayerProtoParser::generateLayerTree(layersProto);
Chia-I Wu2f884132018-09-13 15:17:58 -0700108 surfaceflinger::LayerProtoParser::layerTreeToString(layerTree);
chaviw7ba019b2018-03-14 13:28:39 -0700109 }
110 system(cmd.c_str());
111}
112
Robert Carreb893992017-03-10 13:09:00 -0800113}
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -0800114
115// TODO(b/129481165): remove the #pragma below and fix conversion issues
116#pragma clang diagnostic pop // ignored "-Wconversion"