]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/dll/test/symbol_runtime_info_test.cpp
1 // Copyright 2014 Renato Tegon Forti, Antony Polukhin.
2 // Copyright 2015-2017 Antony Polukhin.
4 // Distributed under the Boost Software License, Version 1.0.
5 // (See accompanying file LICENSE_1_0.txt
6 // or copy at http://www.boost.org/LICENSE_1_0.txt)
8 // For more information, see http://www.boost.org
10 #include "../example/b2_workarounds.hpp"
11 #include <boost/dll.hpp>
12 #include <boost/dll/runtime_symbol_info.hpp>
13 #include <boost/filesystem/operations.hpp>
15 #include <boost/core/lightweight_test.hpp>
17 #include <exception> // std::set_terminate
18 #include <signal.h> // ::signal
22 typedef float (lib_version_func
)();
23 typedef void (say_hello_func
) ();
24 typedef int (increment
) (int);
27 extern "C" int BOOST_SYMBOL_EXPORT
exef() {
32 extern "C" void BOOST_SYMBOL_EXPORT
my_terminate_handler() {
36 extern "C" void BOOST_SYMBOL_EXPORT
my_signal_handler(int) {
40 void internal_function() {}
41 int internal_variable
= 1;
44 int main(int argc
, char* argv
[]) {
45 using namespace boost::dll
;
47 boost::filesystem::path shared_library_path
= b2_workarounds::first_lib_from_argv(argc
, argv
);
48 BOOST_TEST(shared_library_path
.string().find("test_library") != std::string::npos
);
50 shared_library
lib(shared_library_path
);
52 std::cout
<< std::endl
;
53 std::cout
<< "shared_library: " << shared_library_path
<< std::endl
;
54 std::cout
<< "symbol_location: " << symbol_location(lib
.get
<int>("integer_g")) << std::endl
;
55 std::cout
<< "lib.location(): " << lib
.location() << std::endl
;
57 symbol_location(lib
.get
<int>("integer_g")) == lib
.location()
61 symbol_location(lib
.get
<say_hello_func
>("say_hello")) == lib
.location()
65 symbol_location(lib
.get
<lib_version_func
>("lib_version")) == lib
.location()
69 symbol_location(lib
.get
<const int>("const_integer_g")) == lib
.location()
72 // Checking that symbols are still available, after another load+unload of the library
73 { shared_library
sl2(shared_library_path
); }
76 symbol_location(lib
.get
<int>("integer_g")) == lib
.location()
81 symbol_location(lib
.get
<std::size_t(*)(const std::vector
<int>&)>("foo_bar")) == lib
.location()
84 symbol_location(lib
.get_alias
<std::size_t(const std::vector
<int>&)>("foo_bar")) == lib
.location()
89 symbol_location(lib
.get
<std::size_t*>("foo_variable")) == lib
.location()
92 symbol_location(lib
.get_alias
<std::size_t>("foo_variable")) == lib
.location()
96 shared_library
sl(program_location());
98 (boost::filesystem::equivalent(symbol_location(sl
.get
<int(void)>("exef")), argv
[0]))
102 { // self with error_code
103 boost::system::error_code ec
;
104 shared_library
sl(program_location(ec
));
108 (boost::filesystem::equivalent(symbol_location(sl
.get
<int(void)>("exef"), ec
), argv
[0]))
112 symbol_location(&sl
.get
<int(void)>("exef"), ec
);
116 std::cout
<< "\ninternal_function: " << symbol_location(internal_function
);
117 std::cout
<< "\nargv[0] : " << boost::filesystem::absolute(argv
[0]);
119 (boost::filesystem::equivalent(symbol_location(internal_function
), argv
[0]))
123 (boost::filesystem::equivalent(symbol_location(internal_variable
), argv
[0]))
128 (boost::filesystem::equivalent(this_line_location(), argv
[0]))
131 { // this_line_location with error_code
132 boost::system::error_code ec
;
134 (boost::filesystem::equivalent(this_line_location(ec
), argv
[0]))
140 lib
.get_alias
<boost::filesystem::path()>("module_location_from_itself")() == lib
.location()
143 // Checking docs content
144 std::cout
<< "\nsymbol_location(std::cerr); // " << symbol_location(std::cerr
);
145 std::cout
<< "\nsymbol_location(std::puts); // " << symbol_location(std::puts
);
147 std::set_terminate(&my_terminate_handler
);
148 BOOST_TEST((boost::filesystem::equivalent(
149 symbol_location_ptr(std::set_terminate(0)),
154 boost::system::error_code ec
;
155 boost::filesystem::path p
= symbol_location_ptr(std::set_terminate(0), ec
);
156 BOOST_TEST(ec
|| !p
.empty());
160 boost::system::error_code ec
;
161 symbol_location(std::set_terminate(0), ec
),
166 std::set_terminate(&my_terminate_handler
);
167 boost::system::error_code ec
;
168 symbol_location(std::set_terminate(0), ec
),
173 boost::system::error_code ec
;
174 ::signal(SIGSEGV
, &my_signal_handler
);
175 boost::filesystem::path p
= symbol_location_ptr(::signal(SIGSEGV
, SIG_DFL
), ec
);
176 BOOST_TEST((boost::filesystem::equivalent(
183 ::signal(SIGSEGV
, &my_signal_handler
);
184 boost::system::error_code ec
;
185 symbol_location(::signal(SIGSEGV
, SIG_DFL
), ec
);
190 return boost::report_errors();