From 2bd73c9a7dbb79cc56667ced13fceb70a68a5e26 Mon Sep 17 00:00:00 2001 From: Brad House Date: Thu, 18 Jul 2024 19:36:51 -0400 Subject: [PATCH] CI: ability to run tests through debugger and print backtrace if there is a crash --- .cirrus.yml | 29 +++++++++++++++++++---------- .github/workflows/netbsd.yml | 6 +++--- .github/workflows/openbsd.yml | 6 +++--- .github/workflows/solaris.yml | 5 +++-- ci/test.sh | 15 ++++++++++++++- 5 files changed, 42 insertions(+), 19 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 9af4b304..b847d9eb 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -19,6 +19,7 @@ task: BUILD_VALGRIND: "yes" BUILD_COVERAGE: "yes" BUILD_ANALYZE: "yes" + TEST_DEBUGGER: "gdb" TEST_SYMBOL_VISIBILITY: "yes" container: image: debian:latest @@ -32,6 +33,7 @@ task: BUILD_UBSAN: "yes" BUILD_VALGRIND: "yes" BUILD_ANALYZE: "yes" + TEST_DEBUGGER: "gdb" TEST_SYMBOL_VISIBILITY: "yes" container: image: alpine:latest @@ -40,6 +42,7 @@ task: DIST: "UBUNTU" LC_ALL: "C" MAKE: "make" + TEST_DEBUGGER: "gdb" container: image: ubuntu:20.04 - name: "Debian arm64" @@ -57,12 +60,14 @@ task: BUILD_ASAN: "no" BUILD_UBSAN: "no" BUILD_ANALYZE: "yes" + TEST_DEBUGGER: "gdb" arm_container: image: debian:latest - name: "FreeBSD amd64" env: DIST: "FREEBSD" SCAN_BUILD: "scan-build" + TEST_DEBUGGER: "lldb" MAKE: "gmake" BUILD_ANALYZE: "yes" TEST_SYMBOL_VISIBILITY: "yes" @@ -73,6 +78,7 @@ task: DIST: "MACOS" SCAN_BUILD: "/opt/homebrew/opt/llvm/bin/scan-build-py" MAKE: "make" + TEST_DEBUGGER: "lldb" BUILD_ASAN: "yes" BUILD_UBSAN: "yes" BUILD_ANALYZE: "yes" @@ -113,6 +119,7 @@ task: env: BUILD_TYPE: "asan" CC: "clang" + TEST_DEBUGGER: "none" CONFIG_OPTS: "--enable-debug" CFLAGS: "-fsanitize=address" CXXFLAGS: "-fsanitize=address" @@ -123,6 +130,7 @@ task: env: BUILD_TYPE: "ubsan" CC: "clang" + TEST_DEBUGGER: "none" CONFIG_OPTS: "--enable-debug" CFLAGS: "-fsanitize=undefined -fno-sanitize-recover" CXXFLAGS: "-fsanitize=undefined -fno-sanitize-recover" @@ -132,6 +140,7 @@ task: env: BUILD_TYPE: "analyze" CC: "clang" + TEST_DEBUGGER: "lldb" SCAN_WRAP: "${SCAN_BUILD} -v --status-bugs" CONFIG_OPTS: "--enable-debug --disable-tests" CMAKE_TEST_FLAGS: "-DCARES_BUILD_TESTS=OFF" @@ -161,16 +170,16 @@ task: apk add cmake samurai gtest-dev autoconf autoconf-archive automake libtool pkgconf make case "${BUILD_TYPE}" in asan|lsan|ubsan) - apk add clang17 compiler-rt + apk add clang17 compiler-rt lldb ;; analyze) - apk add clang17 clang17-analyzer compiler-rt + apk add clang17 clang17-analyzer compiler-rt lldb ;; valgrind) apk add gcc g++ valgrind ;; *) - apk add gcc g++ + apk add gcc g++ gdb ;; esac ;; @@ -180,10 +189,10 @@ task: apt-get install -y cmake ninja-build autoconf automake libtool g++ libgmock-dev pkg-config case "${BUILD_TYPE}" in asan|lsan|ubsan) - apt-get install -yq clang + apt-get install -yq clang lldb ;; analyze) - apt-get install -yq clang clang-tools + apt-get install -yq clang clang-tools lldb ;; valgrind) apt-get install -yq valgrind @@ -192,17 +201,17 @@ task: apt-get install -yq lcov git pip pip3 install --break-system-packages --user cpp-coveralls ;; + *) + apt-get install -yq gdb + ;; esac ;; FREEBSD) # pkg upgrade -y && \ - pkg install -y cmake ninja googletest pkgconf + pkg install -y cmake ninja googletest pkgconf llvm gmake case "${BUILD_TYPE}" in - asan|analyze|ubsan|lsan) - pkg install -y llvm autoconf automake libtool gmake - ;; autotools) - pkg install -y autoconf automake libtool gmake + pkg install -y autoconf automake libtool ;; esac ;; diff --git a/.github/workflows/netbsd.yml b/.github/workflows/netbsd.yml index f93f9859..6e0adf3c 100644 --- a/.github/workflows/netbsd.yml +++ b/.github/workflows/netbsd.yml @@ -21,18 +21,18 @@ jobs: CMAKE_TEST_FLAGS: "-DCARES_BUILD_TESTS=ON" PKG_PATH: https://cdn.netbsd.org/pub/pkgsrc/packages/NetBSD/amd64/10.0/All/ TEST_FILTER: "--gtest_filter=-*LiveSearchTXT*:*LiveSearchANY*:*Parallel*" - GTEST_INSTALL_FAILURE_SIGNAL_HANDLER: 1 + TEST_DEBUGGER: "gdb" with: operating_system: netbsd version: '10.0' shell: 'bash' - environment_variables: DIST BUILD_TYPE CMAKE_FLAGS CMAKE_TEST_FLAGS PKG_PATH TEST_FILTER GTEST_INSTALL_FAILURE_SIGNAL_HANDLER + environment_variables: DIST BUILD_TYPE CMAKE_FLAGS CMAKE_TEST_FLAGS PKG_PATH TEST_FILTER TEST_DEBUGGER run: | echo "BUILD_TYPE: $BUILD_TYPE" echo "CMAKE_FLAGS: $CMAKE_FLAGS" echo "CMAKE_TEST_FLAGS: $CMAKE_TEST_FLAGS" echo "PKG_PATH: $PKG_PATH" - sudo -E /usr/pkg/sbin/pkg_add -u cmake googletest pkgconf ninja-build + sudo -E /usr/pkg/sbin/pkg_add -u cmake googletest pkgconf ninja-build gdb ./ci/build.sh ./ci/test.sh diff --git a/.github/workflows/openbsd.yml b/.github/workflows/openbsd.yml index 7cf9d70e..b4b3d533 100644 --- a/.github/workflows/openbsd.yml +++ b/.github/workflows/openbsd.yml @@ -18,14 +18,14 @@ jobs: BUILD_TYPE: "cmake" CMAKE_FLAGS: "-DCMAKE_BUILD_TYPE=DEBUG -DCARES_STATIC=ON -DCARES_STATIC_PIC=ON -G Ninja" CMAKE_TEST_FLAGS: "-DCARES_BUILD_TESTS=ON" - GTEST_INSTALL_FAILURE_SIGNAL_HANDLER: 1 + TEST_DEBUGGER: "lldb" with: operating_system: openbsd version: '7.5' shell: 'bash' - environment_variables: DIST BUILD_TYPE CMAKE_FLAGS CMAKE_TEST_FLAGS GTEST_INSTALL_FAILURE_SIGNAL_HANDLER + environment_variables: DIST BUILD_TYPE CMAKE_FLAGS CMAKE_TEST_FLAGS TEST_DEBUGGER run: | - sudo pkg_add cmake gtest pkgconf ninja + sudo pkg_add cmake gtest pkgconf ninja gdb lldb echo "BUILD_TYPE: $BUILD_TYPE" echo "CMAKE_FLAGS: $CMAKE_FLAGS" echo "CMAKE_TEST_FLAGS: $CMAKE_TEST_FLAGS" diff --git a/.github/workflows/solaris.yml b/.github/workflows/solaris.yml index 106324d2..96304d34 100644 --- a/.github/workflows/solaris.yml +++ b/.github/workflows/solaris.yml @@ -16,17 +16,18 @@ jobs: CMAKE_FLAGS: "-DCMAKE_BUILD_TYPE=DEBUG -DCARES_STATIC=ON -DCARES_STATIC_PIC=ON" CMAKE_TEST_FLAGS: "-DCMAKE_PREFIX_PATH=/usr/local/ -DCARES_BUILD_TESTS=ON -DCMAKE_CXX_FLAGS=-DGTEST_HAS_PTHREAD=0" TEST_FILTER: "--gtest_filter=-*Live*" + TEST_DEBUGGER: "none" steps: - uses: actions/checkout@v4 - name: Solaris Build and Test id: solaris uses: vmactions/solaris-vm@v1 with: - envs: 'DIST BUILD_TYPE CMAKE_FLAGS CMAKE_TEST_FLAGS TEST_FILTER CXXFLAGS' + envs: 'DIST BUILD_TYPE CMAKE_FLAGS CMAKE_TEST_FLAGS TEST_FILTER CXXFLAGS TEST_DEBUGGER' usesh: true # package list: http://pkg.oracle.com/solaris/release/en/catalog.shtml prepare: | - pkg install -v --no-refresh cmake gcc pkg-config gnu-make git + pkg install -v --no-refresh cmake gcc pkg-config gnu-make git gdb # We have to jump through a lot of hoops with google test. # - We need to max out at v1.13.x because this solaris VM is old and # only has cmake 3.9 diff --git a/ci/test.sh b/ci/test.sh index 9429cbf5..aba5f68b 100755 --- a/ci/test.sh +++ b/ci/test.sh @@ -25,6 +25,7 @@ TESTDIR="${PWD}/test" if [ "$BUILD_TYPE" = "autotools" -o "$BUILD_TYPE" = "coverage" ]; then TOOLSBIN="${PWD}/atoolsbld/src/tools" TESTSBIN="${PWD}/atoolsbld/test" + TEST_DEBUGGER="" else TOOLSBIN="${PWD}/cmakebld/bin" TESTSBIN="${PWD}/cmakebld/bin" @@ -36,7 +37,19 @@ export GTEST_INSTALL_FAILURE_SIGNAL_HANDLER $TEST_WRAP "${TOOLSBIN}/adig" www.google.com $TEST_WRAP "${TOOLSBIN}/ahost" www.google.com cd "${TESTSBIN}" -$TEST_WRAP ./arestest -4 $TEST_FILTER + +if [ "$TEST_WRAP" != "" ] ; then + $TEST_WRAP ./arestest -4 $TEST_FILTER +elif [ "$TEST_DEBUGGER" = "gdb-nothreads" ] ; then + gdb --batch --batch-silent --return-child-result -ex "handle SIGPIPE nostop noprint pass" -ex "run" -ex "bt" -ex "quit" --args ./arestest -4 $TEST_FILTER +elif [ "$TEST_DEBUGGER" = "gdb" ] ; then + gdb --batch --batch-silent --return-child-result -ex "handle SIGPIPE nostop noprint pass" -ex "run" -ex "thread apply all bt" -ex "quit" --args ./arestest -4 $TEST_FILTER +elif [ "$TEST_DEBUGGER" = "lldb" ] ; then + lldb --batch -o "settings set target.process.extra-startup-command 'process handle SIGPIPE -n true -p true -s false'" -o "process launch --shell-expand-args 0" -k "thread backtrace all" -k "quit 1" -- ./arestest -4 $TEST_FILTER +else + ./arestest -4 $TEST_FILTER +fi + ./aresfuzz ${TESTDIR}/fuzzinput/* ./aresfuzzname ${TESTDIR}/fuzznames/* ./dnsdump "${TESTDIR}/fuzzinput/answer_a" "${TESTDIR}/fuzzinput/answer_aaaa"