Introduce a shared class for test utilities.
To be used more in later CLs.
Test: atest libnativeloader_e2e_tests
Bug: 137356719
Bug: 237577392
Change-Id: I35ef7df45e6337d4eed91a82d561df5f48784670
diff --git a/libnativeloader/test/Android.bp b/libnativeloader/test/Android.bp
index dd5e969..b384dcc 100644
--- a/libnativeloader/test/Android.bp
+++ b/libnativeloader/test/Android.bp
@@ -40,6 +40,15 @@
jni_libs: ["libnativeloader_testlib"],
}
+java_library {
+ name: "loadlibrarytest_test_utils",
+ static_libs: [
+ "androidx.test.ext.junit",
+ "androidx.test.ext.truth",
+ ],
+ srcs: ["src/android/test/lib/TestUtils.java"],
+}
+
java_defaults {
name: "loadlibrarytest_app_defaults",
defaults: ["art_module_source_build_java_defaults"],
@@ -51,8 +60,8 @@
static_libs: [
"androidx.test.ext.junit",
- "androidx.test.ext.truth",
"androidx.test.rules",
+ "loadlibrarytest_test_utils",
],
}
diff --git a/libnativeloader/test/src/android/test/app/ProductAppTest.java b/libnativeloader/test/src/android/test/app/ProductAppTest.java
index 243e2c7..5510d55 100644
--- a/libnativeloader/test/src/android/test/app/ProductAppTest.java
+++ b/libnativeloader/test/src/android/test/app/ProductAppTest.java
@@ -16,9 +16,6 @@
package android.test.app;
-import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.assertThrows;
-
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
import org.junit.Test;
diff --git a/libnativeloader/test/src/android/test/app/SystemAppTest.java b/libnativeloader/test/src/android/test/app/SystemAppTest.java
index dd680f5..faf891f 100644
--- a/libnativeloader/test/src/android/test/app/SystemAppTest.java
+++ b/libnativeloader/test/src/android/test/app/SystemAppTest.java
@@ -16,9 +16,6 @@
package android.test.app;
-import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.assertThrows;
-
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
import org.junit.Test;
diff --git a/libnativeloader/test/src/android/test/app/VendorAppTest.java b/libnativeloader/test/src/android/test/app/VendorAppTest.java
index a830d06..bd6d637 100644
--- a/libnativeloader/test/src/android/test/app/VendorAppTest.java
+++ b/libnativeloader/test/src/android/test/app/VendorAppTest.java
@@ -16,9 +16,7 @@
package android.test.app;
-import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.assertThrows;
-
+import android.test.lib.TestUtils;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
import org.junit.Test;
@@ -29,18 +27,11 @@
public class VendorAppTest {
@Test
public void testLoadLibraries() {
- assertLinkerNamespaceError("foo.oem1");
- assertLinkerNamespaceError("bar.oem1");
- assertLinkerNamespaceError("foo.oem2");
- assertLinkerNamespaceError("bar.oem2");
+ TestUtils.assertLinkerNamespaceError("foo.oem1");
+ TestUtils.assertLinkerNamespaceError("bar.oem1");
+ TestUtils.assertLinkerNamespaceError("foo.oem2");
+ TestUtils.assertLinkerNamespaceError("bar.oem2");
System.loadLibrary("foo.product1");
System.loadLibrary("bar.product1");
}
-
- private void assertLinkerNamespaceError(String libraryName) {
- Throwable t =
- assertThrows(UnsatisfiedLinkError.class, () -> System.loadLibrary(libraryName));
- assertThat(t.getMessage())
- .containsMatch("dlopen failed: .* is not accessible for the namespace");
- }
}
diff --git a/libnativeloader/test/src/android/test/lib/TestUtils.java b/libnativeloader/test/src/android/test/lib/TestUtils.java
new file mode 100644
index 0000000..1518cd0
--- /dev/null
+++ b/libnativeloader/test/src/android/test/lib/TestUtils.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.test.lib;
+
+import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertThrows;
+
+public final class TestUtils {
+ public static void assertLinkerNamespaceError(String libraryName) {
+ Throwable t =
+ assertThrows(UnsatisfiedLinkError.class, () -> System.loadLibrary(libraryName));
+ assertThat(t.getMessage())
+ .containsMatch("dlopen failed: .* is not accessible for the namespace");
+ }
+}