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 com.android.test.tracing.coroutines 18 19 import android.platform.test.annotations.EnableFlags 20 import com.android.app.tracing.coroutines.CoroutineTraceName 21 import com.android.app.tracing.coroutines.TraceContextElement 22 import com.android.app.tracing.coroutines.createCoroutineTracingContext 23 import com.android.systemui.Flags.FLAG_COROUTINE_TRACING 24 import kotlin.coroutines.CoroutineContext 25 import kotlinx.coroutines.launch 26 import org.junit.Test 27 28 @EnableFlags(FLAG_COROUTINE_TRACING) 29 class CoroutineTraceNameTest : TestBase() { 30 31 // BAD: CoroutineTraceName should not be installed on the root like this: <lambda>null32 override val extraContext: CoroutineContext by lazy { CoroutineTraceName("MainName") } 33 34 @Test <lambda>null35 fun nameMergedWithTraceContext() = runTest { 36 expectD() 37 val otherTraceContext = 38 createCoroutineTracingContext("TraceContextName", testMode = true) 39 as TraceContextElement 40 // MainName is never used. It is overwritten by the CoroutineTracingContext: 41 launch(otherTraceContext) { expectD("1^TraceContextName") } 42 expectD() 43 launch(otherTraceContext) { expectD("2^TraceContextName") } 44 launch { expectD() } 45 } 46 } 47