diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2024-05-13 20:15:16 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2024-05-13 20:15:16 +0000 |
commit | 38e631b34e044c5341221bcc44fe9b98f6eed65b (patch) | |
tree | b134ca87e3e621e025ada4e43397e796cbbfb28a | |
parent | 26554b12a393121aa99813a24c1917987dda662c (diff) | |
parent | 76c8d191b8db964d8c3d44d42d2e04a2a383bd80 (diff) | |
download | art-android14-tests-release.tar.gz |
Snap for 11834329 from 76c8d191b8db964d8c3d44d42d2e04a2a383bd80 to android14-tests-releaseandroid14-tests-release
Change-Id: I070c24ca70b98b5a5bd618f141f33d1a13cf8134
-rw-r--r-- | libnativeloader/Android.bp | 115 | ||||
-rw-r--r-- | libnativeloader/native_loader_api_test.cpp (renamed from libnativeloader/native_loader_lazy_test.cpp) | 16 | ||||
-rw-r--r-- | libnativeloader/open_system_library.cpp | 55 |
3 files changed, 71 insertions, 115 deletions
diff --git a/libnativeloader/Android.bp b/libnativeloader/Android.bp index 96f56775f6..114af7020b 100644 --- a/libnativeloader/Android.bp +++ b/libnativeloader/Android.bp @@ -9,6 +9,28 @@ package { default_applicable_licenses: ["art_license"], } +cc_library_headers { + name: "libnativeloader-headers", + defaults: ["art_defaults"], + apex_available: [ + "//apex_available:platform", + "com.android.art", + "com.android.art.debug", + "com.android.media", + ], + visibility: [ + "//art:__subpackages__", + // TODO(b/133140750): Clean this up. + "//frameworks/av/media/libstagefright", + "//frameworks/native/libs/graphicsenv", + "//frameworks/native/vulkan/libvulkan", + ], + host_supported: true, + export_include_dirs: ["include"], + header_libs: ["jni_headers"], + export_header_lib_headers: ["jni_headers"], +} + cc_defaults { name: "libnativeloader-defaults", defaults: ["art_defaults"], @@ -75,6 +97,9 @@ art_cc_library { }, } +// Wrapper that loads nativeloader.so lazily, to be used to deal with layer +// inversion in places like in early boot where libnativeloader and/or +// libnativebridge aren't available. // TODO(b/124250621) eliminate the need for this library cc_library { name: "libnativeloader_lazy", @@ -95,33 +120,14 @@ cc_library { shared_libs: ["liblog"], } -cc_library_headers { - name: "libnativeloader-headers", - defaults: ["art_defaults"], - apex_available: [ - "//apex_available:platform", - "com.android.art", - "com.android.art.debug", - "com.android.media", - ], - visibility: [ - "//art:__subpackages__", - // TODO(b/133140750): Clean this up. - "//frameworks/av/media/libstagefright", - "//frameworks/native/libs/graphicsenv", - "//frameworks/native/vulkan/libvulkan", - ], - host_supported: true, - export_include_dirs: ["include"], - header_libs: ["jni_headers"], - export_header_lib_headers: ["jni_headers"], -} - -cc_defaults { - name: "libnativeloader-test-defaults", +art_cc_test { + name: "libnativeloader_test", defaults: [ "art_module_source_build_defaults", - "art_test_defaults", + // Cannot use art_standalone_gtest_defaults because it makes us link + // libnativebridge statically through libart-gtest, but we need to mock + // its symbols here. + "art_standalone_test_defaults", ], host_supported: false, @@ -143,56 +149,61 @@ cc_defaults { ], shared_libs: [ "libbase", + "libnativeloader", ], - test_suites: ["device-tests"], -} - -art_cc_test { - name: "libnativeloader_test", - defaults: [ - "art_standalone_test_defaults", - "libnativeloader-test-defaults", - ], tidy_timeout_srcs: [ "native_loader_test.cpp", ], srcs: [ "native_loader_api_test.c", "native_loader_test.cpp", - "open_system_library.cpp", + ], + + test_for: [ + "com.android.art", + "com.android.art.debug", + ], + test_suites: [ + "device-tests", + ], +} + +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", - "libnativeloader", + "libgmock", ], +} + +art_cc_test { + name: "art_libnativeloader_cts_test", + defaults: ["libnativeloader_api_test_defaults"], shared_libs: [ - "liblog", + "libnativeloader", ], - target: { - android: { - static_libs: [ - "libPlatformProperties", - ], - }, - }, - - // Added to CTS for API coverage of libnativeloader which is backed by the - // ART module. test_config_template: ":art-gtests-target-standalone-cts-template", test_suites: [ "cts", - "mts-art", + "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) { diff --git a/libnativeloader/open_system_library.cpp b/libnativeloader/open_system_library.cpp deleted file mode 100644 index 63175aa91f..0000000000 --- a/libnativeloader/open_system_library.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2014 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. - */ - -#define LOG_TAG "nativeloader_test" - -#include <dlfcn.h> -#include <log/log.h> - -#ifdef ART_TARGET_ANDROID -#include "nativeloader/dlext_namespaces.h" -#endif - -namespace android { - -extern "C" { - -// TODO(b/268440756): Find a way to reuse it from libnativebridge. -void* OpenSystemLibrary(const char* path, int flags) { -#ifdef ART_TARGET_ANDROID - // The system namespace is called "default" for binaries in /system and - // "system" for those in the Runtime APEX. Try "system" first since - // "default" always exists. - // TODO(b/185587109): Get rid of this error prone logic. - android_namespace_t* system_ns = android_get_exported_namespace("system"); - if (system_ns == nullptr) { - system_ns = android_get_exported_namespace("default"); - const char* message = "Failed to get system namespace for loading %s"; - LOG_ALWAYS_FATAL_IF(system_ns == nullptr, message, path); - } - const android_dlextinfo dlextinfo = { - .flags = ANDROID_DLEXT_USE_NAMESPACE, - .library_namespace = system_ns, - }; - return android_dlopen_ext(path, flags, &dlextinfo); -#else - return dlopen(path, flags); -#endif -} - -} // extern "C" - -} // namespace android |