Skip to content
Snippets Groups Projects
Commit dba67315 authored by Takuya ASADA's avatar Takuya ASADA Committed by Pekka Enberg
Browse files

test case for dladdr()


Test case for dladdr(), to make sure it returns correct symbol in these cases:
 - addr is less than 'vfprintf'. Should returns another symbol.
 - addr is equals to 'vfprintf'. Should returns 'vfprintf' as the result.
 - addr is bigger than 'vfprintf', and also inside of it. Should returns 'vfprintf' as the result.

Reviewed-by: default avatarNadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: default avatarTakuya ASADA <syuu@cloudius-systems.com>
Signed-off-by: default avatarPekka Enberg <penberg@cloudius-systems.com>
parent 1283d800
No related branches found
No related tags found
No related merge requests found
......@@ -26,3 +26,30 @@ BOOST_AUTO_TEST_CASE(test_dlopen_with_empty_file_name)
BOOST_REQUIRE(dlsym(ref, "open") != NULL);
BOOST_REQUIRE(dlclose(ref) == 0);
}
template<typename T>
static void *adj_addr(T addr, int adj)
{
return reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(addr) + adj);
}
BOOST_AUTO_TEST_CASE(test_dladdr)
{
Dl_info info;
BOOST_REQUIRE(dladdr(adj_addr(vfprintf, -2), &info) != 0);
BOOST_REQUIRE(std::string("vfprintf") != std::string(info.dli_sname));
BOOST_REQUIRE(vfprintf != info.dli_saddr);
BOOST_REQUIRE(dladdr(adj_addr(vfprintf, 0), &info) != 0);
BOOST_CHECK_EQUAL("vfprintf", info.dli_sname);
BOOST_CHECK_EQUAL(vfprintf, info.dli_saddr);
BOOST_REQUIRE(dladdr(adj_addr(vfprintf, 2), &info) != 0);
BOOST_CHECK_EQUAL("vfprintf", info.dli_sname);
BOOST_CHECK_EQUAL(vfprintf, info.dli_saddr);
BOOST_REQUIRE(dladdr(adj_addr(vfprintf, 4), &info) != 0);
BOOST_CHECK_EQUAL("vfprintf", info.dli_sname);
BOOST_CHECK_EQUAL(vfprintf, info.dli_saddr);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment