From 488e6a5fd33aa6da3c5e944b50fa6393d6570954 Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Mon, 28 Aug 2023 13:06:05 +1200 Subject: [PATCH] CI: enable backtrace using cpptrace Trying to get a backtrace from the hunter crash. Signed-off-by: Julian Oes --- .github/workflows/main.yml | 27 ++------------------ src/system_tests/CMakeLists.txt | 14 ++++++++++- src/system_tests/system_tests_runner.cpp | 32 ++++++++++++++++++++++++ third_party/CMakeLists.txt | 4 +++ 4 files changed, 51 insertions(+), 26 deletions(-) create mode 100644 src/system_tests/system_tests_runner.cpp diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0b43619cc3..f1d0b1ae9d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -128,41 +128,18 @@ jobs: with: path: ~/.hunter key: ${{ github.job }}-${{ hashFiles('~/.hunter/**') }}-3 - - name: install GDB - run: sudo apt-get install gdb - name: install mavlink on the system run: | cmake -Bthird_party/mavlink/build -Sthird_party/mavlink sudo cmake --build third_party/mavlink/build - name: configure - run: cmake -DSUPERBUILD=OFF -DHUNTER_ENABLED=ON -DCMAKE_TOOLCHAIN_FILE=$(pwd)/src/cmake/fpic_toolchain.cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_MAVSDK_SERVER=OFF -DBUILD_SHARED_LIBS=OFF -Bbuild -H. + run: cmake -DSUPERBUILD=OFF -DHUNTER_ENABLED=ON -DCMAKE_TOOLCHAIN_FILE=$(pwd)/src/cmake/fpic_toolchain.cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_MAVSDK_SERVER=OFF -DBUILD_SHARED_LIBS=OFF -Bbuild -H. -DENABLE_CPPTRACE=On - name: build run: cmake --build build -j2 - - name: enable core dumps - run: | - sudo bash -c 'echo "/home/runner/work/cores/%e.%p.%t" > /proc/sys/kernel/core_pattern' - sudo cat /proc/sys/kernel/core_pattern - mkdir /home/runner/work/cores/ - - name: test enabling cores - run: | - ulimit -c # should output 0 if disabled - ulimit -c unlimited - ulimit -c - name: unit tests run: ./build/src/unit_tests/unit_tests_runner - name: system tests - run: gdb -batch -ex "run" -ex "bt" --args ./build/src/system_tests/system_tests_runner --gtest_catch_exceptions=0 - - name: check core files - if: failure() - run: | - ls -l /home/runner/work/cores/ - - uses: actions/upload-artifact@v3 - if: failure() - with: - name: crashes - path: | - /home/runner/work/cores/ - ./build/ + run: ./build/src/system_tests/system_tests_runner --gtest_catch_exceptions=0 ubuntu22-style-and-proto-check: name: ubuntu-22.04 (style and proto check) diff --git a/src/system_tests/CMakeLists.txt b/src/system_tests/CMakeLists.txt index b8c92a82c1..8b7a8002f2 100644 --- a/src/system_tests/CMakeLists.txt +++ b/src/system_tests/CMakeLists.txt @@ -1,5 +1,4 @@ add_executable(system_tests_runner - ../mavsdk/core/unittests_main.cpp camera_take_photo.cpp component_information.cpp action_arm_disarm.cpp @@ -18,6 +17,7 @@ add_executable(system_tests_runner ftp_remove_dir.cpp ftp_compare_files.cpp ftp_list_dir.cpp + system_tests_runner.cpp ) target_include_directories(system_tests_runner @@ -32,3 +32,15 @@ target_link_libraries(system_tests_runner gtest_main gmock ) + +if(ENABLE_CPPTRACE) + find_package(cpptrace REQUIRED) + target_link_libraries(system_tests_runner + PRIVATE + cpptrace::cpptrace + ) + target_compile_definitions(system_tests_runner + PRIVATE + -DENABLE_CPPTRACE + ) +endif() diff --git a/src/system_tests/system_tests_runner.cpp b/src/system_tests/system_tests_runner.cpp new file mode 100644 index 0000000000..2e770f80ae --- /dev/null +++ b/src/system_tests/system_tests_runner.cpp @@ -0,0 +1,32 @@ +#if defined(ENABLE_CPPTRACE) +#include +#include +#include "log.h" +#include +#endif +#include + +#if defined(ENABLE_CPPTRACE) +void handler(int sig) +{ + mavsdk::LogErr() << "Got signal: " << strsignal(sig) << " (" << sig << ")"; + cpptrace::print_trace(); + exit(1); +} +#endif + +int main(int argc, char** argv) +{ +#if defined(ENABLE_CPPTRACE) + signal(SIGSEGV, handler); + signal(SIGQUIT, handler); + signal(SIGABRT, handler); + signal(SIGILL, handler); + signal(SIGBUS, handler); + signal(SIGPIPE, handler); + signal(SIGFPE, handler); +#endif + + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt index f56d429ccb..bfdc25bfd6 100644 --- a/third_party/CMakeLists.txt +++ b/third_party/CMakeLists.txt @@ -26,5 +26,9 @@ if (SUPERBUILD) build_target(re2) build_target(grpc) endif() + endif() +if (ENABLE_CPPTRACE) + build_target(cpptrace) +endif()