Debian Codegraph @

tests/SurfaceViewBufferTests/src/com/android/test/BufferPresentationTests.kt

raw
1 /*
2 * Copyright (C) 2020 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 package com.android.test
17
18 import com.android.server.wm.flicker.traces.layers.LayersTraceSubject.Companion.assertThat
19 import junit.framework.Assert.assertEquals
20 import junit.framework.Assert.assertTrue
21 import org.junit.Test
22 import org.junit.runner.RunWith
23 import org.junit.runners.Parameterized
24
25 @RunWith(Parameterized::class)
26 class BufferPresentationTests(useBlastAdapter: Boolean) : SurfaceTracingTestBase(useBlastAdapter) {
27 /** Submit buffers as fast as possible and make sure they are presented on display */
28 @Test
29 fun testQueueBuffers() {
30 val numFrames = 100L
31 val trace = withTrace { activity ->
32 for (i in 1..numFrames) {
33 activity.mSurfaceProxy.ANativeWindowLock()
34 activity.mSurfaceProxy.ANativeWindowUnlockAndPost()
35 }
36 assertEquals(0, activity.mSurfaceProxy.waitUntilBufferDisplayed(numFrames,
37 1000 /* ms */))
38 }
39
40 assertThat(trace).hasFrameSequence("SurfaceView", 1..numFrames)
41 }
42
43 @Test
44 fun testSetBufferScalingMode_outOfOrderQueueBuffer() {
45 val trace = withTrace { activity ->
46 assertEquals(0, activity.mSurfaceProxy.SurfaceDequeueBuffer(0, 1000 /* ms */))
47 assertEquals(0, activity.mSurfaceProxy.SurfaceDequeueBuffer(1, 1000 /* ms */))
48
49 activity.mSurfaceProxy.SurfaceQueueBuffer(1)
50 activity.mSurfaceProxy.SurfaceQueueBuffer(0)
51 assertEquals(0, activity.mSurfaceProxy.waitUntilBufferDisplayed(2, 5000 /* ms */))
52 }
53
54 assertThat(trace).hasFrameSequence("SurfaceView", 1..2L)
55 }
56
57 @Test
58 fun testSetBufferScalingMode_multipleDequeueBuffer() {
59 val numFrames = 20L
60 val trace = withTrace { activity ->
61 for (count in 1..(numFrames / 2)) {
62 assertEquals(0, activity.mSurfaceProxy.SurfaceDequeueBuffer(0, 1000 /* ms */))
63 assertEquals(0, activity.mSurfaceProxy.SurfaceDequeueBuffer(1, 1000 /* ms */))
64
65 activity.mSurfaceProxy.SurfaceQueueBuffer(0)
66 activity.mSurfaceProxy.SurfaceQueueBuffer(1)
67 }
68 assertEquals(0, activity.mSurfaceProxy.waitUntilBufferDisplayed(numFrames,
69 5000 /* ms */))
70 }
71
72 assertThat(trace).hasFrameSequence("SurfaceView", 1..numFrames)
73 }
74
75 @Test
76 fun testSetBufferCount_queueMaxBufferCountMinusOne() {
77 val numBufferCount = 8
78 val numFrames = numBufferCount * 5L
79 val trace = withTrace { activity ->
80 assertEquals(0, activity.mSurfaceProxy.NativeWindowSetBufferCount(numBufferCount + 1))
81 for (i in 1..numFrames / numBufferCount) {
82 for (bufferSlot in 0..numBufferCount - 1) {
83 assertEquals(0,
84 activity.mSurfaceProxy.SurfaceDequeueBuffer(bufferSlot, 1000 /* ms */))
85 }
86
87 for (bufferSlot in 0..numBufferCount - 1) {
88 activity.mSurfaceProxy.SurfaceQueueBuffer(bufferSlot)
89 }
90 }
91 assertEquals(0, activity.mSurfaceProxy.waitUntilBufferDisplayed(numFrames,
92 5000 /* ms */))
93 }
94
95 assertThat(trace).hasFrameSequence("SurfaceView", 1..numFrames)
96 }
97
98 @Test
99 // Leave IGBP in sync mode, try to dequeue and queue as fast as possible. Check that we
100 // occasionally get timeout errors.
101 fun testSyncMode_dequeueWithoutBlockingFails() {
102 val numFrames = 1000L
103 runOnUiThread { activity ->
104 assertEquals(0, activity.mSurfaceProxy.SurfaceSetDequeueTimeout(3L))
105 var failures = false
106 for (i in 1..numFrames) {
107 if (activity.mSurfaceProxy.SurfaceDequeueBuffer(0, 0 /* ms */) != 0) {
108 failures = true
109 break
110 }
111 activity.mSurfaceProxy.SurfaceQueueBuffer(0)
112 }
113 assertTrue(failures)
114 }
115 }
116
117 @Test
118 // Set IGBP to be in async mode, try to dequeue and queue as fast as possible. Client should be
119 // able to dequeue and queue buffers without being blocked.
120 fun testAsyncMode_dequeueWithoutBlocking() {
121 val numFrames = 1000L
122 runOnUiThread { activity ->
123 assertEquals(0, activity.mSurfaceProxy.SurfaceSetDequeueTimeout(3L))
124 assertEquals(0, activity.mSurfaceProxy.SurfaceSetAsyncMode(async = true))
125 for (i in 1..numFrames) {
126 assertEquals(0, activity.mSurfaceProxy.SurfaceDequeueBuffer(0, 0 /* ms */))
127 activity.mSurfaceProxy.SurfaceQueueBuffer(0)
128 }
129 }
130 }
131
132 @Test
133 // Disable triple buffering in the system and leave IGBP in sync mode. Check that we
134 // occasionally get timeout errors.
135 fun testSyncModeWithDisabledTripleBuffering_dequeueWithoutBlockingFails() {
136 val numFrames = 1000L
137 runOnUiThread { activity ->
138 assertEquals(0, activity.mSurfaceProxy.SurfaceSetMaxDequeuedBufferCount(1))
139 assertEquals(0, activity.mSurfaceProxy.SurfaceSetDequeueTimeout(3L))
140 var failures = false
141 for (i in 1..numFrames) {
142 if (activity.mSurfaceProxy.SurfaceDequeueBuffer(0, 0 /* ms */) != 0) {
143 failures = true
144 break
145 }
146 activity.mSurfaceProxy.SurfaceQueueBuffer(0)
147 }
148 assertTrue(failures)
149 }
150 }
151
152 @Test
153 // Disable triple buffering in the system and set IGBP to be in async mode. Try to dequeue and
154 // queue as fast as possible. Without triple buffering, the client does not have an extra buffer
155 // to dequeue and will not be able to dequeue and queue buffers without being blocked.
156 fun testAsyncModeWithDisabledTripleBuffering_dequeueWithoutBlockingFails() {
157 val numFrames = 1000L
158 runOnUiThread { activity ->
159 assertEquals(0, activity.mSurfaceProxy.SurfaceSetMaxDequeuedBufferCount(1))
160 assertEquals(0, activity.mSurfaceProxy.SurfaceSetDequeueTimeout(3L))
161 assertEquals(0, activity.mSurfaceProxy.SurfaceSetAsyncMode(async = true))
162 var failures = false
163 for (i in 1..numFrames) {
164 if (activity.mSurfaceProxy.SurfaceDequeueBuffer(0, 0 /* ms */) != 0) {
165 failures = true
166 break
167 }
168 activity.mSurfaceProxy.SurfaceQueueBuffer(0)
169 }
170 assertTrue(failures)
171 }
172 }
173 }