From 8bd10c0283fb5628137a8eaa498e955b740b9c94 Mon Sep 17 00:00:00 2001 From: Brad House Date: Tue, 23 Jul 2024 13:22:12 -0400 Subject: [PATCH] CI: MacOS: move to GitHub Actions instead of Cirrus-CI (#825) We've been using a lot of time on Cirrus-CI and our credits run out quickly. MacOS costs 15 compute credits vs 3 compute credits for Linux. Move MacOS testing to GitHub Actions. Fix By: Brad House (@bradh352) --- .cirrus.yml | 11 ------ .github/workflows/macos.yml | 74 +++++++++++++++++++++++++++++++++++++ .github/workflows/msys2.yml | 2 +- ci/build.sh | 10 +++-- ci/test.sh | 28 +++++++++++--- 5 files changed, 105 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/macos.yml diff --git a/.cirrus.yml b/.cirrus.yml index 9af4b304..7d20f563 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -68,17 +68,6 @@ task: TEST_SYMBOL_VISIBILITY: "yes" freebsd_instance: image_family: freebsd-13-3 - - name: "MacOS" - env: - DIST: "MACOS" - SCAN_BUILD: "/opt/homebrew/opt/llvm/bin/scan-build-py" - MAKE: "make" - BUILD_ASAN: "yes" - BUILD_UBSAN: "yes" - BUILD_ANALYZE: "yes" - TEST_SYMBOL_VISIBILITY: "yes" - macos_instance: - image: ghcr.io/cirruslabs/macos-sonoma-xcode:latest - name: "iOS" env: DIST: "iOS" diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml new file mode 100644 index 00000000..946875e1 --- /dev/null +++ b/.github/workflows/macos.yml @@ -0,0 +1,74 @@ +# Copyright (C) The c-ares project and its contributors +# SPDX-License-Identifier: MIT +name: MacOS +on: + push: + pull_request: + +concurrency: + group: ${{ github.ref }}-macos + cancel-in-progress: true + +env: + TEST_FILTER: "-v --gtest_filter=-*LiveSearchTXT*:*LiveSearchANY*:*LiveGetLocalhostByAddr*" + CMAKE_FLAGS: "-DCMAKE_BUILD_TYPE=DEBUG -DCARES_STATIC=ON -DCARES_STATIC_PIC=ON -G Ninja" + MAKE: make + +jobs: + build: + runs-on: macos-latest + name: "MacOS" + steps: + - name: Install packages + run: brew install cmake googletest llvm autoconf automake libtool make ninja + - name: Checkout c-ares + uses: actions/checkout@v4 + - name: "CMake: build and test c-ares" + env: + BUILD_TYPE: CMAKE + CMAKE_TEST_FLAGS: "-DCARES_BUILD_TESTS=ON" + TEST_DEBUGGER: lldb + run: | + ./ci/build.sh + ./ci/test.sh + - name: "Autotools: build and test c-ares" + env: + BUILD_TYPE: autotools + TEST_DEBUGGER: lldb + run: | + ./ci/build.sh + ./ci/test.sh + - name: "CMake: UBSAN: build and test c-ares" + env: + BUILD_TYPE: "ubsan" + CC: "clang" + CMAKE_TEST_FLAGS: "-DCARES_BUILD_TESTS=ON" + CFLAGS: "-fsanitize=undefined -fno-sanitize-recover" + CXXFLAGS: "-fsanitize=undefined -fno-sanitize-recover" + LDFLAGS: "-fsanitize=undefined" + TEST_DEBUGGER: "none" + run: | + ./ci/build.sh + ./ci/test.sh + - name: "CMake: ASAN: build and test c-ares" + env: + BUILD_TYPE: "asan" + CC: "clang" + CMAKE_TEST_FLAGS: "-DCARES_BUILD_TESTS=ON" + CFLAGS: "-fsanitize=address" + CXXFLAGS: "-fsanitize=address" + LDFLAGS: "-fsanitize=address" + TEST_DEBUGGER: "none" + run: | + ./ci/build.sh + ./ci/test.sh + - name: "Cmake: Static Analyzer: build c-ares" + env: + BUILD_TYPE: "analyze" + CC: "clang" + SCAN_WRAP: "/opt/homebrew/opt/llvm/bin/scan-build-py -v --status-bugs" + CMAKE_TEST_FLAGS: "-DCARES_BUILD_TESTS=OFF" + TEST_DEBUGGER: "lldb" + run: | + ./ci/build.sh + ./ci/test.sh diff --git a/.github/workflows/msys2.yml b/.github/workflows/msys2.yml index 77c893ef..00256487 100644 --- a/.github/workflows/msys2.yml +++ b/.github/workflows/msys2.yml @@ -6,7 +6,7 @@ on: pull_request: concurrency: - group: ${{ github.ref }} + group: ${{ github.ref }}-msys2 cancel-in-progress: true jobs: diff --git a/ci/build.sh b/ci/build.sh index ffd0881d..e4e9f771 100755 --- a/ci/build.sh +++ b/ci/build.sh @@ -1,7 +1,7 @@ #!/bin/sh # Copyright (C) The c-ares project and its contributors # SPDX-License-Identifier: MIT -set -e +set -e -x OS="" if [ "$TRAVIS_OS_NAME" != "" ]; then @@ -17,6 +17,7 @@ fi if [ "$BUILD_TYPE" = "autotools" -o "$BUILD_TYPE" = "coverage" ]; then autoreconf -fi + rm -rf atoolsbld mkdir atoolsbld cd atoolsbld if [ "$DIST" = "iOS" ] ; then @@ -30,9 +31,12 @@ if [ "$BUILD_TYPE" = "autotools" -o "$BUILD_TYPE" = "coverage" ]; then $SCAN_WRAP make else # Use cmake for everything else + rm -rf cmakebld + mkdir cmakebld + cd cmakebld if [ "$DIST" = "iOS" ] ; then CMAKE_FLAGS="${CMAKE_FLAGS} -DCMAKE_OSX_SYSROOT=${SYSROOT}" fi - $SCAN_WRAP cmake ${CMAKE_FLAGS} ${CMAKE_TEST_FLAGS} -Bcmakebld . - $SCAN_WRAP cmake --build cmakebld + $SCAN_WRAP cmake ${CMAKE_FLAGS} ${CMAKE_TEST_FLAGS} .. + $SCAN_WRAP cmake --build . fi diff --git a/ci/test.sh b/ci/test.sh index 2fb93ac0..3dd6c166 100755 --- a/ci/test.sh +++ b/ci/test.sh @@ -1,13 +1,13 @@ #!/bin/sh # Copyright (C) The c-ares project and its contributors # SPDX-License-Identifier: MIT -set -e +set -e -x -o pipefail # Travis on MacOS uses CloudFlare's DNS (1.1.1.1/1.0.0.1) which rejects ANY requests. # Also, LiveSearchTXT is known to fail on Cirrus-CI on some MacOS hosts, we don't get # a truncated UDP response so we never follow up with TCP. # Note res_ninit() and /etc/resolv.conf actually have different configs, bad Travis -[ -z "$TEST_FILTER" ] && export TEST_FILTER="--gtest_filter=-*LiveSearchTXT*:*LiveSearchANY*" +[ -z "$TEST_FILTER" ] && export TEST_FILTER="-4 --gtest_filter=-*LiveSearchTXT*:*LiveSearchANY*" # No tests for ios as it is a cross-compile if [ "$BUILD_TYPE" = "ios" -o "$BUILD_TYPE" = "ios-cmake" -o "$DIST" = "iOS" ] ; then @@ -23,8 +23,10 @@ PWD=`pwd` TESTDIR="${PWD}/test" if [ "$BUILD_TYPE" = "autotools" -o "$BUILD_TYPE" = "coverage" ]; then - TOOLSBIN="${PWD}/atoolsbld/src/tools" - TESTSBIN="${PWD}/atoolsbld/test" + TOOLSBIN="${PWD}/atoolsbld/src/tools/.libs/" + TESTSBIN="${PWD}/atoolsbld/test/.libs/" + export LD_LIBRARY_PATH=${PWD}/atoolsbld/src/lib/.libs:$LD_LIBRARY_PATH + export DYLD_LIBRARY_PATH=${PWD}/atoolsbld/src/lib/.libs:$DYLD_LIBRARY_PATH else TOOLSBIN="${PWD}/cmakebld/bin" TESTSBIN="${PWD}/cmakebld/bin" @@ -33,7 +35,23 @@ fi $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 $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 $TEST_FILTER +elif [ "$TEST_DEBUGGER" = "lldb" ] ; then + # LLDB won't return the exit code of the child process, so we need to extract it from the test output and verify it. + 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 $TEST_FILTER 2>&1 | tee test_output.txt + exit_code=`grep "Process [0-9]* exited with status = [0-9]* (.*)" test_output.txt | sed 's/.* = \([0-9]*\).*/\1/'` + echo "Test Exit Code: ${exit_code}" + if [ "${exit_code}" != "0" ] ; then + exit 1 + fi +else + ./arestest $TEST_FILTER +fi + ./aresfuzz ${TESTDIR}/fuzzinput/* ./aresfuzzname ${TESTDIR}/fuzznames/* ./dnsdump "${TESTDIR}/fuzzinput/answer_a" "${TESTDIR}/fuzzinput/answer_aaaa"