Add test for libraries with textrels
Make sure android fails to load them.
Bug: http://b/30795430
Test: bionic-unit-tests --gtest_filter=dlfcn.dlopen_invalid*
Test: cts-tradefed run singleCommand cts --skip-preconditions -m CtsBionicTestCases
Change-Id: Id0ebdf336b2f297007479ceb1bbccf778a7ca3f2
diff --git a/tests/dlfcn_test.cpp b/tests/dlfcn_test.cpp
index dd9660b..5908fc3 100644
--- a/tests/dlfcn_test.cpp
+++ b/tests/dlfcn_test.cpp
@@ -1227,4 +1227,26 @@
ASSERT_SUBSTR(expected_dlerror.c_str(), dlerror());
}
+TEST(dlfcn, dlopen_invalid_textrels) {
+ const std::string libpath = g_testlib_root +
+ "/" + kPrebuiltElfDir +
+ "/libtest_invalid-textrels.so";
+
+ void* handle = dlopen(libpath.c_str(), RTLD_NOW);
+ ASSERT_TRUE(handle == nullptr);
+ std::string expected_dlerror = std::string("dlopen failed: \"") + libpath + "\" has text relocations";
+ ASSERT_SUBSTR(expected_dlerror.c_str(), dlerror());
+}
+
+TEST(dlfcn, dlopen_invalid_textrels2) {
+ const std::string libpath = g_testlib_root +
+ "/" + kPrebuiltElfDir +
+ "/libtest_invalid-textrels2.so";
+
+ void* handle = dlopen(libpath.c_str(), RTLD_NOW);
+ ASSERT_TRUE(handle == nullptr);
+ std::string expected_dlerror = std::string("dlopen failed: \"") + libpath + "\" has text relocations";
+ ASSERT_SUBSTR(expected_dlerror.c_str(), dlerror());
+}
+
#endif