1 /* 2 * Copyright (C) 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 android.test.lib; 18 19 import static com.google.common.truth.Truth.assertThat; 20 import static org.junit.Assert.assertThrows; 21 22 import androidx.test.platform.app.InstrumentationRegistry; 23 import org.junit.function.ThrowingRunnable; 24 25 public final class TestUtils { assertLibraryNotFound(ThrowingRunnable loadLibrary)26 public static void assertLibraryNotFound(ThrowingRunnable loadLibrary) { 27 Throwable t = assertThrows(UnsatisfiedLinkError.class, loadLibrary); 28 assertThat(t.getMessage()).containsMatch("dlopen failed: library .* not found"); 29 } 30 assertLinkerNamespaceError(ThrowingRunnable loadLibrary)31 public static void assertLinkerNamespaceError(ThrowingRunnable loadLibrary) { 32 Throwable t = assertThrows(UnsatisfiedLinkError.class, loadLibrary); 33 assertThat(t.getMessage()) 34 .containsMatch("dlopen failed: .* is not accessible for the namespace"); 35 } 36 libPath(String dir, String libName)37 public static String libPath(String dir, String libName) { 38 String libDirName = InstrumentationRegistry.getArguments().getString("libDirName"); 39 return dir + "/" + libDirName + "/lib" + libName + ".so"; 40 } 41 } 42