| 1 | // Copyright Antony Polukhin, 2016-2024. |
|---|---|
| 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 <chrono> |
| 11 | #include <sstream> |
| 12 | #include <thread> |
| 13 | |
| 14 | #include <boost/stacktrace.hpp> |
| 15 | #include <boost/optional.hpp> |
| 16 | #include <boost/core/lightweight_test.hpp> |
| 17 | |
| 18 | using boost::stacktrace::stacktrace; |
| 19 | |
| 20 | |
| 21 | void main_test_loop() { |
| 22 | std::size_t loops = 100; |
| 23 | int Depth = 25; |
| 24 | |
| 25 | boost::optional<std::pair<stacktrace, stacktrace> > ethalon; |
| 26 | std::stringstream ss_ethalon; |
| 27 | |
| 28 | while (--loops) { |
| 29 | std::pair<stacktrace, stacktrace> res = function_from_library(i: Depth, foo1: function_from_main_translation_unit); |
| 30 | if (ethalon) { |
| 31 | BOOST_TEST(res == *ethalon); |
| 32 | |
| 33 | std::stringstream ss; |
| 34 | ss << res.first; |
| 35 | BOOST_TEST(ss.str() == ss_ethalon.str()); |
| 36 | } else { |
| 37 | ethalon = res; |
| 38 | ss_ethalon << ethalon->first; |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | int main() { |
| 44 | const auto t = std::chrono::steady_clock::now(); |
| 45 | |
| 46 | std::thread t1(main_test_loop); |
| 47 | std::thread t2(main_test_loop); |
| 48 | std::thread t3(main_test_loop); |
| 49 | main_test_loop(); |
| 50 | |
| 51 | t1.join(); |
| 52 | t2.join(); |
| 53 | t3.join(); |
| 54 | |
| 55 | const auto elapsed = t - std::chrono::steady_clock::now(); |
| 56 | std::cout << "Elapsed: "<< std::chrono::duration_cast<std::chrono::milliseconds>( |
| 57 | d: elapsed |
| 58 | ). count() << "ms"; |
| 59 | return boost::report_errors(); |
| 60 | } |
| 61 |
