summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Martin Stjernholm <mast@google.com> 2024-05-13 18:22:53 +0000
committer Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2024-05-13 18:22:53 +0000
commit8a22c47141de62d743210bf34d1a638f4eb4d252 (patch)
treeb5d4a60ed1b1f603b9af7a0d9cee30a1e7a258c2
parent03f19d54ab636428479fa3b55b0f8194c5d24784 (diff)
parent76c8d191b8db964d8c3d44d42d2e04a2a383bd80 (diff)
Repurpose libnativeloader_lazy tests as shallow tests for API coverage am: 76c8d191b8
Original change: https://android-review.googlesource.com/c/platform/art/+/3074463 Change-Id: I53d57e7b4d7e9da9f5768392fc481288b608138f Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--libnativeloader/Android.bp55
-rw-r--r--libnativeloader/native_loader_api_test.cpp (renamed from libnativeloader/native_loader_lazy_test.cpp)16
2 files changed, 45 insertions, 26 deletions
diff --git a/libnativeloader/Android.bp b/libnativeloader/Android.bp
index 2db1f76ead..114af7020b 100644
--- a/libnativeloader/Android.bp
+++ b/libnativeloader/Android.bp
@@ -120,8 +120,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
@@ -149,42 +149,61 @@ cc_defaults {
],
shared_libs: [
"libbase",
+ "libnativeloader",
+ ],
+
+ tidy_timeout_srcs: [
+ "native_loader_test.cpp",
+ ],
+ srcs: [
+ "native_loader_api_test.c",
+ "native_loader_test.cpp",
],
test_for: [
"com.android.art",
"com.android.art.debug",
],
- test_suites: ["device-tests"],
+ test_suites: [
+ "device-tests",
+ ],
}
-art_cc_test {
- name: "libnativeloader_test",
- defaults: [
- "libnativeloader-test-defaults",
- ],
- tidy_timeout_srcs: [
- "native_loader_test.cpp",
+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",
],
- srcs: [
- "native_loader_api_test.c",
- "native_loader_test.cpp",
+ 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: [
+ "device-tests",
+ ],
}
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) {