• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright Antony Polukhin, 2016-2020.
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 "test_impl.hpp"
8 #include <boost/stacktrace/stacktrace_fwd.hpp>
9 
10 #include <sstream>
11 
12 #include <boost/stacktrace.hpp>
13 #include <boost/thread.hpp>
14 #include <boost/optional.hpp>
15 #include <boost/core/lightweight_test.hpp>
16 
17 #include <boost/timer/timer.hpp>
18 
19 using boost::stacktrace::stacktrace;
20 
21 
main_test_loop()22 void main_test_loop() {
23     std::size_t loops = 100;
24     int Depth = 25;
25 
26     boost::optional<std::pair<stacktrace, stacktrace> > ethalon;
27     std::stringstream ss_ethalon;
28 
29     while (--loops) {
30         std::pair<stacktrace, stacktrace> res = function_from_library(Depth, function_from_main_translation_unit);
31         if (ethalon) {
32             BOOST_TEST(res == *ethalon);
33 
34             std::stringstream ss;
35             ss << res.first;
36             BOOST_TEST(ss.str() == ss_ethalon.str());
37         } else {
38             ethalon = res;
39             ss_ethalon << ethalon->first;
40         }
41     }
42 }
43 
44 #if defined(BOOST_STACKTRACE_TEST_COM_PREINIT_MT) || defined(BOOST_STACKTRACE_TEST_COM_PREINIT_ST)
45 #   include <windows.h>
46 #   include "dbgeng.h"
47 #endif
48 
main()49 int main() {
50 #if defined(BOOST_STACKTRACE_TEST_COM_PREINIT_MT)
51     ::CoInitializeEx(0, COINIT_MULTITHREADED);
52 #elif defined(BOOST_STACKTRACE_TEST_COM_PREINIT_ST)
53     ::CoInitializeEx(0, COINIT_APARTMENTTHREADED);
54 #endif
55 
56     boost::timer::auto_cpu_timer t;
57 
58     boost::thread t1(main_test_loop);
59     boost::thread t2(main_test_loop);
60     boost::thread t3(main_test_loop);
61     main_test_loop();
62 
63     t1.join();
64     t2.join();
65     t3.join();
66 
67 #if defined(BOOST_STACKTRACE_TEST_COM_PREINIT_MT) || defined(BOOST_STACKTRACE_TEST_COM_PREINIT_ST)
68     ::CoUninitialize();
69 #endif
70 
71     return boost::report_errors();
72 }
73