Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Nicolas Geoffray | 7ca8b67 | 2020-04-24 15:43:48 +0100 | [diff] [blame] | 17 | #if defined(ART_TARGET_ANDROID) |
| 18 | |
Martin Stjernholm | 19d1feb | 2021-03-30 22:35:24 +0100 | [diff] [blame] | 19 | #include "native_loader_test.h" |
| 20 | |
Kiyoung Kim | 760e495 | 2023-10-18 10:26:00 +0900 | [diff] [blame] | 21 | #include <android-base/properties.h> |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 22 | #include <android-base/strings.h> |
Kiyoung Kim | 760e495 | 2023-10-18 10:26:00 +0900 | [diff] [blame] | 23 | #include <dlfcn.h> |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 24 | #include <gtest/gtest.h> |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 25 | |
Martin Stjernholm | 94fd9ea | 2019-10-24 16:57:34 +0100 | [diff] [blame] | 26 | #include "nativehelper/scoped_utf_chars.h" |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 27 | #include "nativeloader/native_loader.h" |
| 28 | #include "public_libraries.h" |
| 29 | |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 30 | namespace android { |
| 31 | namespace nativeloader { |
| 32 | |
Martin Stjernholm | 4829733 | 2019-11-12 21:21:32 +0000 | [diff] [blame] | 33 | using ::testing::Eq; |
Martin Stjernholm | 2665943 | 2021-04-16 19:55:03 +0100 | [diff] [blame] | 34 | using ::testing::NotNull; |
Martin Stjernholm | e5f1d63 | 2022-11-16 15:28:12 +0000 | [diff] [blame] | 35 | using ::testing::StartsWith; |
Martin Stjernholm | 4829733 | 2019-11-12 21:21:32 +0000 | [diff] [blame] | 36 | using ::testing::StrEq; |
Stefano Cianciulli | 419e5a1 | 2022-07-04 14:38:21 +0000 | [diff] [blame] | 37 | using internal::ConfigEntry; // NOLINT - ConfigEntry is actually used |
Calin Juravle | 91d2c5c | 2021-05-07 22:44:29 +0000 | [diff] [blame] | 38 | using internal::ParseApexLibrariesConfig; |
Martin Stjernholm | 2665943 | 2021-04-16 19:55:03 +0100 | [diff] [blame] | 39 | using internal::ParseConfig; |
Martin Stjernholm | 4829733 | 2019-11-12 21:21:32 +0000 | [diff] [blame] | 40 | |
Martin Stjernholm | be08b20 | 2019-11-12 20:11:00 +0000 | [diff] [blame] | 41 | #if defined(__LP64__) |
| 42 | #define LIB_DIR "lib64" |
| 43 | #else |
| 44 | #define LIB_DIR "lib" |
| 45 | #endif |
| 46 | |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 47 | static void* const any_nonnull = reinterpret_cast<void*>(0x12345678); |
| 48 | |
| 49 | // Custom matcher for comparing namespace handles |
| 50 | MATCHER_P(NsEq, other, "") { |
| 51 | *result_listener << "comparing " << reinterpret_cast<const char*>(arg) << " and " << other; |
| 52 | return strcmp(reinterpret_cast<const char*>(arg), reinterpret_cast<const char*>(other)) == 0; |
| 53 | } |
| 54 | |
| 55 | ///////////////////////////////////////////////////////////////// |
| 56 | |
| 57 | // Test fixture |
| 58 | class NativeLoaderTest : public ::testing::TestWithParam<bool> { |
| 59 | protected: |
| 60 | bool IsBridged() { return GetParam(); } |
| 61 | |
| 62 | void SetUp() override { |
Martin Stjernholm | 4829733 | 2019-11-12 21:21:32 +0000 | [diff] [blame] | 63 | mock = std::make_unique<testing::NiceMock<MockPlatform>>(IsBridged()); |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 64 | |
| 65 | env = std::make_unique<JNIEnv>(); |
| 66 | env->functions = CreateJNINativeInterface(); |
| 67 | } |
| 68 | |
| 69 | void SetExpectations() { |
| 70 | std::vector<std::string> default_public_libs = |
| 71 | android::base::Split(preloadable_public_libraries(), ":"); |
Stefano Cianciulli | 944df15 | 2022-06-29 08:48:55 +0000 | [diff] [blame] | 72 | for (const std::string& l : default_public_libs) { |
Martin Stjernholm | 2665943 | 2021-04-16 19:55:03 +0100 | [diff] [blame] | 73 | EXPECT_CALL(*mock, |
| 74 | mock_dlopen_ext(false, StrEq(l.c_str()), RTLD_NOW | RTLD_NODELETE, NotNull())) |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 75 | .WillOnce(Return(any_nonnull)); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | void RunTest() { InitializeNativeLoader(); } |
| 80 | |
| 81 | void TearDown() override { |
| 82 | ResetNativeLoader(); |
| 83 | delete env->functions; |
| 84 | mock.reset(); |
| 85 | } |
| 86 | |
| 87 | std::unique_ptr<JNIEnv> env; |
| 88 | }; |
| 89 | |
| 90 | ///////////////////////////////////////////////////////////////// |
| 91 | |
| 92 | TEST_P(NativeLoaderTest, InitializeLoadsDefaultPublicLibraries) { |
| 93 | SetExpectations(); |
| 94 | RunTest(); |
| 95 | } |
| 96 | |
Martin Stjernholm | 2665943 | 2021-04-16 19:55:03 +0100 | [diff] [blame] | 97 | TEST_P(NativeLoaderTest, OpenNativeLibraryWithoutClassloaderInApex) { |
| 98 | const char* test_lib_path = "libfoo.so"; |
| 99 | void* fake_handle = &fake_handle; // Arbitrary non-null value |
| 100 | EXPECT_CALL(*mock, |
| 101 | mock_dlopen_ext(false, StrEq(test_lib_path), RTLD_NOW, NsEq("com_android_art"))) |
| 102 | .WillOnce(Return(fake_handle)); |
| 103 | |
| 104 | bool needs_native_bridge = false; |
| 105 | char* errmsg = nullptr; |
| 106 | EXPECT_EQ(fake_handle, |
| 107 | OpenNativeLibrary(env.get(), |
| 108 | /*target_sdk_version=*/17, |
| 109 | test_lib_path, |
| 110 | /*class_loader=*/nullptr, |
| 111 | /*caller_location=*/"/apex/com.android.art/javalib/myloadinglib.jar", |
| 112 | /*library_path=*/nullptr, |
| 113 | &needs_native_bridge, |
| 114 | &errmsg)); |
| 115 | // OpenNativeLibrary never uses nativebridge when there's no classloader. That |
| 116 | // should maybe change. |
| 117 | EXPECT_EQ(needs_native_bridge, false); |
| 118 | EXPECT_EQ(errmsg, nullptr); |
| 119 | } |
| 120 | |
| 121 | TEST_P(NativeLoaderTest, OpenNativeLibraryWithoutClassloaderInFramework) { |
| 122 | const char* test_lib_path = "libfoo.so"; |
| 123 | void* fake_handle = &fake_handle; // Arbitrary non-null value |
| 124 | EXPECT_CALL(*mock, mock_dlopen_ext(false, StrEq(test_lib_path), RTLD_NOW, NsEq("system"))) |
| 125 | .WillOnce(Return(fake_handle)); |
| 126 | |
| 127 | bool needs_native_bridge = false; |
| 128 | char* errmsg = nullptr; |
| 129 | EXPECT_EQ(fake_handle, |
| 130 | OpenNativeLibrary(env.get(), |
| 131 | /*target_sdk_version=*/17, |
| 132 | test_lib_path, |
| 133 | /*class_loader=*/nullptr, |
| 134 | /*caller_location=*/"/system/framework/framework.jar!classes1.dex", |
| 135 | /*library_path=*/nullptr, |
| 136 | &needs_native_bridge, |
| 137 | &errmsg)); |
| 138 | // OpenNativeLibrary never uses nativebridge when there's no classloader. That |
| 139 | // should maybe change. |
| 140 | EXPECT_EQ(needs_native_bridge, false); |
| 141 | EXPECT_EQ(errmsg, nullptr); |
| 142 | } |
| 143 | |
| 144 | TEST_P(NativeLoaderTest, OpenNativeLibraryWithoutClassloaderAndCallerLocation) { |
| 145 | const char* test_lib_path = "libfoo.so"; |
| 146 | void* fake_handle = &fake_handle; // Arbitrary non-null value |
| 147 | EXPECT_CALL(*mock, mock_dlopen_ext(false, StrEq(test_lib_path), RTLD_NOW, NsEq("system"))) |
| 148 | .WillOnce(Return(fake_handle)); |
| 149 | |
| 150 | bool needs_native_bridge = false; |
| 151 | char* errmsg = nullptr; |
| 152 | EXPECT_EQ(fake_handle, |
| 153 | OpenNativeLibrary(env.get(), |
| 154 | /*target_sdk_version=*/17, |
| 155 | test_lib_path, |
| 156 | /*class_loader=*/nullptr, |
| 157 | /*caller_location=*/nullptr, |
| 158 | /*library_path=*/nullptr, |
| 159 | &needs_native_bridge, |
| 160 | &errmsg)); |
| 161 | // OpenNativeLibrary never uses nativebridge when there's no classloader. That |
| 162 | // should maybe change. |
| 163 | EXPECT_EQ(needs_native_bridge, false); |
| 164 | EXPECT_EQ(errmsg, nullptr); |
| 165 | } |
| 166 | |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 167 | INSTANTIATE_TEST_SUITE_P(NativeLoaderTests, NativeLoaderTest, testing::Bool()); |
| 168 | |
| 169 | ///////////////////////////////////////////////////////////////// |
| 170 | |
Martin Stjernholm | 5af718b | 2022-08-24 23:17:09 +0100 | [diff] [blame] | 171 | std::string append_extended_libraries(const std::string& libs) { |
Stefano Cianciulli | 2be604b | 2022-06-07 08:27:24 +0000 | [diff] [blame] | 172 | const std::string& ext_libs = extended_public_libraries(); |
Martin Stjernholm | 630cb4e | 2022-03-24 00:50:33 +0000 | [diff] [blame] | 173 | if (!ext_libs.empty()) { |
Martin Stjernholm | 5af718b | 2022-08-24 23:17:09 +0100 | [diff] [blame] | 174 | return libs + ":" + ext_libs; |
Martin Stjernholm | 630cb4e | 2022-03-24 00:50:33 +0000 | [diff] [blame] | 175 | } |
Martin Stjernholm | 5af718b | 2022-08-24 23:17:09 +0100 | [diff] [blame] | 176 | return libs; |
| 177 | } |
| 178 | |
| 179 | std::string default_public_and_extended_libraries() { |
| 180 | return append_extended_libraries(default_public_libraries()); |
Martin Stjernholm | 630cb4e | 2022-03-24 00:50:33 +0000 | [diff] [blame] | 181 | } |
| 182 | |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 183 | class NativeLoaderTest_Create : public NativeLoaderTest { |
| 184 | protected: |
| 185 | // Test inputs (initialized to the default values). Overriding these |
| 186 | // must be done before calling SetExpectations() and RunTest(). |
| 187 | uint32_t target_sdk_version = 29; |
| 188 | std::string class_loader = "my_classloader"; |
| 189 | bool is_shared = false; |
| 190 | std::string dex_path = "/data/app/foo/classes.dex"; |
Martin Stjernholm | be08b20 | 2019-11-12 20:11:00 +0000 | [diff] [blame] | 191 | std::string library_path = "/data/app/foo/" LIB_DIR "/arm"; |
| 192 | std::string permitted_path = "/data/app/foo/" LIB_DIR; |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 193 | |
| 194 | // expected output (.. for the default test inputs) |
Martin Stjernholm | e5f1d63 | 2022-11-16 15:28:12 +0000 | [diff] [blame] | 195 | std::string expected_namespace_prefix = "clns"; |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 196 | uint64_t expected_namespace_flags = |
| 197 | ANDROID_NAMESPACE_TYPE_ISOLATED | ANDROID_NAMESPACE_TYPE_ALSO_USED_AS_ANONYMOUS; |
| 198 | std::string expected_library_path = library_path; |
| 199 | std::string expected_permitted_path = std::string("/data:/mnt/expand:") + permitted_path; |
Kiyoung Kim | 99c19ca | 2020-01-29 16:09:38 +0900 | [diff] [blame] | 200 | std::string expected_parent_namespace = "system"; |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 201 | bool expected_link_with_platform_ns = true; |
| 202 | bool expected_link_with_art_ns = true; |
Victor Chang | d20e51d | 2020-05-05 16:01:19 +0100 | [diff] [blame] | 203 | bool expected_link_with_i18n_ns = true; |
Jooyung Han | 180e1e7 | 2021-06-20 17:54:38 +0900 | [diff] [blame] | 204 | bool expected_link_with_conscrypt_ns = false; |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 205 | bool expected_link_with_sphal_ns = !vendor_public_libraries().empty(); |
Justin Yun | a21b584 | 2021-08-10 14:05:49 +0900 | [diff] [blame] | 206 | bool expected_link_with_product_ns = !product_public_libraries().empty(); |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 207 | bool expected_link_with_vndk_ns = false; |
Justin Yun | eb4f08c | 2020-02-18 11:29:07 +0900 | [diff] [blame] | 208 | bool expected_link_with_vndk_product_ns = false; |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 209 | bool expected_link_with_default_ns = false; |
| 210 | bool expected_link_with_neuralnetworks_ns = true; |
Martin Stjernholm | 630cb4e | 2022-03-24 00:50:33 +0000 | [diff] [blame] | 211 | std::string expected_shared_libs_to_platform_ns = default_public_and_extended_libraries(); |
Jooyung Han | cd616d0 | 2020-09-01 14:53:23 +0900 | [diff] [blame] | 212 | std::string expected_shared_libs_to_art_ns = apex_public_libraries().at("com_android_art"); |
| 213 | std::string expected_shared_libs_to_i18n_ns = apex_public_libraries().at("com_android_i18n"); |
Jooyung Han | 180e1e7 | 2021-06-20 17:54:38 +0900 | [diff] [blame] | 214 | std::string expected_shared_libs_to_conscrypt_ns = apex_jni_libraries("com_android_conscrypt"); |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 215 | std::string expected_shared_libs_to_sphal_ns = vendor_public_libraries(); |
Justin Yun | a21b584 | 2021-08-10 14:05:49 +0900 | [diff] [blame] | 216 | std::string expected_shared_libs_to_product_ns = product_public_libraries(); |
Justin Yun | eb4f08c | 2020-02-18 11:29:07 +0900 | [diff] [blame] | 217 | std::string expected_shared_libs_to_vndk_ns = vndksp_libraries_vendor(); |
| 218 | std::string expected_shared_libs_to_vndk_product_ns = vndksp_libraries_product(); |
Martin Stjernholm | 630cb4e | 2022-03-24 00:50:33 +0000 | [diff] [blame] | 219 | std::string expected_shared_libs_to_default_ns = default_public_and_extended_libraries(); |
Jooyung Han | cd616d0 | 2020-09-01 14:53:23 +0900 | [diff] [blame] | 220 | std::string expected_shared_libs_to_neuralnetworks_ns = apex_public_libraries().at("com_android_neuralnetworks"); |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 221 | |
| 222 | void SetExpectations() { |
| 223 | NativeLoaderTest::SetExpectations(); |
| 224 | |
| 225 | ON_CALL(*mock, JniObject_getParent(StrEq(class_loader))).WillByDefault(Return(nullptr)); |
| 226 | |
Martin Stjernholm | 4829733 | 2019-11-12 21:21:32 +0000 | [diff] [blame] | 227 | EXPECT_CALL(*mock, NativeBridgeIsPathSupported(_)).Times(testing::AnyNumber()); |
| 228 | EXPECT_CALL(*mock, NativeBridgeInitialized()).Times(testing::AnyNumber()); |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 229 | |
| 230 | EXPECT_CALL(*mock, mock_create_namespace( |
Martin Stjernholm | e5f1d63 | 2022-11-16 15:28:12 +0000 | [diff] [blame] | 231 | Eq(IsBridged()), StartsWith(expected_namespace_prefix + "-"), nullptr, |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 232 | StrEq(expected_library_path), expected_namespace_flags, |
| 233 | StrEq(expected_permitted_path), NsEq(expected_parent_namespace.c_str()))) |
| 234 | .WillOnce(Return(TO_MOCK_NAMESPACE(TO_ANDROID_NAMESPACE(dex_path.c_str())))); |
| 235 | if (expected_link_with_platform_ns) { |
Kiyoung Kim | 99c19ca | 2020-01-29 16:09:38 +0900 | [diff] [blame] | 236 | EXPECT_CALL(*mock, mock_link_namespaces(Eq(IsBridged()), _, NsEq("system"), |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 237 | StrEq(expected_shared_libs_to_platform_ns))) |
| 238 | .WillOnce(Return(true)); |
| 239 | } |
| 240 | if (expected_link_with_art_ns) { |
Kiyoung Kim | 272b36d | 2020-02-19 16:08:47 +0900 | [diff] [blame] | 241 | EXPECT_CALL(*mock, mock_link_namespaces(Eq(IsBridged()), _, NsEq("com_android_art"), |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 242 | StrEq(expected_shared_libs_to_art_ns))) |
| 243 | .WillOnce(Return(true)); |
| 244 | } |
Victor Chang | d20e51d | 2020-05-05 16:01:19 +0100 | [diff] [blame] | 245 | if (expected_link_with_i18n_ns) { |
| 246 | EXPECT_CALL(*mock, mock_link_namespaces(Eq(IsBridged()), _, NsEq("com_android_i18n"), |
| 247 | StrEq(expected_shared_libs_to_i18n_ns))) |
| 248 | .WillOnce(Return(true)); |
| 249 | } |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 250 | if (expected_link_with_sphal_ns) { |
| 251 | EXPECT_CALL(*mock, mock_link_namespaces(Eq(IsBridged()), _, NsEq("sphal"), |
| 252 | StrEq(expected_shared_libs_to_sphal_ns))) |
| 253 | .WillOnce(Return(true)); |
| 254 | } |
Justin Yun | a21b584 | 2021-08-10 14:05:49 +0900 | [diff] [blame] | 255 | if (expected_link_with_product_ns) { |
| 256 | EXPECT_CALL(*mock, mock_link_namespaces(Eq(IsBridged()), _, NsEq("product"), |
| 257 | StrEq(expected_shared_libs_to_product_ns))) |
| 258 | .WillOnce(Return(true)); |
| 259 | } |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 260 | if (expected_link_with_vndk_ns) { |
| 261 | EXPECT_CALL(*mock, mock_link_namespaces(Eq(IsBridged()), _, NsEq("vndk"), |
| 262 | StrEq(expected_shared_libs_to_vndk_ns))) |
| 263 | .WillOnce(Return(true)); |
| 264 | } |
Justin Yun | eb4f08c | 2020-02-18 11:29:07 +0900 | [diff] [blame] | 265 | if (expected_link_with_vndk_product_ns) { |
| 266 | EXPECT_CALL(*mock, mock_link_namespaces(Eq(IsBridged()), _, NsEq("vndk_product"), |
| 267 | StrEq(expected_shared_libs_to_vndk_product_ns))) |
| 268 | .WillOnce(Return(true)); |
| 269 | } |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 270 | if (expected_link_with_default_ns) { |
| 271 | EXPECT_CALL(*mock, mock_link_namespaces(Eq(IsBridged()), _, NsEq("default"), |
| 272 | StrEq(expected_shared_libs_to_default_ns))) |
| 273 | .WillOnce(Return(true)); |
| 274 | } |
| 275 | if (expected_link_with_neuralnetworks_ns) { |
Kiyoung Kim | 272b36d | 2020-02-19 16:08:47 +0900 | [diff] [blame] | 276 | EXPECT_CALL(*mock, mock_link_namespaces(Eq(IsBridged()), _, NsEq("com_android_neuralnetworks"), |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 277 | StrEq(expected_shared_libs_to_neuralnetworks_ns))) |
| 278 | .WillOnce(Return(true)); |
| 279 | } |
Jooyung Han | 180e1e7 | 2021-06-20 17:54:38 +0900 | [diff] [blame] | 280 | if (expected_link_with_conscrypt_ns) { |
| 281 | EXPECT_CALL(*mock, mock_link_namespaces(Eq(IsBridged()), _, NsEq("com_android_conscrypt"), |
| 282 | StrEq(expected_shared_libs_to_conscrypt_ns))) |
| 283 | .WillOnce(Return(true)); |
| 284 | } |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | void RunTest() { |
| 288 | NativeLoaderTest::RunTest(); |
| 289 | |
| 290 | jstring err = CreateClassLoaderNamespace( |
| 291 | env(), target_sdk_version, env()->NewStringUTF(class_loader.c_str()), is_shared, |
| 292 | env()->NewStringUTF(dex_path.c_str()), env()->NewStringUTF(library_path.c_str()), |
Martin Stjernholm | b309240 | 2020-09-04 00:49:44 +0100 | [diff] [blame] | 293 | env()->NewStringUTF(permitted_path.c_str()), /*uses_library_list=*/ nullptr); |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 294 | |
| 295 | // no error |
Martin Stjernholm | 94fd9ea | 2019-10-24 16:57:34 +0100 | [diff] [blame] | 296 | EXPECT_EQ(err, nullptr) << "Error is: " << std::string(ScopedUtfChars(env(), err).c_str()); |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 297 | |
| 298 | if (!IsBridged()) { |
| 299 | struct android_namespace_t* ns = |
| 300 | FindNamespaceByClassLoader(env(), env()->NewStringUTF(class_loader.c_str())); |
| 301 | |
| 302 | // The created namespace is for this apk |
| 303 | EXPECT_EQ(dex_path.c_str(), reinterpret_cast<const char*>(ns)); |
| 304 | } else { |
| 305 | struct NativeLoaderNamespace* ns = |
| 306 | FindNativeLoaderNamespaceByClassLoader(env(), env()->NewStringUTF(class_loader.c_str())); |
| 307 | |
| 308 | // The created namespace is for the this apk |
| 309 | EXPECT_STREQ(dex_path.c_str(), |
| 310 | reinterpret_cast<const char*>(ns->ToRawNativeBridgeNamespace())); |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | JNIEnv* env() { return NativeLoaderTest::env.get(); } |
| 315 | }; |
| 316 | |
| 317 | TEST_P(NativeLoaderTest_Create, DownloadedApp) { |
| 318 | SetExpectations(); |
| 319 | RunTest(); |
| 320 | } |
| 321 | |
| 322 | TEST_P(NativeLoaderTest_Create, BundledSystemApp) { |
| 323 | dex_path = "/system/app/foo/foo.apk"; |
| 324 | is_shared = true; |
| 325 | |
Martin Stjernholm | e5f1d63 | 2022-11-16 15:28:12 +0000 | [diff] [blame] | 326 | expected_namespace_prefix = "clns-shared"; |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 327 | expected_namespace_flags |= ANDROID_NAMESPACE_TYPE_SHARED; |
| 328 | SetExpectations(); |
| 329 | RunTest(); |
| 330 | } |
| 331 | |
| 332 | TEST_P(NativeLoaderTest_Create, BundledVendorApp) { |
| 333 | dex_path = "/vendor/app/foo/foo.apk"; |
| 334 | is_shared = true; |
| 335 | |
Martin Stjernholm | e5f1d63 | 2022-11-16 15:28:12 +0000 | [diff] [blame] | 336 | expected_namespace_prefix = "clns-shared"; |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 337 | expected_namespace_flags |= ANDROID_NAMESPACE_TYPE_SHARED; |
| 338 | SetExpectations(); |
| 339 | RunTest(); |
| 340 | } |
| 341 | |
| 342 | TEST_P(NativeLoaderTest_Create, UnbundledVendorApp) { |
| 343 | dex_path = "/vendor/app/foo/foo.apk"; |
| 344 | is_shared = false; |
| 345 | |
Martin Stjernholm | e5f1d63 | 2022-11-16 15:28:12 +0000 | [diff] [blame] | 346 | expected_namespace_prefix = "vendor-clns"; |
Martin Stjernholm | be08b20 | 2019-11-12 20:11:00 +0000 | [diff] [blame] | 347 | expected_library_path = expected_library_path + ":/vendor/" LIB_DIR; |
| 348 | expected_permitted_path = expected_permitted_path + ":/vendor/" LIB_DIR; |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 349 | expected_shared_libs_to_platform_ns = |
Martin Stjernholm | 630cb4e | 2022-03-24 00:50:33 +0000 | [diff] [blame] | 350 | default_public_libraries() + ":" + llndk_libraries_vendor(); |
Kiyoung Kim | cd9c984 | 2023-10-19 17:12:13 +0900 | [diff] [blame] | 351 | if (android::base::GetProperty("ro.vndk.version", "") != "") { |
| 352 | expected_link_with_vndk_ns = true; |
| 353 | } |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 354 | SetExpectations(); |
| 355 | RunTest(); |
| 356 | } |
| 357 | |
Justin Yun | 3db26d5 | 2019-12-16 14:09:39 +0900 | [diff] [blame] | 358 | TEST_P(NativeLoaderTest_Create, BundledProductApp) { |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 359 | dex_path = "/product/app/foo/foo.apk"; |
| 360 | is_shared = true; |
| 361 | |
Martin Stjernholm | e5f1d63 | 2022-11-16 15:28:12 +0000 | [diff] [blame] | 362 | expected_namespace_prefix = "clns-shared"; |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 363 | expected_namespace_flags |= ANDROID_NAMESPACE_TYPE_SHARED; |
| 364 | SetExpectations(); |
| 365 | RunTest(); |
| 366 | } |
| 367 | |
Jooyung Han | 180e1e7 | 2021-06-20 17:54:38 +0900 | [diff] [blame] | 368 | TEST_P(NativeLoaderTest_Create, SystemServerWithApexJars) { |
| 369 | dex_path = "/system/framework/services.jar:/apex/com.android.conscrypt/javalib/service-foo.jar"; |
| 370 | is_shared = true; |
| 371 | |
Martin Stjernholm | e5f1d63 | 2022-11-16 15:28:12 +0000 | [diff] [blame] | 372 | expected_namespace_prefix = "clns-shared"; |
Jooyung Han | 180e1e7 | 2021-06-20 17:54:38 +0900 | [diff] [blame] | 373 | expected_namespace_flags |= ANDROID_NAMESPACE_TYPE_SHARED; |
| 374 | expected_link_with_conscrypt_ns = true; |
| 375 | SetExpectations(); |
| 376 | RunTest(); |
| 377 | } |
| 378 | |
Justin Yun | 3db26d5 | 2019-12-16 14:09:39 +0900 | [diff] [blame] | 379 | TEST_P(NativeLoaderTest_Create, UnbundledProductApp) { |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 380 | dex_path = "/product/app/foo/foo.apk"; |
| 381 | is_shared = false; |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 382 | |
Kiyoung Kim | 760e495 | 2023-10-18 10:26:00 +0900 | [diff] [blame] | 383 | if (is_product_treblelized()) { |
| 384 | expected_namespace_prefix = "product-clns"; |
| 385 | expected_library_path = |
| 386 | expected_library_path + ":/product/" LIB_DIR ":/system/product/" LIB_DIR; |
| 387 | expected_permitted_path = |
| 388 | expected_permitted_path + ":/product/" LIB_DIR ":/system/product/" LIB_DIR; |
| 389 | expected_shared_libs_to_platform_ns = |
| 390 | append_extended_libraries(default_public_libraries() + ":" + llndk_libraries_product()); |
Kiyoung Kim | cd9c984 | 2023-10-19 17:12:13 +0900 | [diff] [blame] | 391 | if (android::base::GetProperty("ro.product.vndk.version", "") != "") { |
| 392 | expected_link_with_vndk_product_ns = true; |
| 393 | } |
Kiyoung Kim | 760e495 | 2023-10-18 10:26:00 +0900 | [diff] [blame] | 394 | } |
Kiyoung Kim | c8c2953 | 2023-09-22 13:52:47 +0900 | [diff] [blame] | 395 | |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 396 | SetExpectations(); |
| 397 | RunTest(); |
| 398 | } |
| 399 | |
| 400 | TEST_P(NativeLoaderTest_Create, NamespaceForSharedLibIsNotUsedAsAnonymousNamespace) { |
| 401 | if (IsBridged()) { |
| 402 | // There is no shared lib in translated arch |
| 403 | // TODO(jiyong): revisit this |
| 404 | return; |
| 405 | } |
| 406 | // compared to apks, for java shared libs, library_path is empty; java shared |
| 407 | // libs don't have their own native libs. They use platform's. |
| 408 | library_path = ""; |
| 409 | expected_library_path = library_path; |
| 410 | // no ALSO_USED_AS_ANONYMOUS |
| 411 | expected_namespace_flags = ANDROID_NAMESPACE_TYPE_ISOLATED; |
| 412 | SetExpectations(); |
| 413 | RunTest(); |
| 414 | } |
| 415 | |
| 416 | TEST_P(NativeLoaderTest_Create, TwoApks) { |
| 417 | SetExpectations(); |
| 418 | const uint32_t second_app_target_sdk_version = 29; |
| 419 | const std::string second_app_class_loader = "second_app_classloader"; |
| 420 | const bool second_app_is_shared = false; |
| 421 | const std::string second_app_dex_path = "/data/app/bar/classes.dex"; |
Martin Stjernholm | be08b20 | 2019-11-12 20:11:00 +0000 | [diff] [blame] | 422 | const std::string second_app_library_path = "/data/app/bar/" LIB_DIR "/arm"; |
| 423 | const std::string second_app_permitted_path = "/data/app/bar/" LIB_DIR; |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 424 | const std::string expected_second_app_permitted_path = |
| 425 | std::string("/data:/mnt/expand:") + second_app_permitted_path; |
Martin Stjernholm | e5f1d63 | 2022-11-16 15:28:12 +0000 | [diff] [blame] | 426 | const std::string expected_second_app_parent_namespace = "clns"; |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 427 | // no ALSO_USED_AS_ANONYMOUS |
| 428 | const uint64_t expected_second_namespace_flags = ANDROID_NAMESPACE_TYPE_ISOLATED; |
| 429 | |
| 430 | // The scenario is that second app is loaded by the first app. |
| 431 | // So the first app's classloader (`classloader`) is parent of the second |
| 432 | // app's classloader. |
| 433 | ON_CALL(*mock, JniObject_getParent(StrEq(second_app_class_loader))) |
| 434 | .WillByDefault(Return(class_loader.c_str())); |
| 435 | |
| 436 | // namespace for the second app is created. Its parent is set to the namespace |
| 437 | // of the first app. |
| 438 | EXPECT_CALL(*mock, mock_create_namespace( |
Martin Stjernholm | e5f1d63 | 2022-11-16 15:28:12 +0000 | [diff] [blame] | 439 | Eq(IsBridged()), StartsWith(expected_namespace_prefix + "-"), nullptr, |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 440 | StrEq(second_app_library_path), expected_second_namespace_flags, |
| 441 | StrEq(expected_second_app_permitted_path), NsEq(dex_path.c_str()))) |
| 442 | .WillOnce(Return(TO_MOCK_NAMESPACE(TO_ANDROID_NAMESPACE(second_app_dex_path.c_str())))); |
| 443 | EXPECT_CALL(*mock, mock_link_namespaces(Eq(IsBridged()), NsEq(second_app_dex_path.c_str()), _, _)) |
| 444 | .WillRepeatedly(Return(true)); |
| 445 | |
| 446 | RunTest(); |
| 447 | jstring err = CreateClassLoaderNamespace( |
| 448 | env(), second_app_target_sdk_version, env()->NewStringUTF(second_app_class_loader.c_str()), |
| 449 | second_app_is_shared, env()->NewStringUTF(second_app_dex_path.c_str()), |
| 450 | env()->NewStringUTF(second_app_library_path.c_str()), |
Martin Stjernholm | b309240 | 2020-09-04 00:49:44 +0100 | [diff] [blame] | 451 | env()->NewStringUTF(second_app_permitted_path.c_str()), /*uses_library_list=*/ nullptr); |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 452 | |
| 453 | // success |
Martin Stjernholm | 94fd9ea | 2019-10-24 16:57:34 +0100 | [diff] [blame] | 454 | EXPECT_EQ(err, nullptr) << "Error is: " << std::string(ScopedUtfChars(env(), err).c_str()); |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 455 | |
| 456 | if (!IsBridged()) { |
| 457 | struct android_namespace_t* ns = |
| 458 | FindNamespaceByClassLoader(env(), env()->NewStringUTF(second_app_class_loader.c_str())); |
| 459 | |
| 460 | // The created namespace is for the second apk |
| 461 | EXPECT_EQ(second_app_dex_path.c_str(), reinterpret_cast<const char*>(ns)); |
| 462 | } else { |
| 463 | struct NativeLoaderNamespace* ns = FindNativeLoaderNamespaceByClassLoader( |
| 464 | env(), env()->NewStringUTF(second_app_class_loader.c_str())); |
| 465 | |
| 466 | // The created namespace is for the second apk |
| 467 | EXPECT_STREQ(second_app_dex_path.c_str(), |
| 468 | reinterpret_cast<const char*>(ns->ToRawNativeBridgeNamespace())); |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | INSTANTIATE_TEST_SUITE_P(NativeLoaderTests_Create, NativeLoaderTest_Create, testing::Bool()); |
| 473 | |
| 474 | const std::function<Result<bool>(const struct ConfigEntry&)> always_true = |
| 475 | [](const struct ConfigEntry&) -> Result<bool> { return true; }; |
| 476 | |
| 477 | TEST(NativeLoaderConfigParser, NamesAndComments) { |
| 478 | const char file_content[] = R"( |
| 479 | ###### |
| 480 | |
| 481 | libA.so |
| 482 | #libB.so |
| 483 | |
| 484 | |
| 485 | libC.so |
| 486 | libD.so |
| 487 | #### libE.so |
| 488 | )"; |
| 489 | const std::vector<std::string> expected_result = {"libA.so", "libC.so", "libD.so"}; |
| 490 | Result<std::vector<std::string>> result = ParseConfig(file_content, always_true); |
Bernie Innocenti | ac5ae3c | 2020-02-12 10:43:42 +0900 | [diff] [blame] | 491 | ASSERT_RESULT_OK(result); |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 492 | ASSERT_EQ(expected_result, *result); |
| 493 | } |
| 494 | |
| 495 | TEST(NativeLoaderConfigParser, WithBitness) { |
| 496 | const char file_content[] = R"( |
| 497 | libA.so 32 |
| 498 | libB.so 64 |
| 499 | libC.so |
| 500 | )"; |
| 501 | #if defined(__LP64__) |
| 502 | const std::vector<std::string> expected_result = {"libB.so", "libC.so"}; |
| 503 | #else |
| 504 | const std::vector<std::string> expected_result = {"libA.so", "libC.so"}; |
| 505 | #endif |
| 506 | Result<std::vector<std::string>> result = ParseConfig(file_content, always_true); |
Bernie Innocenti | ac5ae3c | 2020-02-12 10:43:42 +0900 | [diff] [blame] | 507 | ASSERT_RESULT_OK(result); |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 508 | ASSERT_EQ(expected_result, *result); |
| 509 | } |
| 510 | |
| 511 | TEST(NativeLoaderConfigParser, WithNoPreload) { |
| 512 | const char file_content[] = R"( |
| 513 | libA.so nopreload |
| 514 | libB.so nopreload |
| 515 | libC.so |
| 516 | )"; |
| 517 | |
| 518 | const std::vector<std::string> expected_result = {"libC.so"}; |
| 519 | Result<std::vector<std::string>> result = |
| 520 | ParseConfig(file_content, |
| 521 | [](const struct ConfigEntry& entry) -> Result<bool> { return !entry.nopreload; }); |
Bernie Innocenti | ac5ae3c | 2020-02-12 10:43:42 +0900 | [diff] [blame] | 522 | ASSERT_RESULT_OK(result); |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 523 | ASSERT_EQ(expected_result, *result); |
| 524 | } |
| 525 | |
| 526 | TEST(NativeLoaderConfigParser, WithNoPreloadAndBitness) { |
| 527 | const char file_content[] = R"( |
| 528 | libA.so nopreload 32 |
| 529 | libB.so 64 nopreload |
| 530 | libC.so 32 |
| 531 | libD.so 64 |
| 532 | libE.so nopreload |
| 533 | )"; |
| 534 | |
| 535 | #if defined(__LP64__) |
| 536 | const std::vector<std::string> expected_result = {"libD.so"}; |
| 537 | #else |
| 538 | const std::vector<std::string> expected_result = {"libC.so"}; |
| 539 | #endif |
| 540 | Result<std::vector<std::string>> result = |
| 541 | ParseConfig(file_content, |
| 542 | [](const struct ConfigEntry& entry) -> Result<bool> { return !entry.nopreload; }); |
Bernie Innocenti | ac5ae3c | 2020-02-12 10:43:42 +0900 | [diff] [blame] | 543 | ASSERT_RESULT_OK(result); |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 544 | ASSERT_EQ(expected_result, *result); |
| 545 | } |
| 546 | |
| 547 | TEST(NativeLoaderConfigParser, RejectMalformed) { |
Bernie Innocenti | ac5ae3c | 2020-02-12 10:43:42 +0900 | [diff] [blame] | 548 | ASSERT_FALSE(ParseConfig("libA.so 32 64", always_true).ok()); |
| 549 | ASSERT_FALSE(ParseConfig("libA.so 32 32", always_true).ok()); |
| 550 | ASSERT_FALSE(ParseConfig("libA.so 32 nopreload 64", always_true).ok()); |
| 551 | ASSERT_FALSE(ParseConfig("32 libA.so nopreload", always_true).ok()); |
| 552 | ASSERT_FALSE(ParseConfig("nopreload libA.so 32", always_true).ok()); |
| 553 | ASSERT_FALSE(ParseConfig("libA.so nopreload # comment", always_true).ok()); |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 554 | } |
| 555 | |
Jooyung Han | cd616d0 | 2020-09-01 14:53:23 +0900 | [diff] [blame] | 556 | TEST(NativeLoaderApexLibrariesConfigParser, BasicLoading) { |
Jooyung Han | 538f99a | 2020-03-03 00:46:50 +0900 | [diff] [blame] | 557 | const char file_content[] = R"( |
| 558 | # comment |
Jooyung Han | cd616d0 | 2020-09-01 14:53:23 +0900 | [diff] [blame] | 559 | jni com_android_foo libfoo.so |
Jooyung Han | 538f99a | 2020-03-03 00:46:50 +0900 | [diff] [blame] | 560 | # Empty line is ignored |
| 561 | |
Jooyung Han | cd616d0 | 2020-09-01 14:53:23 +0900 | [diff] [blame] | 562 | jni com_android_bar libbar.so:libbar2.so |
| 563 | |
| 564 | public com_android_bar libpublic.so |
Jooyung Han | 538f99a | 2020-03-03 00:46:50 +0900 | [diff] [blame] | 565 | )"; |
| 566 | |
Martin Stjernholm | 8a9b51e | 2024-01-30 21:33:09 +0000 | [diff] [blame] | 567 | Result<std::map<std::string, std::string>> jni_libs = |
| 568 | ParseApexLibrariesConfig(file_content, "jni"); |
Jooyung Han | cd616d0 | 2020-09-01 14:53:23 +0900 | [diff] [blame] | 569 | ASSERT_RESULT_OK(jni_libs); |
| 570 | std::map<std::string, std::string> expected_jni_libs { |
Jooyung Han | 538f99a | 2020-03-03 00:46:50 +0900 | [diff] [blame] | 571 | {"com_android_foo", "libfoo.so"}, |
| 572 | {"com_android_bar", "libbar.so:libbar2.so"}, |
| 573 | }; |
Jooyung Han | cd616d0 | 2020-09-01 14:53:23 +0900 | [diff] [blame] | 574 | ASSERT_EQ(expected_jni_libs, *jni_libs); |
Jooyung Han | 538f99a | 2020-03-03 00:46:50 +0900 | [diff] [blame] | 575 | |
Martin Stjernholm | 8a9b51e | 2024-01-30 21:33:09 +0000 | [diff] [blame] | 576 | Result<std::map<std::string, std::string>> public_libs = |
| 577 | ParseApexLibrariesConfig(file_content, "public"); |
Jooyung Han | cd616d0 | 2020-09-01 14:53:23 +0900 | [diff] [blame] | 578 | ASSERT_RESULT_OK(public_libs); |
| 579 | std::map<std::string, std::string> expected_public_libs { |
| 580 | {"com_android_bar", "libpublic.so"}, |
| 581 | }; |
| 582 | ASSERT_EQ(expected_public_libs, *public_libs); |
Jooyung Han | 538f99a | 2020-03-03 00:46:50 +0900 | [diff] [blame] | 583 | } |
| 584 | |
Jooyung Han | cd616d0 | 2020-09-01 14:53:23 +0900 | [diff] [blame] | 585 | TEST(NativeLoaderApexLibrariesConfigParser, RejectMalformedLine) { |
| 586 | const char file_content[] = R"( |
| 587 | jni com_android_foo libfoo |
| 588 | # missing <library list> |
| 589 | jni com_android_bar |
| 590 | )"; |
Martin Stjernholm | 8a9b51e | 2024-01-30 21:33:09 +0000 | [diff] [blame] | 591 | Result<std::map<std::string, std::string>> result = ParseApexLibrariesConfig(file_content, "jni"); |
Jooyung Han | cd616d0 | 2020-09-01 14:53:23 +0900 | [diff] [blame] | 592 | ASSERT_FALSE(result.ok()); |
| 593 | ASSERT_EQ("Malformed line \"jni com_android_bar\"", result.error().message()); |
Jooyung Han | 538f99a | 2020-03-03 00:46:50 +0900 | [diff] [blame] | 594 | } |
| 595 | |
Jooyung Han | cd616d0 | 2020-09-01 14:53:23 +0900 | [diff] [blame] | 596 | TEST(NativeLoaderApexLibrariesConfigParser, RejectInvalidTag) { |
| 597 | const char file_content[] = R"( |
| 598 | jni apex1 lib |
| 599 | public apex2 lib |
| 600 | # unknown tag |
| 601 | unknown com_android_foo libfoo |
| 602 | )"; |
Martin Stjernholm | 8a9b51e | 2024-01-30 21:33:09 +0000 | [diff] [blame] | 603 | Result<std::map<std::string, std::string>> result = ParseApexLibrariesConfig(file_content, "jni"); |
Jooyung Han | cd616d0 | 2020-09-01 14:53:23 +0900 | [diff] [blame] | 604 | ASSERT_FALSE(result.ok()); |
| 605 | ASSERT_EQ("Invalid tag \"unknown com_android_foo libfoo\"", result.error().message()); |
| 606 | } |
| 607 | |
| 608 | TEST(NativeLoaderApexLibrariesConfigParser, RejectInvalidApexNamespace) { |
| 609 | const char file_content[] = R"( |
| 610 | # apex linker namespace should be mangled ('.' -> '_') |
| 611 | jni com.android.foo lib |
| 612 | )"; |
Martin Stjernholm | 8a9b51e | 2024-01-30 21:33:09 +0000 | [diff] [blame] | 613 | Result<std::map<std::string, std::string>> result = ParseApexLibrariesConfig(file_content, "jni"); |
Jooyung Han | cd616d0 | 2020-09-01 14:53:23 +0900 | [diff] [blame] | 614 | ASSERT_FALSE(result.ok()); |
| 615 | ASSERT_EQ("Invalid apex_namespace \"jni com.android.foo lib\"", result.error().message()); |
| 616 | } |
| 617 | |
| 618 | TEST(NativeLoaderApexLibrariesConfigParser, RejectInvalidLibraryList) { |
| 619 | const char file_content[] = R"( |
| 620 | # library list is ":" separated list of filenames |
| 621 | jni com_android_foo lib64/libfoo.so |
| 622 | )"; |
Martin Stjernholm | 8a9b51e | 2024-01-30 21:33:09 +0000 | [diff] [blame] | 623 | Result<std::map<std::string, std::string>> result = ParseApexLibrariesConfig(file_content, "jni"); |
Jooyung Han | cd616d0 | 2020-09-01 14:53:23 +0900 | [diff] [blame] | 624 | ASSERT_FALSE(result.ok()); |
| 625 | ASSERT_EQ("Invalid library_list \"jni com_android_foo lib64/libfoo.so\"", result.error().message()); |
| 626 | } |
| 627 | |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 628 | } // namespace nativeloader |
| 629 | } // namespace android |
Nicolas Geoffray | 7ca8b67 | 2020-04-24 15:43:48 +0100 | [diff] [blame] | 630 | |
| 631 | #endif // defined(ART_TARGET_ANDROID) |