Merge changes I5667e991,I9d2a873e
* changes:
bionic-unit-tests: remove dependency on ANDROID_DATA
bionic-unit-tests: Create symlinks in runtime
diff --git a/tests/Android.bp b/tests/Android.bp
index 4caaa54..3e1e13b 100644
--- a/tests/Android.bp
+++ b/tests/Android.bp
@@ -250,7 +250,16 @@
cc_test_library {
name: "libBionicGtestMain",
defaults: ["bionic_tests_defaults"],
- srcs: ["gtest_main.cpp"],
+ srcs: [
+ "gtest_main.cpp",
+ "gtest_globals.cpp",
+ ],
+ static_libs: [
+ "libbase",
+ ],
+ include_dirs: [
+ "bionic/libc",
+ ],
target: {
darwin: {
enabled: true,
@@ -267,6 +276,7 @@
srcs: [
"atexit_test.cpp",
"dl_test.cpp",
+ "dlfcn_symlink_support.cpp",
"dlfcn_test.cpp",
"pthread_dlfcn_test.cpp",
],
@@ -299,7 +309,10 @@
cc_test_library {
name: "libBionicCtsGtestMain",
defaults: ["bionic_tests_defaults"],
- srcs: ["gtest_main.cpp"],
+ srcs: [
+ "gtest_main.cpp",
+ "gtest_globals_cts.cpp",
+ ],
cppflags: ["-DUSING_GTEST_OUTPUT_FORMAT"],
shared: {
enabled: false,
@@ -426,6 +439,7 @@
srcs: [
"atexit_test.cpp",
+ "dlfcn_symlink_support.cpp",
"dlfcn_test.cpp",
"dl_test.cpp",
"pthread_dlfcn_test.cpp",
diff --git a/tests/dlext_test.cpp b/tests/dlext_test.cpp
index f597e61..8527b00 100644
--- a/tests/dlext_test.cpp
+++ b/tests/dlext_test.cpp
@@ -32,9 +32,11 @@
#include <pagemap/pagemap.h>
#include <ziparchive/zip_archive.h>
+#include "gtest_globals.h"
#include "TemporaryFile.h"
#include "utils.h"
#include "dlext_private.h"
+#include "dlfcn_symlink_support.h"
#define ASSERT_DL_NOTNULL(ptr) \
ASSERT_TRUE((ptr) != nullptr) << "dlerror: " << dlerror()
@@ -50,32 +52,22 @@
typedef int (*fn)(void);
-#define LIBNAME "libdlext_test.so"
-#define LIBNAME_NORELRO "libdlext_test_norelro.so"
-constexpr auto LIBSIZE = 1024 * 1024; // how much address space to reserve for it
-
-#if defined(__LP64__)
-#define NATIVE_TESTS_PATH "/nativetest64/bionic-loader-test-libs"
-#else
-#define NATIVE_TESTS_PATH "/nativetest/bionic-loader-test-libs"
-#endif
-
-#define LIBPATH NATIVE_TESTS_PATH "/libdlext_test_fd/libdlext_test_fd.so"
-#define LIBZIPPATH NATIVE_TESTS_PATH "/libdlext_test_zip/libdlext_test_zip_zipaligned.zip"
-#define LIBZIPPATH_WITH_RUNPATH NATIVE_TESTS_PATH "/libdlext_test_runpath_zip/libdlext_test_runpath_zip_zipaligned.zip"
-#define LIBZIP_SIMPLE_ZIP "libdir/libatest_simple_zip.so"
+constexpr const char* kLibName = "libdlext_test.so";
+constexpr const char* kLibNameNoRelro = "libdlext_test_norelro.so";
+constexpr const char* kLibZipSimpleZip = "libdir/libatest_simple_zip.so";
+constexpr auto kLibSize = 1024 * 1024; // how much address space to reserve for it
class DlExtTest : public ::testing::Test {
protected:
virtual void SetUp() {
handle_ = nullptr;
// verify that we don't have the library loaded already
- void* h = dlopen(LIBNAME, RTLD_NOW | RTLD_NOLOAD);
+ void* h = dlopen(kLibName, RTLD_NOW | RTLD_NOLOAD);
ASSERT_TRUE(h == nullptr);
- h = dlopen(LIBNAME_NORELRO, RTLD_NOW | RTLD_NOLOAD);
+ h = dlopen(kLibNameNoRelro, RTLD_NOW | RTLD_NOLOAD);
ASSERT_TRUE(h == nullptr);
// call dlerror() to swallow the error, and check it was the one we wanted
- ASSERT_STREQ("dlopen failed: library \"" LIBNAME_NORELRO "\" wasn't loaded and RTLD_NOLOAD prevented it", dlerror());
+ ASSERT_EQ(std::string("dlopen failed: library \"") + kLibNameNoRelro + "\" wasn't loaded and RTLD_NOLOAD prevented it", dlerror());
}
virtual void TearDown() {
@@ -88,7 +80,7 @@
};
TEST_F(DlExtTest, ExtInfoNull) {
- handle_ = android_dlopen_ext(LIBNAME, RTLD_NOW, nullptr);
+ handle_ = android_dlopen_ext(kLibName, RTLD_NOW, nullptr);
ASSERT_DL_NOTNULL(handle_);
fn f = reinterpret_cast<fn>(dlsym(handle_, "getRandomNumber"));
ASSERT_DL_NOTNULL(f);
@@ -98,7 +90,7 @@
TEST_F(DlExtTest, ExtInfoNoFlags) {
android_dlextinfo extinfo;
extinfo.flags = 0;
- handle_ = android_dlopen_ext(LIBNAME, RTLD_NOW, &extinfo);
+ handle_ = android_dlopen_ext(kLibName, RTLD_NOW, &extinfo);
ASSERT_DL_NOTNULL(handle_);
fn f = reinterpret_cast<fn>(dlsym(handle_, "getRandomNumber"));
ASSERT_DL_NOTNULL(f);
@@ -106,7 +98,7 @@
}
TEST_F(DlExtTest, ExtInfoUseFd) {
- const std::string lib_path = std::string(getenv("ANDROID_DATA")) + LIBPATH;
+ const std::string lib_path = g_testlib_root + "/libdlext_test_fd/libdlext_test_fd.so";
android_dlextinfo extinfo;
extinfo.flags = ANDROID_DLEXT_USE_LIBRARY_FD;
@@ -124,7 +116,7 @@
}
TEST_F(DlExtTest, ExtInfoUseFdWithOffset) {
- const std::string lib_path = std::string(getenv("ANDROID_DATA")) + LIBZIPPATH;
+ const std::string lib_path = g_testlib_root + "/libdlext_test_zip/libdlext_test_zip_zipaligned.zip";
android_dlextinfo extinfo;
extinfo.flags = ANDROID_DLEXT_USE_LIBRARY_FD | ANDROID_DLEXT_USE_LIBRARY_FD_OFFSET;
@@ -135,8 +127,8 @@
ASSERT_EQ(0, OpenArchive(lib_path.c_str(), &handle));
ZipEntry zip_entry;
ZipString zip_name;
- zip_name.name = reinterpret_cast<const uint8_t*>(LIBZIP_SIMPLE_ZIP);
- zip_name.name_length = sizeof(LIBZIP_SIMPLE_ZIP) - 1;
+ zip_name.name = reinterpret_cast<const uint8_t*>(kLibZipSimpleZip);
+ zip_name.name_length = strlen(kLibZipSimpleZip);
ASSERT_EQ(0, FindEntry(handle, zip_name, &zip_entry));
extinfo.library_fd_offset = zip_entry.offset;
CloseArchive(handle);
@@ -150,9 +142,7 @@
}
TEST_F(DlExtTest, ExtInfoUseFdWithInvalidOffset) {
- // lib_path is relative when $ANDROID_DATA is relative
- std::string lib_path;
- ASSERT_TRUE(get_realpath(std::string(getenv("ANDROID_DATA")) + LIBZIPPATH, &lib_path)) << strerror(errno);
+ const std::string lib_path = g_testlib_root + "/libdlext_test_zip/libdlext_test_zip_zipaligned.zip";
android_dlextinfo extinfo;
extinfo.flags = ANDROID_DLEXT_USE_LIBRARY_FD | ANDROID_DLEXT_USE_LIBRARY_FD_OFFSET;
@@ -199,13 +189,15 @@
}
TEST(dlext, android_dlopen_ext_force_load_smoke) {
+ DlfcnSymlink symlink("android_dlopen_ext_force_load_smoke");
+ const std::string symlink_name = basename(symlink.get_symlink_path().c_str());
// 1. Open actual file
void* handle = dlopen("libdlext_test.so", RTLD_NOW);
ASSERT_DL_NOTNULL(handle);
// 2. Open link with force_load flag set
android_dlextinfo extinfo;
extinfo.flags = ANDROID_DLEXT_FORCE_LOAD;
- void* handle2 = android_dlopen_ext("libdlext_test_v2.so", RTLD_NOW, &extinfo);
+ void* handle2 = android_dlopen_ext(symlink_name.c_str(), RTLD_NOW, &extinfo);
ASSERT_DL_NOTNULL(handle2);
ASSERT_TRUE(handle != handle2);
@@ -214,15 +206,17 @@
}
TEST(dlext, android_dlopen_ext_force_load_soname_exception) {
+ DlfcnSymlink symlink("android_dlopen_ext_force_load_soname_exception");
+ const std::string symlink_name = basename(symlink.get_symlink_path().c_str());
// Check if soname lookup still returns already loaded library
// when ANDROID_DLEXT_FORCE_LOAD flag is specified.
- void* handle = dlopen("libdlext_test_v2.so", RTLD_NOW);
+ void* handle = dlopen(symlink_name.c_str(), RTLD_NOW);
ASSERT_DL_NOTNULL(handle);
android_dlextinfo extinfo;
extinfo.flags = ANDROID_DLEXT_FORCE_LOAD;
- // Note that 'libdlext_test.so' is dt_soname for libdlext_test_v2.so
+ // Note that 'libdlext_test.so' is dt_soname for the symlink_name
void* handle2 = android_dlopen_ext("libdlext_test.so", RTLD_NOW, &extinfo);
ASSERT_DL_NOTNULL(handle2);
@@ -233,8 +227,8 @@
}
TEST(dlfcn, dlopen_from_zip_absolute_path) {
- std::string lib_path;
- ASSERT_TRUE(get_realpath(std::string(getenv("ANDROID_DATA")) + LIBZIPPATH, &lib_path)) << strerror(errno);
+ const std::string lib_zip_path = "/libdlext_test_zip/libdlext_test_zip_zipaligned.zip";
+ const std::string lib_path = g_testlib_root + lib_zip_path;
void* handle = dlopen((lib_path + "!/libdir/libatest_simple_zip.so").c_str(), RTLD_NOW);
ASSERT_TRUE(handle != nullptr) << dlerror();
@@ -247,9 +241,8 @@
}
TEST(dlfcn, dlopen_from_zip_with_dt_runpath) {
- std::string data_path;
- ASSERT_TRUE(get_realpath(std::string(getenv("ANDROID_DATA")), &data_path)) << strerror(errno);
- const std::string lib_path = data_path + LIBZIPPATH_WITH_RUNPATH;
+ const std::string lib_zip_path = "/libdlext_test_runpath_zip/libdlext_test_runpath_zip_zipaligned.zip";
+ const std::string lib_path = g_testlib_root + lib_zip_path;
void* handle = dlopen((lib_path + "!/libdir/libtest_dt_runpath_d_zip.so").c_str(), RTLD_NOW);
@@ -267,9 +260,8 @@
}
TEST(dlfcn, dlopen_from_zip_ld_library_path) {
- std::string data_path;
- ASSERT_TRUE(get_realpath(std::string(getenv("ANDROID_DATA")), &data_path)) << strerror(errno);
- const std::string lib_path = data_path + LIBZIPPATH + "!/libdir";
+ const std::string lib_zip_path = "/libdlext_test_zip/libdlext_test_zip_zipaligned.zip";
+ const std::string lib_path = g_testlib_root + lib_zip_path + "!/libdir";
typedef void (*fn_t)(const char*);
fn_t android_update_LD_LIBRARY_PATH =
@@ -300,19 +292,19 @@
TEST_F(DlExtTest, Reserved) {
- void* start = mmap(nullptr, LIBSIZE, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ void* start = mmap(nullptr, kLibSize, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
ASSERT_TRUE(start != MAP_FAILED);
android_dlextinfo extinfo;
extinfo.flags = ANDROID_DLEXT_RESERVED_ADDRESS;
extinfo.reserved_addr = start;
- extinfo.reserved_size = LIBSIZE;
- handle_ = android_dlopen_ext(LIBNAME, RTLD_NOW, &extinfo);
+ extinfo.reserved_size = kLibSize;
+ handle_ = android_dlopen_ext(kLibName, RTLD_NOW, &extinfo);
ASSERT_DL_NOTNULL(handle_);
fn f = reinterpret_cast<fn>(dlsym(handle_, "getRandomNumber"));
ASSERT_DL_NOTNULL(f);
EXPECT_GE(reinterpret_cast<void*>(f), start);
EXPECT_LT(reinterpret_cast<void*>(f),
- reinterpret_cast<char*>(start) + LIBSIZE);
+ reinterpret_cast<char*>(start) + kLibSize);
EXPECT_EQ(4, f());
// Check that after dlclose reserved address space is unmapped (and can be reused)
@@ -330,24 +322,24 @@
extinfo.flags = ANDROID_DLEXT_RESERVED_ADDRESS;
extinfo.reserved_addr = start;
extinfo.reserved_size = PAGE_SIZE;
- handle_ = android_dlopen_ext(LIBNAME, RTLD_NOW, &extinfo);
+ handle_ = android_dlopen_ext(kLibName, RTLD_NOW, &extinfo);
EXPECT_EQ(nullptr, handle_);
}
TEST_F(DlExtTest, ReservedHint) {
- void* start = mmap(nullptr, LIBSIZE, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ void* start = mmap(nullptr, kLibSize, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
ASSERT_TRUE(start != MAP_FAILED);
android_dlextinfo extinfo;
extinfo.flags = ANDROID_DLEXT_RESERVED_ADDRESS_HINT;
extinfo.reserved_addr = start;
- extinfo.reserved_size = LIBSIZE;
- handle_ = android_dlopen_ext(LIBNAME, RTLD_NOW, &extinfo);
+ extinfo.reserved_size = kLibSize;
+ handle_ = android_dlopen_ext(kLibName, RTLD_NOW, &extinfo);
ASSERT_DL_NOTNULL(handle_);
fn f = reinterpret_cast<fn>(dlsym(handle_, "getRandomNumber"));
ASSERT_DL_NOTNULL(f);
EXPECT_GE(reinterpret_cast<void*>(f), start);
EXPECT_LT(reinterpret_cast<void*>(f),
- reinterpret_cast<char*>(start) + LIBSIZE);
+ reinterpret_cast<char*>(start) + kLibSize);
EXPECT_EQ(4, f());
}
@@ -358,7 +350,7 @@
extinfo.flags = ANDROID_DLEXT_RESERVED_ADDRESS_HINT;
extinfo.reserved_addr = start;
extinfo.reserved_size = PAGE_SIZE;
- handle_ = android_dlopen_ext(LIBNAME, RTLD_NOW, &extinfo);
+ handle_ = android_dlopen_ext(kLibName, RTLD_NOW, &extinfo);
ASSERT_DL_NOTNULL(handle_);
fn f = reinterpret_cast<fn>(dlsym(handle_, "getRandomNumber"));
ASSERT_DL_NOTNULL(f);
@@ -369,36 +361,36 @@
}
TEST_F(DlExtTest, LoadAtFixedAddress) {
- void* start = mmap(nullptr, LIBSIZE, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ void* start = mmap(nullptr, kLibSize, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
ASSERT_TRUE(start != MAP_FAILED);
- munmap(start, LIBSIZE);
+ munmap(start, kLibSize);
android_dlextinfo extinfo;
extinfo.flags = ANDROID_DLEXT_LOAD_AT_FIXED_ADDRESS;
extinfo.reserved_addr = start;
- handle_ = android_dlopen_ext(LIBNAME, RTLD_NOW, &extinfo);
+ handle_ = android_dlopen_ext(kLibName, RTLD_NOW, &extinfo);
ASSERT_DL_NOTNULL(handle_);
fn f = reinterpret_cast<fn>(dlsym(handle_, "getRandomNumber"));
ASSERT_DL_NOTNULL(f);
EXPECT_GE(reinterpret_cast<void*>(f), start);
- EXPECT_LT(reinterpret_cast<void*>(f), reinterpret_cast<char*>(start) + LIBSIZE);
+ EXPECT_LT(reinterpret_cast<void*>(f), reinterpret_cast<char*>(start) + kLibSize);
EXPECT_EQ(4, f());
dlclose(handle_);
handle_ = nullptr;
// Check that dlclose unmapped the file
- void* addr = mmap(start, LIBSIZE, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ void* addr = mmap(start, kLibSize, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
ASSERT_EQ(start, addr) << "dlclose did not unmap the memory";
}
TEST_F(DlExtTest, LoadAtFixedAddressTooSmall) {
- void* start = mmap(nullptr, LIBSIZE + PAGE_SIZE, PROT_NONE,
+ void* start = mmap(nullptr, kLibSize + PAGE_SIZE, PROT_NONE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
ASSERT_TRUE(start != MAP_FAILED);
- munmap(start, LIBSIZE + PAGE_SIZE);
- void* new_addr = mmap(reinterpret_cast<uint8_t*>(start) + PAGE_SIZE, LIBSIZE, PROT_NONE,
+ munmap(start, kLibSize + PAGE_SIZE);
+ void* new_addr = mmap(reinterpret_cast<uint8_t*>(start) + PAGE_SIZE, kLibSize, PROT_NONE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
ASSERT_TRUE(new_addr != MAP_FAILED);
@@ -406,7 +398,7 @@
extinfo.flags = ANDROID_DLEXT_LOAD_AT_FIXED_ADDRESS;
extinfo.reserved_addr = start;
- handle_ = android_dlopen_ext(LIBNAME, RTLD_NOW, &extinfo);
+ handle_ = android_dlopen_ext(kLibName, RTLD_NOW, &extinfo);
ASSERT_TRUE(handle_ == nullptr);
}
@@ -414,11 +406,11 @@
protected:
virtual void SetUp() {
DlExtTest::SetUp();
- void* start = mmap(nullptr, LIBSIZE, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ void* start = mmap(nullptr, kLibSize, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
ASSERT_TRUE(start != MAP_FAILED);
extinfo_.flags = ANDROID_DLEXT_RESERVED_ADDRESS;
extinfo_.reserved_addr = start;
- extinfo_.reserved_size = LIBSIZE;
+ extinfo_.reserved_size = kLibSize;
extinfo_.relro_fd = -1;
}
@@ -477,8 +469,8 @@
TemporaryFile tf; // Use tf to get an unique filename.
ASSERT_NOERROR(close(tf.fd));
- ASSERT_NO_FATAL_FAILURE(CreateRelroFile(LIBNAME, tf.filename));
- ASSERT_NO_FATAL_FAILURE(TryUsingRelro(LIBNAME));
+ ASSERT_NO_FATAL_FAILURE(CreateRelroFile(kLibName, tf.filename));
+ ASSERT_NO_FATAL_FAILURE(TryUsingRelro(kLibName));
// Use destructor of tf to close and unlink the file.
tf.fd = extinfo_.relro_fd;
@@ -488,15 +480,15 @@
TemporaryFile tf; // // Use tf to get an unique filename.
ASSERT_NOERROR(close(tf.fd));
- ASSERT_NO_FATAL_FAILURE(CreateRelroFile(LIBNAME_NORELRO, tf.filename));
- ASSERT_NO_FATAL_FAILURE(TryUsingRelro(LIBNAME_NORELRO));
+ ASSERT_NO_FATAL_FAILURE(CreateRelroFile(kLibNameNoRelro, tf.filename));
+ ASSERT_NO_FATAL_FAILURE(TryUsingRelro(kLibNameNoRelro));
// Use destructor of tf to close and unlink the file.
tf.fd = extinfo_.relro_fd;
}
TEST_F(DlExtRelroSharingTest, RelroFileEmpty) {
- ASSERT_NO_FATAL_FAILURE(TryUsingRelro(LIBNAME));
+ ASSERT_NO_FATAL_FAILURE(TryUsingRelro(kLibName));
}
TEST_F(DlExtRelroSharingTest, VerifyMemorySaving) {
@@ -508,14 +500,14 @@
TemporaryFile tf; // Use tf to get an unique filename.
ASSERT_NOERROR(close(tf.fd));
- ASSERT_NO_FATAL_FAILURE(CreateRelroFile(LIBNAME, tf.filename));
+ ASSERT_NO_FATAL_FAILURE(CreateRelroFile(kLibName, tf.filename));
int pipefd[2];
ASSERT_NOERROR(pipe(pipefd));
size_t without_sharing, with_sharing;
- ASSERT_NO_FATAL_FAILURE(SpawnChildrenAndMeasurePss(LIBNAME, false, &without_sharing));
- ASSERT_NO_FATAL_FAILURE(SpawnChildrenAndMeasurePss(LIBNAME, true, &with_sharing));
+ ASSERT_NO_FATAL_FAILURE(SpawnChildrenAndMeasurePss(kLibName, false, &without_sharing));
+ ASSERT_NO_FATAL_FAILURE(SpawnChildrenAndMeasurePss(kLibName, true, &with_sharing));
// We expect the sharing to save at least 10% of the total PSS. In practice
// it saves 40%+ for this test.
@@ -639,9 +631,7 @@
ASSERT_STREQ("android_init_namespaces failed: error initializing public namespace: "
"the list of public libraries is empty.", dlerror());
- const std::string lib_path = std::string(getenv("ANDROID_DATA")) + NATIVE_TESTS_PATH;
-
- const std::string lib_public_path = lib_path + "/public_namespace_libs/" + g_public_lib;
+ const std::string lib_public_path = g_testlib_root + "/public_namespace_libs/" + g_public_lib;
void* handle_public = dlopen(lib_public_path.c_str(), RTLD_NOW);
ASSERT_TRUE(handle_public != nullptr) << dlerror();
@@ -649,20 +639,20 @@
// Check that libraries added to public namespace are NODELETE
dlclose(handle_public);
- handle_public = dlopen((lib_path + "/public_namespace_libs/" + g_public_lib).c_str(),
+ handle_public = dlopen((g_testlib_root + "/public_namespace_libs/" + g_public_lib).c_str(),
RTLD_NOW | RTLD_NOLOAD);
ASSERT_TRUE(handle_public != nullptr) << dlerror();
android_namespace_t* ns1 =
android_create_namespace("private", nullptr,
- (lib_path + "/private_namespace_libs").c_str(),
+ (g_testlib_root + "/private_namespace_libs").c_str(),
ANDROID_NAMESPACE_TYPE_REGULAR, nullptr, nullptr);
ASSERT_TRUE(ns1 != nullptr) << dlerror();
android_namespace_t* ns2 =
android_create_namespace("private_isolated", nullptr,
- (lib_path + "/private_namespace_libs").c_str(),
+ (g_testlib_root + "/private_namespace_libs").c_str(),
ANDROID_NAMESPACE_TYPE_ISOLATED, nullptr, nullptr);
ASSERT_TRUE(ns2 != nullptr) << dlerror();
@@ -753,8 +743,7 @@
static const char* root_lib = "libnstest_root_not_isolated.so";
std::string path = std::string("libc.so:libc++.so:libdl.so:libm.so:") + g_public_lib;
- const std::string lib_path = std::string(getenv("ANDROID_DATA")) + NATIVE_TESTS_PATH;
- const std::string lib_public_path = lib_path + "/public_namespace_libs/" + g_public_lib;
+ const std::string lib_public_path = g_testlib_root + "/public_namespace_libs/" + g_public_lib;
void* handle_public = dlopen(lib_public_path.c_str(), RTLD_NOW);
ASSERT_TRUE(handle_public != nullptr) << dlerror();
@@ -764,14 +753,14 @@
android_namespace_t* ns_not_isolated =
android_create_namespace("private", nullptr,
- (lib_path + "/private_namespace_libs").c_str(),
+ (g_testlib_root + "/private_namespace_libs").c_str(),
ANDROID_NAMESPACE_TYPE_REGULAR, nullptr, nullptr);
ASSERT_TRUE(ns_not_isolated != nullptr) << dlerror();
android_namespace_t* ns_isolated =
android_create_namespace("private_isolated1",
nullptr,
- (lib_path + "/private_namespace_libs").c_str(),
+ (g_testlib_root + "/private_namespace_libs").c_str(),
ANDROID_NAMESPACE_TYPE_ISOLATED,
nullptr,
nullptr);
@@ -779,10 +768,10 @@
android_namespace_t* ns_isolated2 =
android_create_namespace("private_isolated2",
- (lib_path + "/private_namespace_libs").c_str(),
+ (g_testlib_root + "/private_namespace_libs").c_str(),
nullptr,
ANDROID_NAMESPACE_TYPE_ISOLATED,
- lib_path.c_str(),
+ g_testlib_root.c_str(),
nullptr);
ASSERT_TRUE(ns_isolated2 != nullptr) << dlerror();
@@ -790,7 +779,7 @@
ASSERT_STREQ("dlopen failed: library \"libnstest_root_not_isolated.so\" not found", dlerror());
std::string lib_private_external_path =
- lib_path + "/private_namespace_libs_external/libnstest_private_external.so";
+ g_testlib_root + "/private_namespace_libs_external/libnstest_private_external.so";
// Load lib_private_external_path to default namespace
// (it should remain invisible for the isolated namespaces after this)
@@ -819,7 +808,7 @@
extinfo.library_namespace = ns_isolated2;
- // this should work because isolation_path for private_isolated2 includes lib_path
+ // this should work because isolation_path for private_isolated2 includes g_testlib_root
handle2 = android_dlopen_ext(root_lib, RTLD_NOW, &extinfo);
ASSERT_TRUE(handle2 != nullptr) << dlerror();
dlclose(handle2);
@@ -860,8 +849,7 @@
static const char* root_lib_isolated = "libnstest_root.so";
std::string path = std::string("libc.so:libc++.so:libdl.so:libm.so:") + g_public_lib;
- const std::string lib_path = std::string(getenv("ANDROID_DATA")) + NATIVE_TESTS_PATH;
- const std::string lib_public_path = lib_path + "/public_namespace_libs/" + g_public_lib;
+ const std::string lib_public_path = g_testlib_root + "/public_namespace_libs/" + g_public_lib;
void* handle_public = dlopen(lib_public_path.c_str(), RTLD_NOW);
ASSERT_TRUE(handle_public != nullptr) << dlerror();
@@ -872,18 +860,18 @@
// preload this library to the default namespace to check if it
// is shared later on.
void* handle_dlopened =
- dlopen((lib_path + "/private_namespace_libs/libnstest_dlopened.so").c_str(), RTLD_NOW);
+ dlopen((g_testlib_root + "/private_namespace_libs/libnstest_dlopened.so").c_str(), RTLD_NOW);
ASSERT_TRUE(handle_dlopened != nullptr) << dlerror();
android_namespace_t* ns_not_isolated =
android_create_namespace("private", nullptr,
- (lib_path + "/private_namespace_libs").c_str(),
+ (g_testlib_root + "/private_namespace_libs").c_str(),
ANDROID_NAMESPACE_TYPE_REGULAR, nullptr, nullptr);
ASSERT_TRUE(ns_not_isolated != nullptr) << dlerror();
android_namespace_t* ns_isolated_shared =
android_create_namespace("private_isolated_shared", nullptr,
- (lib_path + "/private_namespace_libs").c_str(),
+ (g_testlib_root + "/private_namespace_libs").c_str(),
ANDROID_NAMESPACE_TYPE_ISOLATED | ANDROID_NAMESPACE_TYPE_SHARED,
nullptr, nullptr);
ASSERT_TRUE(ns_isolated_shared != nullptr) << dlerror();
@@ -892,7 +880,7 @@
ASSERT_STREQ("dlopen failed: library \"libnstest_root_not_isolated.so\" not found", dlerror());
std::string lib_private_external_path =
- lib_path + "/private_namespace_libs_external/libnstest_private_external.so";
+ g_testlib_root + "/private_namespace_libs_external/libnstest_private_external.so";
// Load lib_private_external_path to default namespace
// (it should remain invisible for the isolated namespaces after this)
@@ -976,8 +964,6 @@
TEST(dlext, ns_shared_dlclose) {
std::string path = "libc.so:libc++.so:libdl.so:libm.so";
- const std::string lib_path = std::string(getenv("ANDROID_DATA")) + NATIVE_TESTS_PATH;
-
android_set_application_target_sdk_version(42U); // something > 23
ASSERT_TRUE(android_init_namespaces(path.c_str(), nullptr)) << dlerror();
@@ -985,12 +971,12 @@
// preload this library to the default namespace to check if it
// is shared later on.
void* handle_dlopened =
- dlopen((lib_path + "/private_namespace_libs/libnstest_dlopened.so").c_str(), RTLD_NOW);
+ dlopen((g_testlib_root + "/private_namespace_libs/libnstest_dlopened.so").c_str(), RTLD_NOW);
ASSERT_TRUE(handle_dlopened != nullptr) << dlerror();
android_namespace_t* ns_isolated_shared =
android_create_namespace("private_isolated_shared", nullptr,
- (lib_path + "/private_namespace_libs").c_str(),
+ (g_testlib_root + "/private_namespace_libs").c_str(),
ANDROID_NAMESPACE_TYPE_ISOLATED | ANDROID_NAMESPACE_TYPE_SHARED,
nullptr, nullptr);
ASSERT_TRUE(ns_isolated_shared != nullptr) << dlerror();
@@ -1011,7 +997,7 @@
ASSERT_TRUE(handle == nullptr)
<< "Error: libnstest_dlopened.so is still accessible in shared namespace";
- handle = android_dlopen_ext((lib_path + "/private_namespace_libs/libnstest_dlopened.so").c_str(),
+ handle = android_dlopen_ext((g_testlib_root + "/private_namespace_libs/libnstest_dlopened.so").c_str(),
RTLD_NOW | RTLD_NOLOAD, &extinfo);
ASSERT_TRUE(handle == nullptr)
<< "Error: libnstest_dlopened.so is still accessible in shared namespace";
@@ -1020,14 +1006,14 @@
ASSERT_TRUE(handle == nullptr)
<< "Error: libnstest_dlopened.so is still accessible in default namespace";
- handle = dlopen((lib_path + "/private_namespace_libs/libnstest_dlopened.so").c_str(),
+ handle = dlopen((g_testlib_root + "/private_namespace_libs/libnstest_dlopened.so").c_str(),
RTLD_NOW | RTLD_NOLOAD);
ASSERT_TRUE(handle == nullptr)
<< "Error: libnstest_dlopened.so is still accessible in default namespace";
// Now lets see if the soinfo area gets reused in the wrong way:
// load a library to default namespace.
- const std::string lib_public_path = lib_path + "/public_namespace_libs/" + g_public_lib;
+ const std::string lib_public_path = g_testlib_root + "/public_namespace_libs/" + g_public_lib;
void* handle_public = dlopen(lib_public_path.c_str(), RTLD_NOW);
ASSERT_TRUE(handle_public != nullptr) << dlerror();
@@ -1043,14 +1029,12 @@
ASSERT_TRUE(android_init_namespaces(path.c_str(), nullptr));
- const std::string lib_path = std::string(getenv("ANDROID_DATA")) + NATIVE_TESTS_PATH;
-
- const std::string lib_public_path = lib_path + "/public_namespace_libs";
+ const std::string lib_public_path = g_testlib_root + "/public_namespace_libs";
android_namespace_t* ns1 =
android_create_namespace("isolated1",
nullptr,
- (lib_path + "/private_namespace_libs").c_str(),
+ (g_testlib_root + "/private_namespace_libs").c_str(),
ANDROID_NAMESPACE_TYPE_ISOLATED,
lib_public_path.c_str(),
nullptr);
@@ -1059,7 +1043,7 @@
android_namespace_t* ns2 =
android_create_namespace("isolated2",
nullptr,
- (lib_path + "/private_namespace_libs").c_str(),
+ (g_testlib_root + "/private_namespace_libs").c_str(),
ANDROID_NAMESPACE_TYPE_ISOLATED,
lib_public_path.c_str(),
nullptr);
@@ -1078,7 +1062,7 @@
android_namespace_t* ns1_child =
android_create_namespace("isolated1_child",
nullptr,
- (lib_path + "/private_namespace_libs").c_str(),
+ (g_testlib_root + "/private_namespace_libs").c_str(),
ANDROID_NAMESPACE_TYPE_ISOLATED,
nullptr,
ns1);
@@ -1113,26 +1097,22 @@
static const char* root_lib = "libnstest_root.so";
std::string path = std::string("libc.so:libc++.so:libdl.so:libm.so:") + g_public_lib;
- std::string data_path;
- ASSERT_TRUE(get_realpath(std::string(getenv("ANDROID_DATA")), &data_path)) << strerror(errno);
- const std::string lib_path = data_path + NATIVE_TESTS_PATH;
-
- const std::string lib_public_path = lib_path + "/public_namespace_libs/" + g_public_lib;
+ const std::string lib_public_path = g_testlib_root + "/public_namespace_libs/" + g_public_lib;
void* handle_public = dlopen(lib_public_path.c_str(), RTLD_NOW);
ASSERT_TRUE(handle_public != nullptr) << dlerror();
- ASSERT_TRUE(android_init_namespaces(path.c_str(), (lib_path + "/private_namespace_libs").c_str()))
+ ASSERT_TRUE(android_init_namespaces(path.c_str(), (g_testlib_root + "/private_namespace_libs").c_str()))
<< dlerror();
android_namespace_t* ns = android_create_namespace(
"private", nullptr,
- (lib_path + "/private_namespace_libs").c_str(),
+ (g_testlib_root + "/private_namespace_libs").c_str(),
ANDROID_NAMESPACE_TYPE_REGULAR, nullptr, nullptr);
ASSERT_TRUE(ns != nullptr) << dlerror();
- std::string private_library_absolute_path = lib_path + "/private_namespace_libs/" + root_lib;
+ std::string private_library_absolute_path = g_testlib_root + "/private_namespace_libs/" + root_lib;
android_dlextinfo extinfo;
extinfo.flags = ANDROID_DLEXT_USE_NAMESPACE;
diff --git a/tests/dlfcn_symlink_support.cpp b/tests/dlfcn_symlink_support.cpp
new file mode 100644
index 0000000..be1839e
--- /dev/null
+++ b/tests/dlfcn_symlink_support.cpp
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+#include "dlfcn_symlink_support.h"
+
+#include <gtest/gtest.h>
+
+#include <dlfcn.h>
+#include <libgen.h>
+#include <link.h>
+#include <unistd.h>
+
+#include <android-base/strings.h>
+
+#include <algorithm>
+#include <string>
+#include <vector>
+
+static const constexpr char* source_file_name = "libdlext_test.so";
+static const constexpr char* symlink_name_prefix = "libdlext_test_";
+
+static int dl_callback(struct dl_phdr_info *info, size_t /* size */, void *data) {
+ // The case when path is not absolute and is equal to source_file_name
+ // is disregarded intentionally since in bionic dlpi_name should always
+ // be realpath to a shared object.
+ const std::string suffix = std::string("/") + source_file_name;
+
+ // TODO (dimitry): remove this check once fake libdl.so is gone
+ if (info->dlpi_name == nullptr) {
+ // This is linker imposing as libdl.so - skip it
+ return 0;
+ }
+
+ if (android::base::EndsWith(info->dlpi_name, suffix.c_str())) {
+ std::string* path = reinterpret_cast<std::string*>(data);
+ *path = info->dlpi_name;
+ return 1; // found
+ }
+
+ return 0;
+}
+
+void create_dlfcn_test_symlink(const char* suffix, std::string* result) {
+ void* handle = dlopen(source_file_name, RTLD_NOW);
+ std::string source_file_path;
+
+ ASSERT_TRUE(handle != nullptr) << dlerror();
+ ASSERT_TRUE(dl_iterate_phdr(dl_callback, &source_file_path) == 1)
+ << "dl_phdr_info for \"" << source_file_name << "\" was not found.";
+
+ dlclose(handle);
+ std::vector<char> buf;
+ std::copy(source_file_path.begin(), source_file_path.end(), std::back_inserter(buf));
+ buf.push_back('\0');
+
+ std::string path_dir = dirname(&buf[0]);
+ std::string link_path = path_dir + "/" + symlink_name_prefix + suffix + ".so";
+
+ ASSERT_TRUE(symlink(source_file_path.c_str(), link_path.c_str()) == 0) << strerror(errno);
+ *result = link_path;
+}
+
+void remove_dlfcn_test_symlink(const std::string& path) {
+ ASSERT_TRUE(unlink(path.c_str()) == 0) << strerror(errno);
+}
diff --git a/tests/dlfcn_symlink_support.h b/tests/dlfcn_symlink_support.h
new file mode 100644
index 0000000..8a8d3a2
--- /dev/null
+++ b/tests/dlfcn_symlink_support.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+#ifndef __DLFCN_SYMLINK_SUPPORT_H__
+#define __DLFCN_SYMLINK_SUPPORT_H__
+
+#include <string>
+
+void create_dlfcn_test_symlink(const char* suffix, std::string* result);
+void remove_dlfcn_test_symlink(const std::string& path);
+
+class DlfcnSymlink {
+ public:
+ explicit DlfcnSymlink(const char* test_name) {
+ create_dlfcn_test_symlink(test_name, &symlink_path_);
+ }
+
+ ~DlfcnSymlink() {
+ remove_dlfcn_test_symlink(symlink_path_);
+ }
+
+ const std::string& get_symlink_path() const {
+ return symlink_path_;
+ }
+
+ private:
+ std::string symlink_path_;
+};
+
+#endif /* __DLFCN_SYMLINK_SUPPORT_H__ */
diff --git a/tests/dlfcn_test.cpp b/tests/dlfcn_test.cpp
index 34c4108..dd9660b 100644
--- a/tests/dlfcn_test.cpp
+++ b/tests/dlfcn_test.cpp
@@ -17,15 +17,17 @@
#include <gtest/gtest.h>
#include <dlfcn.h>
-#include <libgen.h>
#include <limits.h>
#include <stdio.h>
#include <stdint.h>
+#include <string.h>
#include "private/ScopeGuard.h"
#include <string>
+#include "gtest_globals.h"
+#include "dlfcn_symlink_support.h"
#include "utils.h"
#define ASSERT_SUBSTR(needle, haystack) \
@@ -1012,8 +1014,10 @@
}
TEST(dlfcn, dlopen_symlink) {
+ DlfcnSymlink symlink("dlopen_symlink");
+ const std::string symlink_name = basename(symlink.get_symlink_path().c_str());
void* handle1 = dlopen("libdlext_test.so", RTLD_NOW);
- void* handle2 = dlopen("libdlext_test_v2.so", RTLD_NOW);
+ void* handle2 = dlopen(symlink_name.c_str(), RTLD_NOW);
ASSERT_TRUE(handle1 != nullptr);
ASSERT_TRUE(handle2 != nullptr);
ASSERT_EQ(handle1, handle2);
@@ -1132,16 +1136,8 @@
// Bionic specific tests
#if defined(__BIONIC__)
-#if defined(__LP64__)
-#define NATIVE_TESTS_PATH "/nativetest64/bionic-loader-test-libs"
-#else
-#define NATIVE_TESTS_PATH "/nativetest/bionic-loader-test-libs"
-#endif
-
-#define PREBUILT_ELF_PATH NATIVE_TESTS_PATH "/prebuilt-elf-files"
-
TEST(dlfcn, dt_runpath_absolute_path) {
- std::string libpath = std::string(getenv("ANDROID_DATA")) + NATIVE_TESTS_PATH + "/libtest_dt_runpath_d.so";
+ std::string libpath = g_testlib_root + "/libtest_dt_runpath_d.so";
void* handle = dlopen(libpath.c_str(), RTLD_NOW);
ASSERT_TRUE(handle != nullptr) << dlerror();
@@ -1156,9 +1152,9 @@
}
TEST(dlfcn, dlopen_invalid_rw_load_segment) {
- std::string data_path;
- ASSERT_TRUE(get_realpath(std::string(getenv("ANDROID_DATA")), &data_path)) << strerror(errno);
- const std::string libpath = data_path + PREBUILT_ELF_PATH + "/libtest_invalid-rw_load_segment.so";
+ const std::string libpath = g_testlib_root +
+ "/" + kPrebuiltElfDir +
+ "/libtest_invalid-rw_load_segment.so";
void* handle = dlopen(libpath.c_str(), RTLD_NOW);
ASSERT_TRUE(handle == nullptr);
std::string expected_dlerror = std::string("dlopen failed: \"") + libpath + "\": W + E load segments are not allowed";
@@ -1166,9 +1162,10 @@
}
TEST(dlfcn, dlopen_invalid_unaligned_shdr_offset) {
- std::string data_path;
- ASSERT_TRUE(get_realpath(std::string(getenv("ANDROID_DATA")), &data_path)) << strerror(errno);
- const std::string libpath = data_path + PREBUILT_ELF_PATH + "/libtest_invalid-unaligned_shdr_offset.so";
+ const std::string libpath = g_testlib_root +
+ "/" + kPrebuiltElfDir +
+ "/libtest_invalid-unaligned_shdr_offset.so";
+
void* handle = dlopen(libpath.c_str(), RTLD_NOW);
ASSERT_TRUE(handle == nullptr);
std::string expected_dlerror = std::string("dlopen failed: \"") + libpath + "\" has invalid shdr offset/size: ";
@@ -1176,9 +1173,10 @@
}
TEST(dlfcn, dlopen_invalid_zero_shentsize) {
- std::string data_path;
- ASSERT_TRUE(get_realpath(std::string(getenv("ANDROID_DATA")), &data_path)) << strerror(errno);
- const std::string libpath = data_path + PREBUILT_ELF_PATH + "/libtest_invalid-zero_shentsize.so";
+ const std::string libpath = g_testlib_root +
+ "/" + kPrebuiltElfDir +
+ "/libtest_invalid-zero_shentsize.so";
+
void* handle = dlopen(libpath.c_str(), RTLD_NOW);
ASSERT_TRUE(handle == nullptr);
std::string expected_dlerror = std::string("dlopen failed: \"") + libpath + "\" has unsupported e_shentsize: 0x0 (expected 0x";
@@ -1186,9 +1184,10 @@
}
TEST(dlfcn, dlopen_invalid_zero_shstrndx) {
- std::string data_path;
- ASSERT_TRUE(get_realpath(std::string(getenv("ANDROID_DATA")), &data_path)) << strerror(errno);
- const std::string libpath = data_path + PREBUILT_ELF_PATH + "/libtest_invalid-zero_shstrndx.so";
+ const std::string libpath = g_testlib_root +
+ "/" + kPrebuiltElfDir +
+ "/libtest_invalid-zero_shstrndx.so";
+
void* handle = dlopen(libpath.c_str(), RTLD_NOW);
ASSERT_TRUE(handle == nullptr);
std::string expected_dlerror = std::string("dlopen failed: \"") + libpath + "\" has invalid e_shstrndx";
@@ -1196,9 +1195,10 @@
}
TEST(dlfcn, dlopen_invalid_empty_shdr_table) {
- std::string data_path;
- ASSERT_TRUE(get_realpath(std::string(getenv("ANDROID_DATA")), &data_path)) << strerror(errno);
- std::string libpath = data_path + PREBUILT_ELF_PATH + "/libtest_invalid-empty_shdr_table.so";
+ const std::string libpath = g_testlib_root +
+ "/" + kPrebuiltElfDir +
+ "/libtest_invalid-empty_shdr_table.so";
+
void* handle = dlopen(libpath.c_str(), RTLD_NOW);
ASSERT_TRUE(handle == nullptr);
std::string expected_dlerror = std::string("dlopen failed: \"") + libpath + "\" has no section headers";
@@ -1206,9 +1206,10 @@
}
TEST(dlfcn, dlopen_invalid_zero_shdr_table_offset) {
- std::string data_path;
- ASSERT_TRUE(get_realpath(std::string(getenv("ANDROID_DATA")), &data_path)) << strerror(errno);
- const std::string libpath = data_path + PREBUILT_ELF_PATH + "/libtest_invalid-zero_shdr_table_offset.so";
+ const std::string libpath = g_testlib_root +
+ "/" + kPrebuiltElfDir +
+ "/libtest_invalid-zero_shdr_table_offset.so";
+
void* handle = dlopen(libpath.c_str(), RTLD_NOW);
ASSERT_TRUE(handle == nullptr);
std::string expected_dlerror = std::string("dlopen failed: \"") + libpath + "\" has invalid shdr offset/size: 0/";
@@ -1216,9 +1217,10 @@
}
TEST(dlfcn, dlopen_invalid_zero_shdr_table_content) {
- std::string data_path;
- ASSERT_TRUE(get_realpath(std::string(getenv("ANDROID_DATA")), &data_path)) << strerror(errno);
- const std::string libpath = data_path + PREBUILT_ELF_PATH + "/libtest_invalid-zero_shdr_table_content.so";
+ const std::string libpath = g_testlib_root +
+ "/" + kPrebuiltElfDir +
+ "/libtest_invalid-zero_shdr_table_content.so";
+
void* handle = dlopen(libpath.c_str(), RTLD_NOW);
ASSERT_TRUE(handle == nullptr);
std::string expected_dlerror = std::string("dlopen failed: \"") + libpath + "\" .dynamic section header was not found";
diff --git a/tests/gtest_globals.cpp b/tests/gtest_globals.cpp
new file mode 100644
index 0000000..4f2c82e
--- /dev/null
+++ b/tests/gtest_globals.cpp
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+#include "gtest_globals.h"
+
+#include <gtest/gtest.h>
+#include "utils.h"
+
+#include <string>
+
+static std::string get_testlib_root() {
+ std::string out_path;
+ const char* data_dir = getenv("ANDROID_DATA");
+ if (data_dir == nullptr) {
+ out_path = "/data";
+ } else {
+ out_path = data_dir;
+ }
+
+ out_path = out_path + "/nativetest";
+#if defined(__LP64__)
+ out_path += "64";
+#endif
+ out_path += "/bionic-loader-test-libs";
+ std::string real_path;
+ if (!get_realpath(out_path, &real_path)) {
+ abort();
+ }
+
+ return real_path;
+}
+
+const std::string g_testlib_root = get_testlib_root();
diff --git a/tests/gtest_globals.h b/tests/gtest_globals.h
new file mode 100644
index 0000000..fab2a39
--- /dev/null
+++ b/tests/gtest_globals.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+#ifndef _BIONIC_TESTS_GTEST_GLOBALS_H
+#define _BIONIC_TESTS_GTEST_GLOBALS_H
+
+#include <string>
+
+constexpr const char* kPrebuiltElfDir = "prebuilt-elf-files";
+
+extern const std::string g_testlib_root;
+
+#endif // _BIONIC_TESTS_GTEST_GLOBALS_H
diff --git a/tests/gtest_globals_cts.cpp b/tests/gtest_globals_cts.cpp
new file mode 100644
index 0000000..bf891a1
--- /dev/null
+++ b/tests/gtest_globals_cts.cpp
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+#include "gtest_globals.h"
+
+#include <string>
+
+const std::string g_testlib_root = "/data/local/tmp/lib/bionic-loader-test-libs";
diff --git a/tests/libs/Android.mk b/tests/libs/Android.mk
index 94cc516..a54318d 100644
--- a/tests/libs/Android.mk
+++ b/tests/libs/Android.mk
@@ -49,26 +49,6 @@
include $(LOCAL_PATH)/Android.build.testlib.mk
# -----------------------------------------------------------------------------
-# create symlink to libdlext_test.so for symlink test
-# -----------------------------------------------------------------------------
-# Use = instead of := to defer the evaluation of $@
-$(TARGET_OUT_DATA_NATIVE_TESTS)/bionic-loader-test-libs/libdlext_test.so: PRIVATE_POST_INSTALL_CMD = \
- $(hide) cd $(dir $@) && ln -sf $(notdir $@) libdlext_test_v2.so
-
-ifneq ($(TARGET_2ND_ARCH),)
-# link 64 bit .so
-$($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_DATA_NATIVE_TESTS)/bionic-loader-test-libs/libdlext_test.so: PRIVATE_POST_INSTALL_CMD = \
- $(hide) cd $(dir $@) && ln -sf $(notdir $@) libdlext_test_v2.so
-endif
-
-# host symlinks
-$(HOST_OUT)/lib64/libdlext_test.so: PRIVATE_POST_INSTALL_CMD = \
- $(hide) cd $(dir $@) && ln -sf $(notdir $@) libdlext_test_v2.so
-
-$(HOST_OUT)/lib/libdlext_test.so: PRIVATE_POST_INSTALL_CMD = \
- $(hide) cd $(dir $@) && ln -sf $(notdir $@) libdlext_test_v2.so
-
-# -----------------------------------------------------------------------------
# Library used by dlext tests - different name non-default location
# -----------------------------------------------------------------------------
module := libdlext_test_fd