Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Add test for a greylisted library
Browse files Browse the repository at this point in the history
Test: bionic-unit-tests --gtest_filter=dlext.ns*
Bug: http://b/35338922
Change-Id: I2f4895cb1ec458c2f565a7e4d06f7a1f6200e7aa
  • Loading branch information
dimitry- committed Feb 23, 2017
1 parent c84e8a5 commit 1862314
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/dlext_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,37 @@ TEST(dlext, ns_unload_between_namespaces) {
"\" wasn't loaded and RTLD_NOLOAD prevented it", dlerror());
}

TEST(dlext, ns_greylist) {
ASSERT_TRUE(android_init_anonymous_namespace(g_core_shared_libs.c_str(), nullptr));

const std::string ns_search_path = get_testlib_root() + "/private_namespace_libs";

android_namespace_t* ns =
android_create_namespace("namespace",
nullptr,
ns_search_path.c_str(),
ANDROID_NAMESPACE_TYPE_ISOLATED,
nullptr,
nullptr);

ASSERT_TRUE(android_link_namespaces(ns, nullptr, g_core_shared_libs.c_str())) << dlerror();

android_dlextinfo extinfo;
extinfo.flags = ANDROID_DLEXT_USE_NAMESPACE;
extinfo.library_namespace = ns;

android_set_application_target_sdk_version(__ANDROID_API_M__);
void* handle = android_dlopen_ext("libnativehelper.so", RTLD_NOW, &extinfo);
ASSERT_TRUE(handle != nullptr) << dlerror();

dlclose(handle);

android_set_application_target_sdk_version(__ANDROID_API_N__);
handle = android_dlopen_ext("libnativehelper.so", RTLD_NOW, &extinfo);
ASSERT_TRUE(handle == nullptr);
ASSERT_STREQ("dlopen failed: library \"libnativehelper.so\" not found", dlerror());
}

TEST(dlext, ns_cyclic_namespaces) {
// Test that ns1->ns2->ns1 link does not break the loader
ASSERT_TRUE(android_init_anonymous_namespace(g_core_shared_libs.c_str(), nullptr));
Expand Down

0 comments on commit 1862314

Please sign in to comment.