1 #include <android/api-level.h> 2 #include <dlfcn.h> 3 4 #include <minitest/minitest.h> 5 6 #if __ANDROID_API__ >= 8 7 Dl_info info; 8 extern "C" int my_dladdr(const void* addr, Dl_info *info); 9 #else 10 void *info; 11 extern "C" int my_dladdr(const void* addr, void **info); 12 #endif 13 14 TEST(libdl, my_dladdr) { 15 void *h, *libdl = dlopen("libc.so", RTLD_NOW); 16 EXPECT_NE(0, libdl); 17 h = dlsym(libdl, "printf"); 18 EXPECT_NE(0, h); 19 int r = my_dladdr((char*)h+1, &info); 20 #if __ANDROID_API__ >= 8 21 EXPECT_NE(0, r); 22 EXPECT_EQ(h, info.dli_saddr); 23 EXPECT_EQ(0, strcmp("libc.so", info.dli_fname)); 24 #else 25 EXPECT_EQ(0, r); 26 #endif 27 } 28