summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Stjernholm <mast@google.com>2024-04-16 18:33:11 +0100
committerMartin Stjernholm <mast@google.com>2024-04-24 13:06:42 +0000
commit1dc111804f9ea778bce6258ffd10fed80fb02d0c (patch)
tree77f41c265a2365e4742e97dc12e242644ad0e37d
parent186ee7b672ebe158caf5c19777a6c281ced449dd (diff)
downloadart-1dc111804f9ea778bce6258ffd10fed80fb02d0c.tar.gz
Repurpose libnativeloader_lazy tests as shallow tests for API coverage
in CTS. Most APIs are exercised extensively in any managed process, but use this to cover the fringes. This drops the mocks that used dynamic library symbol overrides (android_create_namespace and android_link_namespaces) from the former libnativeloader_lazy tests, because we cannot inject them in CTS tests. However it turns out it works just fine to call into the real code in the linker. As a result libnativeloader_lazy_test no longer needs to be built with exported symbols necessary to make the symbol override mocks to work. Also strengthen the CreateClassLoaderNamespace test slightly by verifying that it really did create a classloader namespace. Also move libnativeloader_test and libnativeloader_lazy_test from device-tests to general-tests, because they shouldn't have any device dependencies. Test: atest libnativeloader_test \ art_libnativeloader_cts_test \ libnativeloader_lazy_test Bug: 335224367 Change-Id: Idd15d5a79f4f54c68304a4b758c7a46ba9b96c86
-rw-r--r--libnativeloader/Android.bp59
-rw-r--r--libnativeloader/native_loader_api_test.cpp (renamed from libnativeloader/native_loader_lazy_test.cpp)16
2 files changed, 48 insertions, 27 deletions
diff --git a/libnativeloader/Android.bp b/libnativeloader/Android.bp
index 4e5cde5665..f7e5bf8c98 100644
--- a/libnativeloader/Android.bp
+++ b/libnativeloader/Android.bp
@@ -123,8 +123,8 @@ cc_library {
shared_libs: ["liblog"],
}
-cc_defaults {
- name: "libnativeloader-test-defaults",
+art_cc_test {
+ name: "libnativeloader_test",
defaults: [
"art_module_source_build_defaults",
// Cannot use art_standalone_gtest_defaults because it makes us link
@@ -148,24 +148,13 @@ cc_defaults {
],
shared_libs: [
"liblog", // libbase dependency
+ "libnativeloader",
],
static_libs: [
"libbase",
"libgmock",
],
- test_for: [
- "com.android.art",
- "com.android.art.debug",
- ],
- test_suites: ["device-tests"],
-}
-
-art_cc_test {
- name: "libnativeloader_test",
- defaults: [
- "libnativeloader-test-defaults",
- ],
tidy_timeout_srcs: [
"native_loader_test.cpp",
],
@@ -174,21 +163,53 @@ art_cc_test {
"native_loader_api_test.c",
"native_loader_test.cpp",
],
+
+ test_for: [
+ "com.android.art",
+ "com.android.art.debug",
+ ],
+ test_suites: [
+ "general-tests",
+ "mts-art",
+ ],
+}
+
+cc_defaults {
+ name: "libnativeloader_api_test_defaults",
+ defaults: ["art_standalone_test_defaults"],
+
+ srcs: ["native_loader_api_test.cpp"],
+ header_libs: [
+ "libnativebridge-headers",
+ "libnativehelper_header_only",
+ ],
+ static_libs: [
+ "libbase",
+ "libgmock",
+ ],
+}
+
+art_cc_test {
+ name: "art_libnativeloader_cts_test",
+ defaults: ["libnativeloader_api_test_defaults"],
shared_libs: [
"libnativeloader",
],
+ test_config_template: ":art-gtests-target-standalone-cts-template",
test_suites: [
- "mts-art",
+ "cts",
+ "mcts-art",
],
}
art_cc_test {
name: "libnativeloader_lazy_test",
- defaults: ["libnativeloader-test-defaults"],
- srcs: [
- "native_loader_lazy_test.cpp",
- ],
+ defaults: ["libnativeloader_api_test_defaults"],
static_libs: [
"libnativeloader_lazy",
],
+ test_suites: [
+ "general-tests",
+ "mts-art",
+ ],
}
diff --git a/libnativeloader/native_loader_lazy_test.cpp b/libnativeloader/native_loader_api_test.cpp
index b863c85100..78fb29f91d 100644
--- a/libnativeloader/native_loader_lazy_test.cpp
+++ b/libnativeloader/native_loader_api_test.cpp
@@ -16,8 +16,7 @@
#if defined(ART_TARGET_ANDROID)
-#include <gtest/gtest.h>
-
+#include "gtest/gtest.h"
#include "native_loader_test.h"
#include "nativehelper/scoped_utf_chars.h"
#include "nativeloader/native_loader.h"
@@ -25,11 +24,13 @@
namespace android {
namespace nativeloader {
+using ::testing::Return;
using ::testing::StrEq;
-// Only need to test that the trivial lazy lib wrappers call through to the real
-// functions, but still have to mock things well enough to avoid null pointer
-// dereferences.
+// Test the exported API in libnativeloader and libnativeloader_lazy. The
+// testing we can do here outside a full VM is limited, but this is only to
+// complement other tests and ensure coverage of the APIs that aren't in the
+// common call paths.
class NativeLoaderLazyTest : public ::testing::Test {
protected:
@@ -49,9 +50,6 @@ class NativeLoaderLazyTest : public ::testing::Test {
void CallCreateClassLoaderNamespace(const char* class_loader) {
ON_CALL(*mock, JniObject_getParent(StrEq(class_loader))).WillByDefault(Return(nullptr));
- EXPECT_CALL(*mock, mock_create_namespace)
- .WillOnce(Return(TO_MOCK_NAMESPACE(TO_ANDROID_NAMESPACE(class_loader))));
- ON_CALL(*mock, mock_link_namespaces).WillByDefault(Return(true));
jstring err = CreateClassLoaderNamespace(env.get(),
17,
@@ -69,6 +67,8 @@ class NativeLoaderLazyTest : public ::testing::Test {
TEST_F(NativeLoaderLazyTest, CreateClassLoaderNamespace) {
CallCreateClassLoaderNamespace("my_classloader_1");
+ EXPECT_NE(FindNamespaceByClassLoader(env.get(), env.get()->NewStringUTF("my_classloader_1")),
+ nullptr);
}
TEST_F(NativeLoaderLazyTest, OpenNativeLibrary) {