]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/stacktrace/test/thread_safety_checking.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / stacktrace / test / thread_safety_checking.cpp
1 // Copyright Antony Polukhin, 2016-2017.
2 //
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)
6
7 #include <boost/stacktrace/stacktrace_fwd.hpp>
8
9 #include <sstream>
10
11 #include <boost/stacktrace.hpp>
12 #include <boost/thread.hpp>
13 #include <boost/optional.hpp>
14 #include <boost/core/lightweight_test.hpp>
15
16 #include <boost/timer/timer.hpp>
17
18 #ifdef BOOST_STACKTRACE_DYN_LINK
19 # define BOOST_ST_API BOOST_SYMBOL_IMPORT
20 #else
21 # define BOOST_ST_API
22 #endif
23
24 using boost::stacktrace::stacktrace;
25
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();
29
30 BOOST_NOINLINE std::pair<stacktrace, stacktrace> foo1(int i) {
31 if (i) {
32 return foo2(i - 1, foo1);
33 }
34
35 std::pair<stacktrace, stacktrace> ret;
36 try {
37 throw std::logic_error("test");
38 } catch (const std::logic_error& /*e*/) {
39 ret.second = stacktrace();
40 return ret;
41 }
42 }
43
44 void main_test_loop() {
45 std::size_t loops = 100;
46 int Depth = 25;
47
48 boost::optional<std::pair<stacktrace, stacktrace> > ethalon;
49 std::stringstream ss_ethalon;
50
51 while (--loops) {
52 std::pair<stacktrace, stacktrace> res = foo2(Depth, foo1);
53 if (ethalon) {
54 BOOST_TEST(res == *ethalon);
55
56 std::stringstream ss;
57 ss << res.first;
58 BOOST_TEST(ss.str() == ss_ethalon.str());
59 } else {
60 ethalon = res;
61 ss_ethalon << ethalon->first;
62 }
63 }
64 }
65
66 #if defined(BOOST_STACKTRACE_TEST_COM_PREINIT_MT) || defined(BOOST_STACKTRACE_TEST_COM_PREINIT_ST)
67 # include <windows.h>
68 # include "dbgeng.h"
69 #endif
70
71 int main() {
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);
76 #endif
77
78 boost::timer::auto_cpu_timer t;
79
80 boost::thread t1(main_test_loop);
81 boost::thread t2(main_test_loop);
82 boost::thread t3(main_test_loop);
83 main_test_loop();
84
85 t1.join();
86 t2.join();
87 t3.join();
88
89 #if defined(BOOST_STACKTRACE_TEST_COM_PREINIT_MT) || defined(BOOST_STACKTRACE_TEST_COM_PREINIT_ST)
90 ::CoUninitialize();
91 #endif
92
93 return boost::report_errors();
94 }