1 /* 2 * Copyright 2022 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 androidx.tracing.perfetto.binary.test 18 19 import androidx.test.ext.junit.runners.AndroidJUnit4 20 import androidx.test.filters.SmallTest 21 import androidx.test.platform.app.InstrumentationRegistry 22 import dalvik.system.BaseDexClassLoader 23 import java.io.File 24 import java.util.zip.ZipFile 25 import org.junit.Assert.assertTrue 26 import org.junit.Test 27 import org.junit.runner.RunWith 28 29 @SmallTest 30 @RunWith(AndroidJUnit4::class) 31 class TracingTest { 32 /** 33 * The test verifies that the library was assembled and can be found by the system. We cannot 34 * load the library since it contains explicit JNI method registration tied to the 35 * [androidx.tracing.perfetto.jni.PerfettoNative] class. 36 * 37 * Methods of the library are further tested in e.g.: 38 * - [androidx.tracing.perfetto.jni.test.PerfettoNativeTest] 39 * - [androidx.compose.integration.macrobenchmark.TrivialTracingBenchmark] 40 */ 41 @Test test_library_was_creatednull42 fun test_library_was_created() { 43 // check that the system can resolve the library 44 val nativeLibraryName = System.mapLibraryName("tracing_perfetto") 45 46 // check that the class loader can find the library 47 val classLoader = javaClass.classLoader as BaseDexClassLoader 48 val libraryPath = classLoader.findLibrary("tracing_perfetto") 49 assertTrue(libraryPath.endsWith("/$nativeLibraryName")) 50 51 // check that the APK contains the library file 52 val context = InstrumentationRegistry.getInstrumentation().context 53 val baseApk = File(context.applicationInfo.publicSourceDir!!) 54 assertTrue( 55 ZipFile(baseApk).entries().asSequence().any { it.name.endsWith("/$nativeLibraryName") } 56 ) 57 } 58 } 59