aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitriy Ivanov2014-12-16 16:01:47 -0600
committerGerrit Code Review2014-12-16 16:01:47 -0600
commit92b9cb2c899c386954b8f9ad8111aa6c8c63e306 (patch)
tree3c08c95348bb00f0b16777de76104085e719fe6d
parent3a50b65fd152b4a50dc15ec33f19080e8724b02c (diff)
parentbfa88bca5ca387d6b3560074050856527cfc7514 (diff)
downloadplatform-bionic-92b9cb2c899c386954b8f9ad8111aa6c8c63e306.tar.gz
platform-bionic-92b9cb2c899c386954b8f9ad8111aa6c8c63e306.tar.xz
platform-bionic-92b9cb2c899c386954b8f9ad8111aa6c8c63e306.zip
Merge "Add another test for weak-reference"
-rw-r--r--tests/dlfcn_test.cpp14
-rw-r--r--tests/libs/Android.mk9
-rw-r--r--tests/libs/dlopen_weak_undefined.cpp25
3 files changed, 47 insertions, 1 deletions
diff --git a/tests/dlfcn_test.cpp b/tests/dlfcn_test.cpp
index c988d29d..6fdfdc75 100644
--- a/tests/dlfcn_test.cpp
+++ b/tests/dlfcn_test.cpp
@@ -819,7 +819,7 @@ TEST(dlfcn, rtld_next_known_symbol) {
819 819
820TEST(dlfcn, dlsym_weak_func) { 820TEST(dlfcn, dlsym_weak_func) {
821 dlerror(); 821 dlerror();
822 void* handle = dlopen("libtest_dlsym_weak_func.so",RTLD_NOW); 822 void* handle = dlopen("libtest_dlsym_weak_func.so", RTLD_NOW);
823 ASSERT_TRUE(handle != NULL); 823 ASSERT_TRUE(handle != NULL);
824 824
825 int (*weak_func)(); 825 int (*weak_func)();
@@ -829,6 +829,18 @@ TEST(dlfcn, dlsym_weak_func) {
829 dlclose(handle); 829 dlclose(handle);
830} 830}
831 831
832TEST(dlfcn, dlopen_undefined_weak_func) {
833 test_isolated([] {
834 void* handle = dlopen("libtest_dlopen_weak_undefined_func.so", RTLD_NOW);
835 ASSERT_TRUE(handle != nullptr) << dlerror();
836 int (*weak_func)();
837 weak_func = reinterpret_cast<int (*)()>(dlsym(handle, "use_weak_undefined_func"));
838 ASSERT_TRUE(weak_func != nullptr) << dlerror();
839 EXPECT_EQ(6551, weak_func());
840 dlclose(handle);
841 });
842}
843
832TEST(dlfcn, dlopen_symlink) { 844TEST(dlfcn, dlopen_symlink) {
833 void* handle1 = dlopen("libdlext_test.so", RTLD_NOW); 845 void* handle1 = dlopen("libdlext_test.so", RTLD_NOW);
834 void* handle2 = dlopen("libdlext_test_v2.so", RTLD_NOW); 846 void* handle2 = dlopen("libdlext_test_v2.so", RTLD_NOW);
diff --git a/tests/libs/Android.mk b/tests/libs/Android.mk
index e4620f57..50d96b2b 100644
--- a/tests/libs/Android.mk
+++ b/tests/libs/Android.mk
@@ -358,3 +358,12 @@ libtest_dlsym_weak_func_src_files := \
358 358
359module := libtest_dlsym_weak_func 359module := libtest_dlsym_weak_func
360include $(LOCAL_PATH)/Android.build.testlib.mk 360include $(LOCAL_PATH)/Android.build.testlib.mk
361
362# -----------------------------------------------------------------------------
363# Library with weak undefined function
364# -----------------------------------------------------------------------------
365libtest_dlopen_weak_undefined_func_src_files := \
366 dlopen_weak_undefined.cpp
367
368module := libtest_dlopen_weak_undefined_func
369include $(LOCAL_PATH)/Android.build.testlib.mk
diff --git a/tests/libs/dlopen_weak_undefined.cpp b/tests/libs/dlopen_weak_undefined.cpp
new file mode 100644
index 00000000..599a52e6
--- /dev/null
+++ b/tests/libs/dlopen_weak_undefined.cpp
@@ -0,0 +1,25 @@
1/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17extern "C" int __attribute__((weak)) weak_undefined_func();
18
19extern "C" int use_weak_undefined_func() {
20 if (weak_undefined_func) {
21 return weak_undefined_func();
22 } else {
23 return 6551;
24 }
25}