bionic-unit-tests: remove dependency on ANDROID_DATA
Replace references to ANDROID_DATA enviroment variable with references
to g_testlib_root.
Bug: http://b/22182538
Test: build and run bionic-unit-tests --gtest_filter=dl*:Dl*
Test: make cts && cts-tradefed run singleCommand cts --skip-preconditions -m CtsBionicTestCases
Change-Id: I5667e991551cec55b9b664f2f0063039671ff34b
diff --git a/tests/dlfcn_test.cpp b/tests/dlfcn_test.cpp
index 23b133b..dd9660b 100644
--- a/tests/dlfcn_test.cpp
+++ b/tests/dlfcn_test.cpp
@@ -26,6 +26,7 @@
#include <string>
+#include "gtest_globals.h"
#include "dlfcn_symlink_support.h"
#include "utils.h"
@@ -1135,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();
@@ -1159,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";
@@ -1169,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: ";
@@ -1179,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";
@@ -1189,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";
@@ -1199,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";
@@ -1209,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/";
@@ -1219,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";