From ea68319870623a6d65b290f8daa8a3797b6e0e52 Mon Sep 17 00:00:00 2001 From: s3rj1k Date: Thu, 25 Jul 2024 19:47:30 +0200 Subject: [PATCH] [GHA] Add tests. --- .github/workflows/ci.yml | 286 +++++++++++++++++++++++++++++++++++++++ scan_build.sh | 28 ++++ tests/unit/run-tests.mk | 5 + tests/unit/run-tests.sh | 37 ++--- tests/unit/test.sh | 12 +- 5 files changed, 348 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100755 scan_build.sh create mode 100644 tests/unit/run-tests.mk diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000000..b1dd29cd755 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,286 @@ +name: CI + +on: + push: + branches: + - master + pull_request: + types: + - opened + - synchronize + +jobs: + unit-tests_1: + name: "unit-tests (group 1)" + runs-on: ubuntu-latest + container: + image: signalwire/freeswitch-public-base:bookworm + credentials: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + options: --privileged + env: + REPOTOKEN: ${{ secrets.REPOTOKEN }} + DEBIAN_FRONTEND: noninteractive + ASAN_OPTIONS: log_path=stdout:disable_coredump=0:unmap_shadow_on_exit=1:fast_unwind_on_malloc=0 + + steps: + - name: Override core_pattern + shell: bash + run: | + cat /proc/sys/kernel/core_pattern + echo '/cores/core.%s.%E.%e.%p.%t' > /proc/sys/kernel/core_pattern + cat /proc/sys/kernel/core_pattern + + - name: Install dependencies + shell: bash + run: | + echo "machine freeswitch.signalwire.com password $REPOTOKEN" > /etc/apt/auth.conf && \ + apt-get update && \ + apt-get -y remove \ + libsofia-sip-ua0 \ + libspandsp-dev && \ + apt-get -y install \ + libspandsp3-dev && \ + rm -rf /etc/apt/auth.conf + + - name: Checkout code + uses: actions/checkout@v4 + with: + path: /__w/freeswitch/freeswitch + + - name: Bootstrap + shell: bash + working-directory: /__w/freeswitch/freeswitch + run: | + ./bootstrap.sh -j || exit 1 + + - name: Checkout Sofia-Sip + uses: actions/checkout@v4 + with: + repository: freeswitch/sofia-sip + path: /__w/freeswitch/freeswitch/sofia-sip + + - name: Build sofia-sip + shell: bash + working-directory: /__w/freeswitch/freeswitch/sofia-sip + run: | + ./autogen.sh && \ + ./configure.gnu && \ + make -j$(nproc --all) install + + - name: Build FreeSwitch + shell: bash + working-directory: /__w/freeswitch/freeswitch + run: | + echo 'codecs/mod_openh264' >> modules.conf && \ + sed -i \ + -e '/applications\/mod_http_cache/s/^#//g' \ + -e '/event_handlers\/mod_rayo/s/^#//g' \ + -e '/formats\/mod_opusfile/s/^#//g' \ + -e '/languages\/mod_lua/s/^#//g' \ + modules.conf && \ + ./configure \ + --enable-address-sanitizer \ + --enable-fake-dlclose && \ + make -j$(nproc --all) |& tee ./unit-tests-build-result.txt + + echo ${PIPESTATUS[0]} > ./build-status.txt + if ! test "$(cat ./build-status.txt | tr -d '[:space:]')" -eq 0; then + exit "$(cat ./build-status.txt | tr -d '[:space:]')" + fi + make install + + - name: Run tests + shell: bash + working-directory: /__w/freeswitch/freeswitch/tests/unit + run: | + ./run-tests.sh 2 1 + mkdir logs && (mv log_run-tests_*.html logs || true) && (mv backtrace_*.txt logs || true) + ./collect-test-logs.sh + + - name: Print result + shell: bash + working-directory: /__w/freeswitch/freeswitch/tests/unit + run: | + ls -la /cores + ls -la . + ls -la ./logs + +# - name: Notify result +# if: failure() +# uses: signalwire/actions-template/.github/actions/notify-ci-result@main +# with: +# for: "run_tests" +# test_logs_path: /__w/stack/stack/tests/unit + + unit-tests_2: + name: "unit-tests (group 2)" + runs-on: ubuntu-latest + container: + image: signalwire/freeswitch-public-base:bookworm + credentials: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + options: --privileged + env: + REPOTOKEN: ${{ secrets.REPOTOKEN }} + DEBIAN_FRONTEND: noninteractive + ASAN_OPTIONS: log_path=stdout:disable_coredump=0:unmap_shadow_on_exit=1:fast_unwind_on_malloc=0 + + steps: + - name: Override core_pattern + shell: bash + run: | + cat /proc/sys/kernel/core_pattern + echo '/cores/core.%s.%E.%e.%p.%t' > /proc/sys/kernel/core_pattern + cat /proc/sys/kernel/core_pattern + + - name: Install dependencies + shell: bash + run: | + echo "machine freeswitch.signalwire.com password $REPOTOKEN" > /etc/apt/auth.conf && \ + apt-get update && \ + apt-get -y remove \ + libsofia-sip-ua0 \ + libspandsp-dev && \ + apt-get -y install \ + libspandsp3-dev && \ + rm -rf /etc/apt/auth.conf + + - name: Checkout code + uses: actions/checkout@v4 + with: + path: /__w/freeswitch/freeswitch + + - name: Bootstrap + shell: bash + working-directory: /__w/freeswitch/freeswitch + run: | + ./bootstrap.sh -j || exit 1 + + - name: Checkout Sofia-Sip + uses: actions/checkout@v4 + with: + repository: freeswitch/sofia-sip + path: /__w/freeswitch/freeswitch/sofia-sip + + - name: Build sofia-sip + shell: bash + working-directory: /__w/freeswitch/freeswitch/sofia-sip + run: | + ./autogen.sh && \ + ./configure.gnu && \ + make -j$(nproc --all) install + + - name: Build FreeSwitch + shell: bash + working-directory: /__w/freeswitch/freeswitch + run: | + echo 'codecs/mod_openh264' >> modules.conf && \ + sed -i \ + -e '/applications\/mod_http_cache/s/^#//g' \ + -e '/event_handlers\/mod_rayo/s/^#//g' \ + -e '/formats\/mod_opusfile/s/^#//g' \ + -e '/languages\/mod_lua/s/^#//g' \ + modules.conf && \ + ./configure \ + --enable-address-sanitizer \ + --enable-fake-dlclose && \ + make -j$(nproc --all) |& tee ./unit-tests-build-result.txt + + echo ${PIPESTATUS[0]} > ./build-status.txt + if ! test "$(cat ./build-status.txt | tr -d '[:space:]')" -eq 0; then + exit "$(cat ./build-status.txt | tr -d '[:space:]')" + fi + make install + + - name: Run tests + shell: bash + working-directory: /__w/freeswitch/freeswitch/tests/unit + run: | + ./run-tests.sh 2 2 + mkdir logs && (mv log_run-tests_*.html logs || true) && (mv backtrace_*.txt logs || true) + ./collect-test-logs.sh + + - name: Print result + shell: bash + working-directory: /__w/freeswitch/freeswitch/tests/unit + run: | + ls -la /cores + ls -la . + ls -la ./logs + +# - name: Notify result +# if: failure() +# uses: signalwire/actions-template/.github/actions/notify-ci-result@main +# with: +# for: "run_tests" +# test_logs_path: /__w/stack/stack/tests/unit + + scan-build: + runs-on: ubuntu-latest + container: + image: signalwire/freeswitch-public-base:bookworm + credentials: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + options: --privileged + env: + REPOTOKEN: ${{ secrets.REPOTOKEN }} + DEBIAN_FRONTEND: noninteractive + + steps: + - name: Install dependencies + shell: bash + run: | + echo "machine freeswitch.signalwire.com password $REPOTOKEN" > /etc/apt/auth.conf && \ + apt-get update && \ + apt-get -y remove \ + libsofia-sip-ua0 \ + libspandsp-dev && \ + apt-get -y install \ + autoconf \ + libsofia-sip-ua-dev \ + libspandsp3-dev && \ + rm -rf /etc/apt/auth.conf + + - name: Checkout code + uses: actions/checkout@v4 + with: + path: /__w/freeswitch/freeswitch + + - name: Bootstrap + shell: bash + working-directory: /__w/freeswitch/freeswitch + run: | + ./bootstrap.sh -j || exit 1 + + - name: Scan-build FreeSwitch + shell: bash + working-directory: /__w/freeswitch/freeswitch + run: | + cp build/modules.conf.most modules.conf && \ + echo 'codecs/mod_openh264' >> modules.conf && \ + sed -i \ + -e '/mod_mariadb/s/^#//g' \ + -e '/mod_v8/s/^#//g' \ + -e '/mod_ilbc/s/^/#/g' \ + -e '/mod_isac/s/^/#/g' \ + -e '/mod_mp4/s/^/#/g' \ + -e '/mod_mongo/s/^/#/g' \ + -e '/mod_pocketsphinx/s/^/#/g' \ + -e '/mod_sangoma_codec/s/^/#/g' \ + -e '/mod_siren/s/^/#/g' \ + -e '/mod_avmd/s/^/#/g' \ + -e '/mod_basic/s/^/#/g' \ + -e '/mod_cdr_mongodb/s/^/#/g' \ + -e '/mod_cv/s/^/#/g' \ + -e '/mod_erlang_event/s/^/#/g' \ + -e '/mod_perl/s/^/#/g' \ + -e '/mod_rtmp/s/^/#/g' \ + -e '/mod_unimrcp/s/^/#/g' \ + -e '/mod_xml_rpc/s/^/#/g' \ + modules.conf && \ + ./configure && \ + ./scan_build.sh diff --git a/scan_build.sh b/scan_build.sh new file mode 100755 index 00000000000..200cc2d2df9 --- /dev/null +++ b/scan_build.sh @@ -0,0 +1,28 @@ +#!/bin/bash +mkdir -p scan-build +scan-build-14 --force-analyze-debug-code -o ./scan-build/ make -j`nproc --all` |& tee ./scan-build-result.txt +exitstatus=${PIPESTATUS[0]} +echo "*** Exit status is $exitstatus" +export SubString="scan-build: No bugs found" +export COMPILATION_FAILED="false" +export BUGS_FOUND="false" +if [[ "0" != "$exitstatus" ]] ; then + export COMPILATION_FAILED="true" + echo MESSAGE="compilation failed" >> $GITHUB_OUTPUT +fi +export RESULTFILE="$PWD/scan-build-result.txt" +# cat $RESULTFILE +if ! grep -sq "$SubString" $RESULTFILE; then + export BUGS_FOUND="true" + echo MESSAGE="found bugs" >> $GITHUB_OUTPUT +fi +export REPORT=$PWD/`find scan-build* -mindepth 1 -type d` +echo "COMPILATION_FAILED: $COMPILATION_FAILED" +echo "BUGS_FOUND: $BUGS_FOUND" +echo "COMPILATION_FAILED=$COMPILATION_FAILED" >> $GITHUB_OUTPUT +echo "BUGS_FOUND=$BUGS_FOUND" >> $GITHUB_OUTPUT +echo "REPORT=$REPORT" >> $GITHUB_OUTPUT +if [[ "0" != "$exitstatus" ]] || ! grep -sq "$SubString" $RESULTFILE; then + exit 1 +fi +exit 0 diff --git a/tests/unit/run-tests.mk b/tests/unit/run-tests.mk new file mode 100644 index 00000000000..8c260cfa2a5 --- /dev/null +++ b/tests/unit/run-tests.mk @@ -0,0 +1,5 @@ +.DEFAULT: + ./test.sh "$@" + +all: $(TEST_LIST) + diff --git a/tests/unit/run-tests.sh b/tests/unit/run-tests.sh index bda6a325715..559dec4a8f0 100755 --- a/tests/unit/run-tests.sh +++ b/tests/unit/run-tests.sh @@ -3,26 +3,27 @@ # "print_tests" returns relative paths to all the tests TESTS=$(make -s -C ../.. print_tests) +chunks=${1:-1} +chunk_number=${2:-1} + +IFS=$'\n' read -d '' -r -a lines <<< "$TESTS" + +result="" +for ((i=chunk_number-1; i<${#lines[@]}; i+=chunks)) +do + result+="${lines[$i]}"$'\n' +done + +TESTS=$result + echo "-----------------------------------------------------------------"; -echo "Starting tests"; +echo "Starting tests on $(nproc --all) processors"; echo "Tests found: ${TESTS}"; echo "-----------------------------------------------------------------"; -echo "Starting" > pids.txt -for i in $TESTS -do - echo "Testing $i" ; - ./test.sh "$i" & - pid=($!) - pids+=($pid) - echo "$pid $i" >> pids.txt - echo "----------------" ; -done -for pid in "${pids[@]}" -do - echo "$pid waiting" >> pids.txt - wait "$pid" - echo "$pid finished" >> pids.txt -done +make -f run-tests.mk TEST_LIST=$TESTS + +echo "Timing results:" +cat test_times.log -echo "Done running tests!" \ No newline at end of file +echo "Done running tests!" diff --git a/tests/unit/test.sh b/tests/unit/test.sh index 89711ca99bb..08de6ccd991 100755 --- a/tests/unit/test.sh +++ b/tests/unit/test.sh @@ -1,11 +1,16 @@ #!/bin/bash +start_time=$(date +%s) + # All output will be collected here TESTSUNITPATH=$PWD # All relative paths are based on the tree's root FSBASEDIR=$(realpath "$PWD/../../") +ulimit -c unlimited +ulimit -a + i=$1 echo "----------------------------------" ; @@ -28,20 +33,23 @@ echo "Start executing $currenttestpath" $currenttestpath 2>&1 | tee >(ansi2html > $log) ; exitstatus=${PIPESTATUS[0]} ; echo "End executing $currenttestpath" +end_time=$(date +%s) +duration=$((end_time - start_time)) +echo "Test $1 took $duration seconds" >> test_times.log echo "Exit status is $exitstatus" if [ "0" -eq $exitstatus ] ; then rm $log ; else echo "*** ./$i exit status is $exitstatus" ; - corefilesearch=/cores/core.*.!drone!src!${relativedir//\//!}!.libs!$file.* ; + corefilesearch=/cores/core.*.!__w!freeswitch!freeswitch!${relativedir//\//!}!.libs!$file.* ; echo $corefilesearch ; if ls $corefilesearch 1> /dev/null 2>&1; then echo "coredump found"; coredump=$(ls $corefilesearch) ; echo $coredump; echo "set logging file $TESTSUNITPATH/backtrace_${i//\//!}.txt" ; - gdb -ex "set logging file $TESTSUNITPATH/backtrace_${i//\//!}.txt" -ex "set logging on" -ex "set pagination off" -ex "bt full" -ex "bt" -ex "info threads" -ex "thread apply all bt" -ex "thread apply all bt full" -ex "quit" /drone/src/$relativedir/.libs/$file $coredump ; + gdb -ex "set logging file $TESTSUNITPATH/backtrace_${i//\//!}.txt" -ex "set logging on" -ex "set pagination off" -ex "bt full" -ex "bt" -ex "info threads" -ex "thread apply all bt" -ex "thread apply all bt full" -ex "quit" /__w/freeswitch/freeswitch/$relativedir/.libs/$file $coredump ; fi ; echo "*** $log was saved" ; fi ;