summaryrefslogtreecommitdiff
path: root/libnativeloader/native_loader_test.cpp
diff options
context:
space:
mode:
authorMartin Stjernholm <mast@google.com>2020-09-04 00:49:44 +0100
committerMartin Stjernholm <mast@google.com>2020-09-07 14:59:33 +0000
commitb309240781b17ee994d088648d5fc76814dde436 (patch)
treea62c1d3a10063d1b0b4b11b5f128a5f03398fa59 /libnativeloader/native_loader_test.cpp
parentfa37ba22d1e996ad785f94819be286abfae2aae5 (diff)
Fix libnativeloader unit tests being skipped.
ART_TARGET_ANDROID was only defined in art_defaults, which wasn't imported into libnativeloader_test. However doing that imports a lot of stuff, including compiler pickiness that doesn't work with cxxabi.h included via gtest.h. We instead make ART_TARGET_(ANDROID|LINUX) implicitly defined in all art_cc_* module types. These tests have probably not run since https://r.android.com/1295365. Also fixed the accumulated bitrot. Test: atest libnativeloader_test, check that 25 tests pass. Test: Plant a test failure in native_loader_test.cpp, check that presubmit fails. Bug: 154074847 Bug: 137356719 Change-Id: I4e9d4dc8d78c91a7b750b8de0ab7db2114b154ac
Diffstat (limited to 'libnativeloader/native_loader_test.cpp')
-rw-r--r--libnativeloader/native_loader_test.cpp28
1 files changed, 17 insertions, 11 deletions
diff --git a/libnativeloader/native_loader_test.cpp b/libnativeloader/native_loader_test.cpp
index e64e1a518c..81109b6008 100644
--- a/libnativeloader/native_loader_test.cpp
+++ b/libnativeloader/native_loader_test.cpp
@@ -20,6 +20,7 @@
#include <memory>
#include <unordered_map>
+#include <android-base/stringprintf.h>
#include <android-base/strings.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
@@ -95,14 +96,17 @@ class Platform {
// These represents built-in namespaces created by the linker according to ld.config.txt
static std::unordered_map<std::string, Platform::mock_namespace_handle> namespaces = {
- {"system", TO_MOCK_NAMESPACE(TO_ANDROID_NAMESPACE("system"))},
- {"default", TO_MOCK_NAMESPACE(TO_ANDROID_NAMESPACE("default"))},
- {"com_android_i18n", TO_MOCK_NAMESPACE(TO_ANDROID_NAMESPACE("com_android_i18n"))},
- {"sphal", TO_MOCK_NAMESPACE(TO_ANDROID_NAMESPACE("sphal"))},
- {"vndk", TO_MOCK_NAMESPACE(TO_ANDROID_NAMESPACE("vndk"))},
- {"vndk_product", TO_MOCK_NAMESPACE(TO_ANDROID_NAMESPACE("vndk_product"))},
- {"com_android_neuralnetworks", TO_MOCK_NAMESPACE(TO_ANDROID_NAMESPACE("com_android_neuralnetworks"))},
- {"com_android_os_statsd", TO_MOCK_NAMESPACE(TO_ANDROID_NAMESPACE("com_android_os_statsd"))},
+#define NAMESPACE_ENTRY(ns) {ns, TO_MOCK_NAMESPACE(TO_ANDROID_NAMESPACE(ns))}
+ NAMESPACE_ENTRY("com_android_i18n"),
+ NAMESPACE_ENTRY("com_android_neuralnetworks"),
+ NAMESPACE_ENTRY("com_android_os_statsd"),
+ NAMESPACE_ENTRY("com_android_art"),
+ NAMESPACE_ENTRY("default"),
+ NAMESPACE_ENTRY("sphal"),
+ NAMESPACE_ENTRY("system"),
+ NAMESPACE_ENTRY("vndk"),
+ NAMESPACE_ENTRY("vndk_product"),
+#undef NAMESPACE_ENTRY
};
// The actual gmock object
@@ -116,7 +120,9 @@ class MockPlatform : public Platform {
if (namespaces.find(name) != namespaces.end()) {
return namespaces[name];
}
- return TO_MOCK_NAMESPACE(TO_ANDROID_NAMESPACE("(namespace not found"));
+ std::string msg = android::base::StringPrintf("(namespace %s not found)", name);
+ // The strdup'ed string will leak, but the test is already failing if we get here.
+ return TO_MOCK_NAMESPACE(TO_ANDROID_NAMESPACE(strdup(msg.c_str())));
}));
}
@@ -438,7 +444,7 @@ class NativeLoaderTest_Create : public NativeLoaderTest {
jstring err = CreateClassLoaderNamespace(
env(), target_sdk_version, env()->NewStringUTF(class_loader.c_str()), is_shared,
env()->NewStringUTF(dex_path.c_str()), env()->NewStringUTF(library_path.c_str()),
- env()->NewStringUTF(permitted_path.c_str()));
+ env()->NewStringUTF(permitted_path.c_str()), /*uses_library_list=*/ nullptr);
// no error
EXPECT_EQ(err, nullptr) << "Error is: " << std::string(ScopedUtfChars(env(), err).c_str());
@@ -579,7 +585,7 @@ TEST_P(NativeLoaderTest_Create, TwoApks) {
env(), second_app_target_sdk_version, env()->NewStringUTF(second_app_class_loader.c_str()),
second_app_is_shared, env()->NewStringUTF(second_app_dex_path.c_str()),
env()->NewStringUTF(second_app_library_path.c_str()),
- env()->NewStringUTF(second_app_permitted_path.c_str()));
+ env()->NewStringUTF(second_app_permitted_path.c_str()), /*uses_library_list=*/ nullptr);
// success
EXPECT_EQ(err, nullptr) << "Error is: " << std::string(ScopedUtfChars(env(), err).c_str());