From 12e07fcca19f956ead15dcd14f62dff07c607e20 Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Thu, 22 Feb 2024 09:12:00 +0300 Subject: [PATCH] CI fixes (#153) * Update thread_safety_checking.cpp to use Standard Library types * Remove MinGW runs due to https://github.com/boostorg/system/issues/116 * Delete the shared memory example sources --- .github/workflows/ci.yml | 3 +- doc/stacktrace.qbk | 37 ------------- example/terminate_handler.cpp | 92 +-------------------------------- test/Jamfile.v2 | 18 ++----- test/appveyor.yml | 16 +++--- test/thread_safety_checking.cpp | 17 +++--- 6 files changed, 28 insertions(+), 155 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7ca7dca..a600a06 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,8 +27,7 @@ jobs: - toolset: gcc-9 cxxstd: "03,11,14,17,2a" os: ubuntu-22.04 - - toolset: clang - compiler: clang++-14 + - toolset: clang-15 cxxstd: "03,11,14,17,2a" os: ubuntu-22.04 # TODO: fix and uncomment diff --git a/doc/stacktrace.qbk b/doc/stacktrace.qbk index 30d43cf..9fa601c 100644 --- a/doc/stacktrace.qbk +++ b/doc/stacktrace.qbk @@ -295,43 +295,6 @@ Terminate called: [endsect] -[/ -[section Store stacktraces into shared memory] - -There's a way to serialize stacktrace in async safe manner and share that serialized representation with another process. Here's another example with signal handlers. - -This example is very close to the [link stacktrace.getting_started.handle_terminates_aborts_and_seg "Handle terminates, aborts and Segmentation Faults"], but this time we are dumping stacktrace into shared memory: - -[getting_started_terminate_handlers_shmem] - -After registering signal handlers and catching a signal, we may print stacktrace dumps on program restart: - -[getting_started_on_program_restart_shmem] - -The program output will be the following: - -``` -Previous run crashed and left trace in shared memory: - 0# 0x00007FD51C7218EF - 1# my_signal_handler2(int) at ../example/terminate_handler.cpp:68 - 2# 0x00007FD51B833CB0 - 3# 0x00007FD51B833C37 - 4# 0x00007FD51B837028 - 5# 0x00007FD51BE44BBD - 6# 0x00007FD51BE42B96 - 7# 0x00007FD51BE42BE1 - 8# bar(int) at ../example/terminate_handler.cpp:18 - 9# foo(int) at ../example/terminate_handler.cpp:22 -10# bar(int) at ../example/terminate_handler.cpp:14 -11# foo(int) at ../example/terminate_handler.cpp:22 -12# run_3(char const**) at ../example/terminate_handler.cpp:152 -13# main at ../example/terminate_handler.cpp:207 -14# 0x00007FD51B81EF45 -15# 0x0000000000402999 -``` - -[endsect] -] [endsect] diff --git a/example/terminate_handler.cpp b/example/terminate_handler.cpp index c9336a5..8b69e9b 100644 --- a/example/terminate_handler.cpp +++ b/example/terminate_handler.cpp @@ -63,33 +63,12 @@ void my_terminate_handler() { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -BOOST_CONSTEXPR_OR_CONST std::size_t shared_memory_size = 4096 * 8; - -//[getting_started_terminate_handlers_shmem -#include -#include -#include - -boost::interprocess::shared_memory_object g_shm; // inited at program start -boost::interprocess::mapped_region g_region; // inited at program start - - -void my_signal_handler2(int signum) { - ::signal(signum, SIG_DFL); - void** f = static_cast(g_region.get_address()); - *f = reinterpret_cast(1); // Setting flag that shared memory now contains stacktrace. - boost::stacktrace::safe_dump_to(f + 1, g_region.get_size() - sizeof(void*)); - - ::raise(SIGABRT); -} -//] - #include // std::cerr #include // std::ifstream #include #include - +#ifndef BOOST_WINDOWS inline void copy_and_run(const char* exec_name, char param, bool not_null) { std::cout << "Running with param " << param << std::endl; boost::filesystem::path command = exec_name; @@ -110,6 +89,7 @@ inline void copy_and_run(const char* exec_name, char param, bool not_null) { std::exit(ret); } } +#endif int run_0(const char* /*argv*/[]) { //[getting_started_setup_terminate_handlers @@ -160,67 +140,6 @@ int run_2(const char* argv[]) { return 0; } - -int run_3(const char* /*argv*/[]) { - using namespace boost::interprocess; - { - shared_memory_object shm_obj(open_or_create, "shared_memory", read_write); - shm_obj.swap(g_shm); - } - g_shm.truncate(shared_memory_size); - - { - mapped_region m(g_shm, read_write, 0, shared_memory_size); - m.swap(g_region); - } - void** f = static_cast(g_region.get_address()); - *f = 0; - - ::signal(SIGSEGV, &my_signal_handler2); - ::signal(SIGABRT, &my_signal_handler2); - foo(5); - return 31; -} - -int run_4(const char* argv[]) { - using namespace boost::interprocess; - { - shared_memory_object shm_obj(open_only, "shared_memory", read_write); - shm_obj.swap(g_shm); - } - - { - mapped_region m(g_shm, read_write, 0, shared_memory_size); - m.swap(g_region); - } - -//[getting_started_on_program_restart_shmem - void** f = static_cast(g_region.get_address()); - if (*f) { // Checking if memory contains stacktrace. - boost::stacktrace::stacktrace st - = boost::stacktrace::stacktrace::from_dump(f + 1, g_region.get_size() - sizeof(bool)); - - std::cout << "Previous run crashed and left trace in shared memory:\n" << st << std::endl; - *f = 0; /*<-*/ - shared_memory_object::remove("shared_memory"); - if (std::string(argv[0]).find("noop") == std::string::npos) { - if (!st) { - return 43; - } - } else { - if (st) { - return 44; - } - } - } else { - return 42; /*->*/ - } -//] - - - return 0; -} - #include int test_inplace() { @@ -335,10 +254,6 @@ int main(int argc, const char* argv[]) { // We are copying files to make sure that stacktrace printing works independently from executable name copy_and_run(argv[0], '1', true); copy_and_run(argv[0], '2', false); - - // There are some issues with async-safety of shared memory writes on Windows. - copy_and_run(argv[0], '3', true); - copy_and_run(argv[0], '4', false); #endif return test_inplace(); @@ -347,9 +262,6 @@ int main(int argc, const char* argv[]) { switch (argv[1][0]) { case '0': return run_0(argv); case '1': return run_1(argv); - case '2': return run_2(argv); - case '3': return run_3(argv); - case '4': return run_4(argv); } return 404; diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index bc97545..901d450 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -117,20 +117,20 @@ test-suite stacktrace_tests # Thread safety with debug symbols [ run thread_safety_checking.cpp - : : : on /boost/thread//boost_thread /boost/timer//boost_timer .//test_impl_lib_backtrace $(LINKSHARED_BT) + : : : on .//test_impl_lib_backtrace $(LINKSHARED_BT) : backtrace_lib_threaded ] [ run thread_safety_checking.cpp - : : : on /boost/thread//boost_thread /boost/timer//boost_timer .//test_impl_lib_backtrace $(LINKSHARED_BT) + : : : on .//test_impl_lib_backtrace $(LINKSHARED_BT) BOOST_STACKTRACE_BACKTRACE_FORCE_STATIC : backtrace_lib_threaded_static ] [ run thread_safety_checking.cpp - : : : on /boost/thread//boost_thread /boost/timer//boost_timer .//test_impl_lib_windbg $(LINKSHARED_WIND) + : : : on .//test_impl_lib_windbg $(LINKSHARED_WIND) : windbg_lib_threaded ] [ run thread_safety_checking.cpp - : : : on /boost/thread//boost_thread /boost/timer//boost_timer .//test_impl_lib_windbg_cached $(LINKSHARED_WIND_CACHED) + : : : on .//test_impl_lib_windbg_cached $(LINKSHARED_WIND_CACHED) : windbg_cached_lib_threaded ] [ run thread_safety_checking.cpp - : : : on /boost/thread//boost_thread /boost/timer//boost_timer .//test_impl_lib_basic $(LINKSHARED_BASIC) + : : : on .//test_impl_lib_basic $(LINKSHARED_BASIC) : basic_lib_threaded ] ##### Tests with disabled debug symbols ##### @@ -157,29 +157,21 @@ test-suite stacktrace_tests # Thread safety without debug symbols [ run thread_safety_checking.cpp : : : off - /boost/thread//boost_thread - /boost/timer//boost_timer .//test_impl_lib_backtrace_no_dbg $(LINKSHARED_BT) : backtrace_lib_no_dbg_threaded ] [ run thread_safety_checking.cpp : : : off - /boost/thread//boost_thread - /boost/timer//boost_timer .//test_impl_lib_windbg_no_dbg $(LINKSHARED_WIND) : windbg_lib_no_dbg_threaded ] [ run thread_safety_checking.cpp : : : off - /boost/thread//boost_thread - /boost/timer//boost_timer .//test_impl_lib_windbg_cached_no_dbg $(LINKSHARED_WIND_CACHED) : windbg_cached_lib_no_dbg_threaded ] [ run thread_safety_checking.cpp : : : off - /boost/thread//boost_thread - /boost/timer//boost_timer .//test_impl_lib_basic_no_dbg $(LINKSHARED_BASIC) : basic_lib_no_dbg_threaded ] diff --git a/test/appveyor.yml b/test/appveyor.yml index 3149c1f..0ec6702 100644 --- a/test/appveyor.yml +++ b/test/appveyor.yml @@ -33,7 +33,7 @@ skip_tags: true environment: matrix: - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 - TOOLSET: msvc-14.1 # ,clang-win + TOOLSET: msvc-14.1 #,clang-win CXXSTD: 14,17 ADDRMD: 64 #- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 @@ -44,10 +44,11 @@ environment: # ADDPATH: C:\cygwin64\bin; # TOOLSET: gcc # CXXSTD: 03,11,14,1z - - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 - ADDPATH: C:\mingw\bin; - TOOLSET: gcc - CXXSTD: 03,11,14,1z + # Waiting for https://github.com/boostorg/system/issues/116 + #- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 + # ADDPATH: C:\mingw\bin; + # TOOLSET: gcc + # CXXSTD: 03,11,14,1z #- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 # ADDPATH: C:\mingw-w64\x86_64-7.2.0-posix-seh-rt_v5-rev1\mingw64\bin; # TOOLSET: gcc @@ -61,7 +62,10 @@ before_build: - set BOOST=C:/boost-local - git clone -b %BOOST_BRANCH% --depth 10 https://github.com/boostorg/boost.git %BOOST% - cd %BOOST% - - git submodule update --init --depth 10 tools/build tools/boostdep libs/filesystem libs/interprocess + - git submodule update --init --depth 10 tools/build tools/boostdep + libs/filesystem libs/atomic libs/system libs/interprocess libs/array + libs/iterator libs/detail libs/exception libs/smart_ptr libs/mpl + libs/align libs/container libs/tuple libs/intrusive libs/scope - rm -rf %BOOST%/libs/%BOOST_LIBS_FOLDER% - mv -f %APPVEYOR_BUILD_FOLDER% %BOOST%/libs/%BOOST_LIBS_FOLDER% diff --git a/test/thread_safety_checking.cpp b/test/thread_safety_checking.cpp index dfb18e2..0fe85ff 100644 --- a/test/thread_safety_checking.cpp +++ b/test/thread_safety_checking.cpp @@ -7,15 +7,14 @@ #include "test_impl.hpp" #include +#include #include +#include #include -#include #include #include -#include - using boost::stacktrace::stacktrace; @@ -42,16 +41,20 @@ void main_test_loop() { } int main() { - boost::timer::auto_cpu_timer t; + const auto t = std::chrono::steady_clock::now(); - boost::thread t1(main_test_loop); - boost::thread t2(main_test_loop); - boost::thread t3(main_test_loop); + std::thread t1(main_test_loop); + std::thread t2(main_test_loop); + std::thread t3(main_test_loop); main_test_loop(); t1.join(); t2.join(); t3.join(); + const auto elapsed = t - std::chrono::steady_clock::now(); + std::cout << "Elapsed: " << std::chrono::duration_cast( + elapsed + ). count() << "ms"; return boost::report_errors(); }