]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/stacktrace/test/thread_safety_checking.cpp
1 // Copyright Antony Polukhin, 2016-2017.
3 // Distributed under the Boost Software License, Version 1.0. (See
4 // accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
7 #include <boost/stacktrace/stacktrace_fwd.hpp>
11 #include <boost/stacktrace.hpp>
12 #include <boost/thread.hpp>
13 #include <boost/optional.hpp>
14 #include <boost/core/lightweight_test.hpp>
16 #include <boost/timer/timer.hpp>
18 #ifdef BOOST_STACKTRACE_DYN_LINK
19 # define BOOST_ST_API BOOST_SYMBOL_IMPORT
24 using boost::stacktrace::stacktrace
;
26 typedef std::pair
<stacktrace
, stacktrace
> (*foo1_t
)(int i
);
27 BOOST_ST_API
std::pair
<stacktrace
, stacktrace
> foo2(int i
, foo1_t foo1
);
28 BOOST_ST_API stacktrace
return_from_nested_namespaces();
30 BOOST_NOINLINE
std::pair
<stacktrace
, stacktrace
> foo1(int i
) {
32 return foo2(i
- 1, foo1
);
35 std::pair
<stacktrace
, stacktrace
> ret
;
37 throw std::logic_error("test");
38 } catch (const std::logic_error
& /*e*/) {
39 ret
.second
= stacktrace();
44 void main_test_loop() {
45 std::size_t loops
= 100;
48 boost::optional
<std::pair
<stacktrace
, stacktrace
> > ethalon
;
49 std::stringstream ss_ethalon
;
52 std::pair
<stacktrace
, stacktrace
> res
= foo2(Depth
, foo1
);
54 BOOST_TEST(res
== *ethalon
);
58 BOOST_TEST(ss
.str() == ss_ethalon
.str());
61 ss_ethalon
<< ethalon
->first
;
66 #if defined(BOOST_STACKTRACE_TEST_COM_PREINIT_MT) || defined(BOOST_STACKTRACE_TEST_COM_PREINIT_ST)
72 #if defined(BOOST_STACKTRACE_TEST_COM_PREINIT_MT)
73 ::CoInitializeEx(0, COINIT_MULTITHREADED
);
74 #elif defined(BOOST_STACKTRACE_TEST_COM_PREINIT_ST)
75 ::CoInitializeEx(0, COINIT_APARTMENTTHREADED
);
78 boost::timer::auto_cpu_timer t
;
80 boost::thread
t1(main_test_loop
);
81 boost::thread
t2(main_test_loop
);
82 boost::thread
t3(main_test_loop
);
89 #if defined(BOOST_STACKTRACE_TEST_COM_PREINIT_MT) || defined(BOOST_STACKTRACE_TEST_COM_PREINIT_ST)
93 return boost::report_errors();