1 /* 2 * Copyright (C) 2023 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.monitors.wm 18 19 import android.tools.io.TraceType 20 import android.tools.monitors.TraceMonitorTest 21 import android.tools.testutils.CleanFlickerEnvironmentRule 22 import android.tools.testutils.newTestResultWriter 23 import android.tools.traces.TRACE_CONFIG_REQUIRE_CHANGES 24 import android.tools.traces.io.ResultReader 25 import android.tools.traces.monitors.wm.WindowManagerTraceMonitor 26 import com.android.server.wm.nano.WindowManagerTraceFileProto 27 import com.google.common.truth.Truth 28 import org.junit.Assume 29 import org.junit.Before 30 import org.junit.ClassRule 31 import org.junit.FixMethodOrder 32 import org.junit.Test 33 import org.junit.runners.MethodSorters 34 35 /** Contains [WindowManagerTraceMonitor] tests. */ 36 @FixMethodOrder(MethodSorters.NAME_ASCENDING) 37 class WindowManagerTraceMonitorTest : TraceMonitorTest<WindowManagerTraceMonitor>() { 38 override val traceType = TraceType.WM 39 getMonitornull40 override fun getMonitor() = WindowManagerTraceMonitor() 41 42 override fun assertTrace(traceData: ByteArray) { 43 val trace = WindowManagerTraceFileProto.parseFrom(traceData) 44 Truth.assertThat(trace.magicNumber) 45 .isEqualTo( 46 WindowManagerTraceFileProto.MAGIC_NUMBER_H.toLong() shl 47 32 or 48 WindowManagerTraceFileProto.MAGIC_NUMBER_L.toLong() 49 ) 50 } 51 52 @Before beforenull53 override fun before() { 54 Assume.assumeFalse(android.tracing.Flags.perfettoWmTracing()) 55 } 56 57 @Test includesProtologTracenull58 fun includesProtologTrace() { 59 Assume.assumeFalse(android.tracing.Flags.perfettoProtologTracing()) 60 61 val monitor = getMonitor() 62 monitor.start() 63 val writer = newTestResultWriter() 64 monitor.stop(writer) 65 val result = writer.write() 66 val reader = ResultReader(result, TRACE_CONFIG_REQUIRE_CHANGES) 67 Truth.assertWithMessage("Trace file exists ${TraceType.PROTOLOG.fileName}") 68 .that(reader.hasTraceFile(TraceType.PROTOLOG)) 69 .isTrue() 70 } 71 72 companion object { 73 @ClassRule @JvmField val ENV_CLEANUP = CleanFlickerEnvironmentRule() 74 } 75 } 76