summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libnativeloader/test/src/android/test/app/DataAppTest.java41
-rw-r--r--libnativeloader/test/src/android/test/app/ProductAppTest.java42
-rw-r--r--libnativeloader/test/src/android/test/app/SystemAppTest.java34
-rw-r--r--libnativeloader/test/src/android/test/app/VendorAppTest.java50
-rw-r--r--libnativeloader/test/src/android/test/hostside/LibnativeloaderTest.java3
-rw-r--r--libnativeloader/test/src/android/test/lib/TestUtils.java25
6 files changed, 119 insertions, 76 deletions
diff --git a/libnativeloader/test/src/android/test/app/DataAppTest.java b/libnativeloader/test/src/android/test/app/DataAppTest.java
index 4ba8afcbd2..39762ef6cc 100644
--- a/libnativeloader/test/src/android/test/app/DataAppTest.java
+++ b/libnativeloader/test/src/android/test/app/DataAppTest.java
@@ -34,7 +34,7 @@ public class DataAppTest {
System.loadLibrary("system_extpub.oem1");
System.loadLibrary("system_extpub.oem2");
System.loadLibrary("system_extpub1.oem1");
- TestUtils.assertLinkerNamespaceError( // Missing <uses-native-library>.
+ TestUtils.assertLibraryInaccessible( // Missing <uses-native-library>.
() -> System.loadLibrary("system_extpub_nouses.oem2"));
if (!TestUtils.skipPublicProductLibTests()) {
System.loadLibrary("product_extpub.product1");
@@ -44,12 +44,12 @@ public class DataAppTest {
@Test
public void testLoadPrivateLibraries() {
- TestUtils.assertLinkerNamespaceError(() -> System.loadLibrary("system_private1"));
- TestUtils.assertLinkerNamespaceError(() -> System.loadLibrary("systemext_private1"));
+ TestUtils.assertLibraryInaccessible(() -> System.loadLibrary("system_private1"));
+ TestUtils.assertLibraryInaccessible(() -> System.loadLibrary("systemext_private1"));
if (!TestUtils.skipPublicProductLibTests()) {
- TestUtils.assertLibraryNotFound(() -> System.loadLibrary("product_private1"));
+ TestUtils.assertLibraryInaccessible(() -> System.loadLibrary("product_private1"));
}
- TestUtils.assertLibraryNotFound(() -> System.loadLibrary("vendor_private1"));
+ TestUtils.assertLibraryInaccessible(() -> System.loadLibrary("vendor_private1"));
}
@Test
@@ -67,9 +67,10 @@ public class DataAppTest {
// SystemSharedLib.loadLibrary("system_private2");
// SystemSharedLib.loadLibrary("systemext_private2");
if (!TestUtils.skipPublicProductLibTests()) {
- TestUtils.assertLibraryNotFound(() -> SystemSharedLib.loadLibrary("product_private2"));
+ TestUtils.assertLibraryInaccessible(
+ () -> SystemSharedLib.loadLibrary("product_private2"));
}
- TestUtils.assertLibraryNotFound(() -> SystemSharedLib.loadLibrary("vendor_private2"));
+ TestUtils.assertLibraryInaccessible(() -> SystemSharedLib.loadLibrary("vendor_private2"));
}
@Test
@@ -79,30 +80,32 @@ public class DataAppTest {
// SystemExtSharedLib.loadLibrary("system_private3");
// SystemExtSharedLib.loadLibrary("systemext_private3");
if (!TestUtils.skipPublicProductLibTests()) {
- TestUtils.assertLibraryNotFound(
+ TestUtils.assertLibraryInaccessible(
() -> SystemExtSharedLib.loadLibrary("product_private3"));
}
- TestUtils.assertLibraryNotFound(() -> SystemExtSharedLib.loadLibrary("vendor_private3"));
+ TestUtils.assertLibraryInaccessible(
+ () -> SystemExtSharedLib.loadLibrary("vendor_private3"));
}
@Test
public void testLoadPrivateLibrariesViaProductSharedLib() {
- TestUtils.assertLinkerNamespaceError(() -> ProductSharedLib.loadLibrary("system_private4"));
- TestUtils.assertLinkerNamespaceError(
+ TestUtils.assertLibraryInaccessible(() -> ProductSharedLib.loadLibrary("system_private4"));
+ TestUtils.assertLibraryInaccessible(
() -> ProductSharedLib.loadLibrary("systemext_private4"));
if (!TestUtils.skipPublicProductLibTests()) {
ProductSharedLib.loadLibrary("product_private4");
}
- TestUtils.assertLibraryNotFound(() -> ProductSharedLib.loadLibrary("vendor_private4"));
+ TestUtils.assertLibraryInaccessible(() -> ProductSharedLib.loadLibrary("vendor_private4"));
}
@Test
public void testLoadPrivateLibrariesViaVendorSharedLib() {
- TestUtils.assertLinkerNamespaceError(() -> VendorSharedLib.loadLibrary("system_private5"));
- TestUtils.assertLinkerNamespaceError(
+ TestUtils.assertLibraryInaccessible(() -> VendorSharedLib.loadLibrary("system_private5"));
+ TestUtils.assertLibraryInaccessible(
() -> VendorSharedLib.loadLibrary("systemext_private5"));
if (!TestUtils.skipPublicProductLibTests()) {
- TestUtils.assertLibraryNotFound(() -> VendorSharedLib.loadLibrary("product_private5"));
+ TestUtils.assertLibraryInaccessible(
+ () -> VendorSharedLib.loadLibrary("product_private5"));
}
VendorSharedLib.loadLibrary("vendor_private5");
}
@@ -117,15 +120,15 @@ public class DataAppTest {
@Test
public void testLoadPrivateLibrariesWithAbsolutePaths() {
- TestUtils.assertLinkerNamespaceError(
+ TestUtils.assertLibraryInaccessible(
() -> System.load(TestUtils.libPath("/system", "system_private6")));
- TestUtils.assertLinkerNamespaceError(
+ TestUtils.assertLibraryInaccessible(
() -> System.load(TestUtils.libPath("/system_ext", "systemext_private6")));
if (!TestUtils.skipPublicProductLibTests()) {
- TestUtils.assertLinkerNamespaceError(
+ TestUtils.assertLibraryInaccessible(
() -> System.load(TestUtils.libPath("/product", "product_private6")));
}
- TestUtils.assertLinkerNamespaceError(
+ TestUtils.assertLibraryInaccessible(
() -> System.load(TestUtils.libPath("/vendor", "vendor_private6")));
}
}
diff --git a/libnativeloader/test/src/android/test/app/ProductAppTest.java b/libnativeloader/test/src/android/test/app/ProductAppTest.java
index 82d8b6e1f1..fae20a0806 100644
--- a/libnativeloader/test/src/android/test/app/ProductAppTest.java
+++ b/libnativeloader/test/src/android/test/app/ProductAppTest.java
@@ -41,12 +41,17 @@ public class ProductAppTest {
}
@Test
+ public void testPrivateLibsExist() {
+ TestUtils.testPrivateLibsExist("/product", "product_private");
+ }
+
+ @Test
public void testLoadExtendedPublicLibraries() {
System.loadLibrary("system_extpub.oem1");
System.loadLibrary("system_extpub.oem2");
System.loadLibrary("system_extpub1.oem1");
if (!productAppsAreShared()) {
- TestUtils.assertLinkerNamespaceError( // Missing <uses-native-library>.
+ TestUtils.assertLibraryInaccessible( // Missing <uses-native-library>.
() -> System.loadLibrary("system_extpub_nouses.oem2"));
}
System.loadLibrary("product_extpub.product1");
@@ -56,11 +61,11 @@ public class ProductAppTest {
@Test
public void testLoadPrivateLibraries() {
if (!productAppsAreShared()) {
- TestUtils.assertLinkerNamespaceError(() -> System.loadLibrary("system_private1"));
- TestUtils.assertLinkerNamespaceError(() -> System.loadLibrary("systemext_private1"));
+ TestUtils.assertLibraryInaccessible(() -> System.loadLibrary("system_private1"));
+ TestUtils.assertLibraryInaccessible(() -> System.loadLibrary("systemext_private1"));
}
System.loadLibrary("product_private1");
- TestUtils.assertLibraryNotFound(() -> System.loadLibrary("vendor_private1"));
+ TestUtils.assertLibraryInaccessible(() -> System.loadLibrary("vendor_private1"));
}
@Test
@@ -78,9 +83,10 @@ public class ProductAppTest {
// SystemSharedLib.loadLibrary("system_private2");
// SystemSharedLib.loadLibrary("systemext_private2");
if (!productAppsAreShared()) {
- TestUtils.assertLibraryNotFound(() -> SystemSharedLib.loadLibrary("product_private2"));
+ TestUtils.assertLibraryInaccessible(
+ () -> SystemSharedLib.loadLibrary("product_private2"));
}
- TestUtils.assertLibraryNotFound(() -> SystemSharedLib.loadLibrary("vendor_private2"));
+ TestUtils.assertLibraryInaccessible(() -> SystemSharedLib.loadLibrary("vendor_private2"));
}
@Test
@@ -90,32 +96,34 @@ public class ProductAppTest {
// SystemExtSharedLib.loadLibrary("system_private3");
// SystemExtSharedLib.loadLibrary("systemext_private3");
if (!productAppsAreShared()) {
- TestUtils.assertLibraryNotFound(
+ TestUtils.assertLibraryInaccessible(
() -> SystemExtSharedLib.loadLibrary("product_private3"));
}
- TestUtils.assertLibraryNotFound(() -> SystemExtSharedLib.loadLibrary("vendor_private3"));
+ TestUtils.assertLibraryInaccessible(
+ () -> SystemExtSharedLib.loadLibrary("vendor_private3"));
}
@Test
public void testLoadPrivateLibrariesViaProductSharedLib() {
if (!productAppsAreShared()) {
- TestUtils.assertLinkerNamespaceError(
+ TestUtils.assertLibraryInaccessible(
() -> ProductSharedLib.loadLibrary("system_private4"));
- TestUtils.assertLinkerNamespaceError(
+ TestUtils.assertLibraryInaccessible(
() -> ProductSharedLib.loadLibrary("systemext_private4"));
}
ProductSharedLib.loadLibrary("product_private4");
- TestUtils.assertLibraryNotFound(() -> ProductSharedLib.loadLibrary("vendor_private4"));
+ TestUtils.assertLibraryInaccessible(() -> ProductSharedLib.loadLibrary("vendor_private4"));
}
@Test
public void testLoadPrivateLibrariesViaVendorSharedLib() {
if (!productAppsAreShared()) {
- TestUtils.assertLinkerNamespaceError(
+ TestUtils.assertLibraryInaccessible(
() -> VendorSharedLib.loadLibrary("system_private5"));
- TestUtils.assertLinkerNamespaceError(
+ TestUtils.assertLibraryInaccessible(
() -> VendorSharedLib.loadLibrary("systemext_private5"));
- TestUtils.assertLibraryNotFound(() -> VendorSharedLib.loadLibrary("product_private5"));
+ TestUtils.assertLibraryInaccessible(
+ () -> VendorSharedLib.loadLibrary("product_private5"));
// When the app has a shared namespace, its libraries get loaded
// with shared namespaces as well, inheriting the same paths. So
// since the app wouldn't have access to /vendor/${LIB},
@@ -133,13 +141,13 @@ public class ProductAppTest {
@Test
public void testLoadPrivateLibrariesWithAbsolutePaths() {
if (!productAppsAreShared()) {
- TestUtils.assertLinkerNamespaceError(
+ TestUtils.assertLibraryInaccessible(
() -> System.load(TestUtils.libPath("/system", "system_private6")));
- TestUtils.assertLinkerNamespaceError(
+ TestUtils.assertLibraryInaccessible(
() -> System.load(TestUtils.libPath("/system_ext", "systemext_private6")));
}
System.load(TestUtils.libPath("/product", "product_private6"));
- TestUtils.assertLinkerNamespaceError(
+ TestUtils.assertLibraryInaccessible(
() -> System.load(TestUtils.libPath("/vendor", "vendor_private6")));
}
}
diff --git a/libnativeloader/test/src/android/test/app/SystemAppTest.java b/libnativeloader/test/src/android/test/app/SystemAppTest.java
index a909a4c49d..5c55f93974 100644
--- a/libnativeloader/test/src/android/test/app/SystemAppTest.java
+++ b/libnativeloader/test/src/android/test/app/SystemAppTest.java
@@ -31,6 +31,12 @@ import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public class SystemAppTest {
@Test
+ public void testPrivateLibsExist() {
+ TestUtils.testPrivateLibsExist("/system", "system_private");
+ TestUtils.testPrivateLibsExist("/system_ext", "systemext_private");
+ }
+
+ @Test
public void testLoadExtendedPublicLibraries() {
System.loadLibrary("system_extpub.oem1");
System.loadLibrary("system_extpub.oem2");
@@ -49,9 +55,9 @@ public class SystemAppTest {
System.loadLibrary("system_private1");
System.loadLibrary("systemext_private1");
if (!TestUtils.skipPublicProductLibTests()) {
- TestUtils.assertLibraryNotFound(() -> System.loadLibrary("product_private1"));
+ TestUtils.assertLibraryInaccessible(() -> System.loadLibrary("product_private1"));
}
- TestUtils.assertLibraryNotFound(() -> System.loadLibrary("vendor_private1"));
+ TestUtils.assertLibraryInaccessible(() -> System.loadLibrary("vendor_private1"));
}
@Test
@@ -67,9 +73,10 @@ public class SystemAppTest {
SystemSharedLib.loadLibrary("system_private2");
SystemSharedLib.loadLibrary("systemext_private2");
if (!TestUtils.skipPublicProductLibTests()) {
- TestUtils.assertLibraryNotFound(() -> SystemSharedLib.loadLibrary("product_private2"));
+ TestUtils.assertLibraryInaccessible(
+ () -> SystemSharedLib.loadLibrary("product_private2"));
}
- TestUtils.assertLibraryNotFound(() -> SystemSharedLib.loadLibrary("vendor_private2"));
+ TestUtils.assertLibraryInaccessible(() -> SystemSharedLib.loadLibrary("vendor_private2"));
}
@Test
@@ -77,10 +84,11 @@ public class SystemAppTest {
SystemExtSharedLib.loadLibrary("system_private3");
SystemExtSharedLib.loadLibrary("systemext_private3");
if (!TestUtils.skipPublicProductLibTests()) {
- TestUtils.assertLibraryNotFound(
+ TestUtils.assertLibraryInaccessible(
() -> SystemExtSharedLib.loadLibrary("product_private3"));
}
- TestUtils.assertLibraryNotFound(() -> SystemExtSharedLib.loadLibrary("vendor_private3"));
+ TestUtils.assertLibraryInaccessible(
+ () -> SystemExtSharedLib.loadLibrary("vendor_private3"));
}
@Test
@@ -88,9 +96,10 @@ public class SystemAppTest {
ProductSharedLib.loadLibrary("system_private4");
ProductSharedLib.loadLibrary("systemext_private4");
if (!TestUtils.skipPublicProductLibTests()) {
- TestUtils.assertLibraryNotFound(() -> ProductSharedLib.loadLibrary("product_private4"));
+ TestUtils.assertLibraryInaccessible(
+ () -> ProductSharedLib.loadLibrary("product_private4"));
}
- TestUtils.assertLibraryNotFound(() -> ProductSharedLib.loadLibrary("vendor_private4"));
+ TestUtils.assertLibraryInaccessible(() -> ProductSharedLib.loadLibrary("vendor_private4"));
}
@Test
@@ -98,9 +107,10 @@ public class SystemAppTest {
VendorSharedLib.loadLibrary("system_private5");
VendorSharedLib.loadLibrary("systemext_private5");
if (!TestUtils.skipPublicProductLibTests()) {
- TestUtils.assertLibraryNotFound(() -> VendorSharedLib.loadLibrary("product_private5"));
+ TestUtils.assertLibraryInaccessible(
+ () -> VendorSharedLib.loadLibrary("product_private5"));
}
- TestUtils.assertLibraryNotFound(() -> VendorSharedLib.loadLibrary("vendor_private5"));
+ TestUtils.assertLibraryInaccessible(() -> VendorSharedLib.loadLibrary("vendor_private5"));
}
@Test
@@ -116,10 +126,10 @@ public class SystemAppTest {
System.load(TestUtils.libPath("/system", "system_private6"));
System.load(TestUtils.libPath("/system_ext", "systemext_private6"));
if (!TestUtils.skipPublicProductLibTests()) {
- TestUtils.assertLinkerNamespaceError(
+ TestUtils.assertLibraryInaccessible(
() -> System.load(TestUtils.libPath("/product", "product_private6")));
}
- TestUtils.assertLinkerNamespaceError(
+ TestUtils.assertLibraryInaccessible(
() -> System.load(TestUtils.libPath("/vendor", "vendor_private6")));
}
}
diff --git a/libnativeloader/test/src/android/test/app/VendorAppTest.java b/libnativeloader/test/src/android/test/app/VendorAppTest.java
index 52688bbf35..2177cf2cc4 100644
--- a/libnativeloader/test/src/android/test/app/VendorAppTest.java
+++ b/libnativeloader/test/src/android/test/app/VendorAppTest.java
@@ -30,11 +30,16 @@ import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public class VendorAppTest {
@Test
+ public void testPrivateLibsExist() {
+ TestUtils.testPrivateLibsExist("/vendor", "vendor_private");
+ }
+
+ @Test
public void testLoadExtendedPublicLibraries() {
- TestUtils.assertLinkerNamespaceError(() -> System.loadLibrary("system_extpub.oem1"));
- TestUtils.assertLinkerNamespaceError(() -> System.loadLibrary("system_extpub.oem2"));
- TestUtils.assertLinkerNamespaceError(() -> System.loadLibrary("system_extpub1.oem1"));
- TestUtils.assertLinkerNamespaceError(() -> System.loadLibrary("system_extpub_nouses.oem2"));
+ TestUtils.assertLibraryInaccessible(() -> System.loadLibrary("system_extpub.oem1"));
+ TestUtils.assertLibraryInaccessible(() -> System.loadLibrary("system_extpub.oem2"));
+ TestUtils.assertLibraryInaccessible(() -> System.loadLibrary("system_extpub1.oem1"));
+ TestUtils.assertLibraryInaccessible(() -> System.loadLibrary("system_extpub_nouses.oem2"));
if (!TestUtils.skipPublicProductLibTests()) {
System.loadLibrary("product_extpub.product1");
System.loadLibrary("product_extpub1.product1");
@@ -43,10 +48,10 @@ public class VendorAppTest {
@Test
public void testLoadPrivateLibraries() {
- TestUtils.assertLinkerNamespaceError(() -> System.loadLibrary("system_private1"));
- TestUtils.assertLinkerNamespaceError(() -> System.loadLibrary("systemext_private1"));
+ TestUtils.assertLibraryInaccessible(() -> System.loadLibrary("system_private1"));
+ TestUtils.assertLibraryInaccessible(() -> System.loadLibrary("systemext_private1"));
if (!TestUtils.skipPublicProductLibTests()) {
- TestUtils.assertLibraryNotFound(() -> System.loadLibrary("product_private1"));
+ TestUtils.assertLibraryInaccessible(() -> System.loadLibrary("product_private1"));
}
System.loadLibrary("vendor_private1");
}
@@ -66,9 +71,10 @@ public class VendorAppTest {
// SystemSharedLib.loadLibrary("system_private2");
// SystemSharedLib.loadLibrary("systemext_private2");
if (!TestUtils.skipPublicProductLibTests()) {
- TestUtils.assertLibraryNotFound(() -> SystemSharedLib.loadLibrary("product_private2"));
+ TestUtils.assertLibraryInaccessible(
+ () -> SystemSharedLib.loadLibrary("product_private2"));
}
- TestUtils.assertLibraryNotFound(() -> SystemSharedLib.loadLibrary("vendor_private2"));
+ TestUtils.assertLibraryInaccessible(() -> SystemSharedLib.loadLibrary("vendor_private2"));
}
@Test
@@ -78,37 +84,39 @@ public class VendorAppTest {
// SystemExtSharedLib.loadLibrary("system_private3");
// SystemExtSharedLib.loadLibrary("systemext_private3");
if (!TestUtils.skipPublicProductLibTests()) {
- TestUtils.assertLibraryNotFound(
+ TestUtils.assertLibraryInaccessible(
() -> SystemExtSharedLib.loadLibrary("product_private3"));
}
- TestUtils.assertLibraryNotFound(() -> SystemExtSharedLib.loadLibrary("vendor_private3"));
+ TestUtils.assertLibraryInaccessible(
+ () -> SystemExtSharedLib.loadLibrary("vendor_private3"));
}
@Test
public void testLoadPrivateLibrariesViaProductSharedLib() {
- TestUtils.assertLinkerNamespaceError(() -> ProductSharedLib.loadLibrary("system_private4"));
- TestUtils.assertLinkerNamespaceError(
+ TestUtils.assertLibraryInaccessible(() -> ProductSharedLib.loadLibrary("system_private4"));
+ TestUtils.assertLibraryInaccessible(
() -> ProductSharedLib.loadLibrary("systemext_private4"));
if (!TestUtils.skipPublicProductLibTests()) {
ProductSharedLib.loadLibrary("product_private4");
}
- TestUtils.assertLibraryNotFound(() -> ProductSharedLib.loadLibrary("vendor_private4"));
+ TestUtils.assertLibraryInaccessible(() -> ProductSharedLib.loadLibrary("vendor_private4"));
}
@Test
public void testLoadPrivateLibrariesViaVendorSharedLib() {
- TestUtils.assertLinkerNamespaceError(() -> VendorSharedLib.loadLibrary("system_private5"));
- TestUtils.assertLinkerNamespaceError(
+ TestUtils.assertLibraryInaccessible(() -> VendorSharedLib.loadLibrary("system_private5"));
+ TestUtils.assertLibraryInaccessible(
() -> VendorSharedLib.loadLibrary("systemext_private5"));
if (!TestUtils.skipPublicProductLibTests()) {
- TestUtils.assertLibraryNotFound(() -> VendorSharedLib.loadLibrary("product_private5"));
+ TestUtils.assertLibraryInaccessible(
+ () -> VendorSharedLib.loadLibrary("product_private5"));
}
VendorSharedLib.loadLibrary("vendor_private5");
}
@Test
public void testLoadExtendedPublicLibrariesWithAbsolutePaths() {
- TestUtils.assertLinkerNamespaceError(
+ TestUtils.assertLibraryInaccessible(
() -> System.load(TestUtils.libPath("/system", "system_extpub3.oem1")));
if (!TestUtils.skipPublicProductLibTests()) {
System.load(TestUtils.libPath("/product", "product_extpub3.product1"));
@@ -117,12 +125,12 @@ public class VendorAppTest {
@Test
public void testLoadPrivateLibrariesWithAbsolutePaths() {
- TestUtils.assertLinkerNamespaceError(
+ TestUtils.assertLibraryInaccessible(
() -> System.load(TestUtils.libPath("/system", "system_private6")));
- TestUtils.assertLinkerNamespaceError(
+ TestUtils.assertLibraryInaccessible(
() -> System.load(TestUtils.libPath("/system_ext", "systemext_private6")));
if (!TestUtils.skipPublicProductLibTests()) {
- TestUtils.assertLinkerNamespaceError(
+ TestUtils.assertLibraryInaccessible(
() -> System.load(TestUtils.libPath("/product", "product_private6")));
}
System.load(TestUtils.libPath("/vendor", "vendor_private6"));
diff --git a/libnativeloader/test/src/android/test/hostside/LibnativeloaderTest.java b/libnativeloader/test/src/android/test/hostside/LibnativeloaderTest.java
index 55a6dd27b3..80bd72667e 100644
--- a/libnativeloader/test/src/android/test/hostside/LibnativeloaderTest.java
+++ b/libnativeloader/test/src/android/test/hostside/LibnativeloaderTest.java
@@ -278,6 +278,9 @@ public class LibnativeloaderTest extends BaseHostJUnit4Test {
void pushPrivateLibs(ZipFile libApk) throws Exception {
// Push the libraries once for each test. Since we cannot unload them, we need a fresh
// never-before-loaded library in each loadLibrary call.
+ //
+ // Remember to update testPrivateLibsExist in TestUtils.java when
+ // the number of libraries changes.
for (int i = 1; i <= 6; ++i) {
pushNativeTestLib(libApk, "libsystem_testlib.so",
"/system/${LIB}/libsystem_private" + i + ".so");
diff --git a/libnativeloader/test/src/android/test/lib/TestUtils.java b/libnativeloader/test/src/android/test/lib/TestUtils.java
index ca64bad791..26bc0f8265 100644
--- a/libnativeloader/test/src/android/test/lib/TestUtils.java
+++ b/libnativeloader/test/src/android/test/lib/TestUtils.java
@@ -17,6 +17,7 @@
package android.test.lib;
import static com.google.common.truth.Truth.assertThat;
+import static com.google.common.truth.Truth.assertWithMessage;
import static org.junit.Assert.assertThrows;
@@ -26,16 +27,13 @@ import androidx.test.platform.app.InstrumentationRegistry;
import org.junit.function.ThrowingRunnable;
-public final class TestUtils {
- public static void assertLibraryNotFound(ThrowingRunnable loadLibrary) {
- Throwable t = assertThrows(UnsatisfiedLinkError.class, loadLibrary);
- assertThat(t.getMessage()).containsMatch("dlopen failed: library .* not found");
- }
+import java.io.File;
- public static void assertLinkerNamespaceError(ThrowingRunnable loadLibrary) {
+public final class TestUtils {
+ public static void assertLibraryInaccessible(ThrowingRunnable loadLibrary) {
Throwable t = assertThrows(UnsatisfiedLinkError.class, loadLibrary);
assertThat(t.getMessage())
- .containsMatch("dlopen failed: .* is not accessible for the namespace");
+ .containsMatch("dlopen failed: .* (not found|not accessible for the namespace)");
}
public static String libPath(String dir, String libName) {
@@ -48,4 +46,17 @@ public final class TestUtils {
public static boolean skipPublicProductLibTests() {
return Build.VERSION.SDK_INT < 33; // TIRAMISU
}
+
+ // Test that private libs are present, as a safeguard so that the dlopen
+ // failures we expect in other tests aren't due to them not being there.
+ public static void testPrivateLibsExist(String libDir, String libStem) {
+ // Remember to update pushPrivateLibs in LibnativeloaderTest.java when
+ // the number of libraries changes.
+ for (int i = 1; i <= 6; ++i) {
+ String libPath = libPath(libDir, libStem + i);
+ assertWithMessage(libPath + " does not exist")
+ .that(new File(libPath).exists())
+ .isTrue();
+ }
+ }
}