• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 package android.tools
18 
19 import android.tools.io.TraceType
20 import android.tools.testutils.CleanFlickerEnvironmentRule
21 import android.tools.traces.NullableDeviceStateDump
22 import android.tools.traces.getCurrentState
23 import android.tools.traces.getCurrentStateDumpNullable
24 import com.google.common.truth.Truth
25 import org.junit.ClassRule
26 import org.junit.FixMethodOrder
27 import org.junit.Test
28 import org.junit.runners.MethodSorters
29 
30 /** Contains [android.os.traces] utils tests. */
31 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
32 class UtilsTest {
getCurrStatenull33     private fun getCurrState(
34         vararg dumpTypes: TraceType = arrayOf(TraceType.SF_DUMP, TraceType.WM_DUMP)
35     ): Pair<ByteArray, ByteArray> {
36         return getCurrentState(*dumpTypes)
37     }
38 
getCurrStateDumpnull39     private fun getCurrStateDump(
40         vararg dumpTypes: TraceType = arrayOf(TraceType.SF_DUMP, TraceType.WM_DUMP)
41     ): NullableDeviceStateDump {
42         return getCurrentStateDumpNullable(*dumpTypes, clearCacheAfterParsing = false)
43     }
44 
45     @Test
canFetchCurrentDeviceStatenull46     fun canFetchCurrentDeviceState() {
47         val currState = this.getCurrState()
48         Truth.assertThat(currState.first).isNotEmpty()
49         Truth.assertThat(currState.second).isNotEmpty()
50     }
51 
52     @Test
canFetchCurrentDeviceStateOnlyWmnull53     fun canFetchCurrentDeviceStateOnlyWm() {
54         val currStateDump = this.getCurrState(TraceType.WM_DUMP)
55         Truth.assertThat(currStateDump.first).isNotEmpty()
56         Truth.assertThat(currStateDump.second).isEmpty()
57         val currState = this.getCurrStateDump(TraceType.WM_DUMP)
58         Truth.assertThat(currState.wmState).isNotNull()
59         Truth.assertThat(currState.layerState).isNull()
60     }
61 
62     @Test
canFetchCurrentDeviceStateOnlyLayersnull63     fun canFetchCurrentDeviceStateOnlyLayers() {
64         val currStateDump = this.getCurrState(TraceType.SF_DUMP)
65         Truth.assertThat(currStateDump.first).isEmpty()
66         Truth.assertThat(currStateDump.second).isNotEmpty()
67         val currState = this.getCurrStateDump(TraceType.SF_DUMP)
68         Truth.assertThat(currState.wmState).isNull()
69         Truth.assertThat(currState.layerState).isNotNull()
70     }
71 
72     @Test
canParseCurrentDeviceStatenull73     fun canParseCurrentDeviceState() {
74         val currState = this.getCurrStateDump()
75         val wmArray = currState.wmState?.asTrace()?.entries ?: emptyList()
76         Truth.assertThat(wmArray).hasSize(1)
77         Truth.assertThat(wmArray.first().windowStates).isNotEmpty()
78         val layersArray = currState.layerState?.asTrace()?.entries ?: emptyList()
79         Truth.assertThat(layersArray).hasSize(1)
80         Truth.assertThat(layersArray.first().flattenedLayers).isNotEmpty()
81     }
82 
83     companion object {
84         @ClassRule @JvmField val ENV_CLEANUP = CleanFlickerEnvironmentRule()
85     }
86 }
87