From 38505589e12d739588c5eea4c91f8b43aa482733 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 2 Jan 2020 13:16:25 -0800 Subject: [PATCH] Switch CI scripts to use ASAN/LSAN instead of gperftools Using AddressSanitizer/LeakSanitizer is better. It covers the full unit/baseline test suite by default without requiring one to write specific memory leak tests. It also covers other types of memory errors besides just leaks. --- .cirrus.yml | 13 ++++----- ci/test.sh | 56 +++----------------------------------- ci/travis-job | 42 ++++++++++------------------ ci/ubuntu-18.04/Dockerfile | 3 -- 4 files changed, 23 insertions(+), 91 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 1625a120b6..b14fcd08c1 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -3,7 +3,7 @@ btest_jobs: &BTEST_JOBS 8 memory: &MEMORY 8GB config: &CONFIG --build-type=release --enable-cpp-tests -leak_config: &LEAK_CONFIG --build-type=debug --enable-perftools-debug +memcheck_config: &MEMCHECK_CONFIG --build-type=debug --enable-cpp-tests --sanitizers=address resources_template: &RESOURCES_TEMPLATE cpu: *CPUS @@ -16,8 +16,7 @@ ci_template: &CI_TEMPLATE $CIRRUS_BRANCH =~ 'release/.*' # Default timeout is 60 minutes, Cirrus hard limit is 120 minutes for free - # tasks. This leakcheck one can tend to run long, but see no downside - # to universally asking for the maximum. + # tasks, so may as well ask for full time. timeout_in: 120m sync_submodules_script: git submodule update --recursive --init @@ -114,13 +113,11 @@ freebsd_task: prepare_script: ./ci/freebsd/prepare.sh << : *CI_TEMPLATE -leakcheck_task: +memcheck_task: container: - # Just uses a recent/common distro to run leak checks. + # Just uses a recent/common distro to run memory error/leak checks. dockerfile: ci/ubuntu-18.04/Dockerfile << : *RESOURCES_TEMPLATE << : *CI_TEMPLATE env: - ZEEK_CI_LEAK_CHECK: true - ZEEK_CI_CONFIGURE_FLAGS: *LEAK_CONFIG - ZEEK_CI_BTEST_JOBS: 7 + ZEEK_CI_CONFIGURE_FLAGS: *MEMCHECK_CONFIG diff --git a/ci/test.sh b/ci/test.sh index d7c1e71ab7..264e3d7454 100755 --- a/ci/test.sh +++ b/ci/test.sh @@ -2,8 +2,7 @@ # It's possible to use this script locally from the zeek repo's root dir. # The parallelism level when running tests locally is $1 if provided, else -# the value of `nproc` if available, otherwise just a single core. Run with -# ZEEK_CI_LEAK_CHECK set to do just the leak checks. +# the value of `nproc` if available, otherwise just a single core. result=0 BTEST=$(pwd)/aux/btest/btest @@ -102,57 +101,10 @@ function run_external_btests fi } -function run_leak_tests - { - local zeek_testing_pid="" - local zeek_testing_pid_private="" - banner "Running memory leak tests: zeek" - - pushd testing/btest - ${BTEST} -d -b -x btest-results.xml -j ${ZEEK_CI_BTEST_JOBS} -g leaks || result=1 - prep_artifacts - popd - - pushd testing/external/zeek-testing - ${BTEST} -d -b -x btest-results.xml -j ${ZEEK_CI_BTEST_JOBS} -g leaks >btest.out 2>&1 & - zeek_testing_pid=$! - popd - - if [[ -d testing/external/zeek-testing-private ]]; then - pushd testing/external/zeek-testing-private - # Note that we don't use btest's "-d" flag or generate/upload any - # artifacts to prevent leaking information about the private pcaps. - ${BTEST} -b -j ${ZEEK_CI_BTEST_JOBS} -g leaks >btest.out 2>&1 & - zeek_testing_private_pid=$! - popd - fi - - banner "Running memory leak tests: external/zeek-testing" - wait ${zeek_testing_pid} || result=1 - pushd testing/external/zeek-testing - cat btest.out - prep_artifacts - popd - - if [[ -n "${zeek_testing_private_pid}" ]]; then - banner "Running memory leak tests: external/zeek-testing-private" - wait ${zeek_testing_private_pid} || result=1 - cat testing/external/zeek-testing-private/btest.out - else - banner "Skipping private tests (not available for PRs)" - fi - - return 0 - } - banner "Start tests: ${ZEEK_CI_CPUS} cpus, ${ZEEK_CI_BTEST_JOBS} btest jobs" -if [[ -n "${ZEEK_CI_LEAK_CHECK}" ]]; then - run_leak_tests -else - run_unit_tests - run_btests - run_external_btests -fi +run_unit_tests +run_btests +run_external_btests exit ${result} diff --git a/ci/travis-job b/ci/travis-job index 66df4eda4b..7da51117a2 100755 --- a/ci/travis-job +++ b/ci/travis-job @@ -100,7 +100,7 @@ install_in_docker() { distro_cmds="apt-get update; apt-get -y install wget xz-utils gdb cmake make gcc g++ flex bison python3 libpcap-dev libssl-dev zlib1g-dev libkrb5-dev git sqlite3 curl bsdmainutils; ln -s /usr/bin/python3 /usr/local/bin/python" ;; ${LEAK_TEST_DISTRO}) - distro_cmds="apt-get update; apt-get -y install gdb cmake make gcc g++ flex bison python3 libpcap-dev libssl-dev zlib1g-dev libkrb5-dev git sqlite3 curl bsdmainutils google-perftools libgoogle-perftools4 libgoogle-perftools-dev; ln -s /usr/bin/python3 /usr/local/bin/python" + distro_cmds="apt-get update; apt-get -y install gdb cmake make gcc g++ flex bison python3 libpcap-dev libssl-dev zlib1g-dev libkrb5-dev git sqlite3 curl bsdmainutils; ln -s /usr/bin/python3 /usr/local/bin/python" local_distro="ubuntu_18.04" ;; *) @@ -168,7 +168,7 @@ build() { ./configure --build-type=Release --disable-broker-tests --enable-cpp-tests --disable-python --disable-zeekctl && make -j 2 else echo "Configuring zeek to build for leak testing" - ./configure --build-type=Debug --disable-broker-tests --disable-python --disable-zeekctl --enable-perftools --enable-perftools-debug && make -j 2 + ./configure --build-type=Debug --disable-broker-tests --enable-cpp-tests --disable-python --disable-zeekctl --sanitizers=address && make -j 2 fi } @@ -209,21 +209,19 @@ run() { ulimit -a ret=0 - if [ "${BUILD_DISTRO}" != "${LEAK_TEST_DISTRO}" ]; then - echo - echo "Running unit tests ##################################################" - echo + echo + echo "Running unit tests ##################################################" + echo - set +e - ( cd build && . ./zeek-path-dev.sh && zeek --test ) + set +e + ( cd build && . ./zeek-path-dev.sh && zeek --test ) - if [ $? -ne 0 ]; then - ret=1 - fi - - set -e + if [ $? -ne 0 ]; then + ret=1 fi + set -e + echo echo "Running baseline tests ##############################################" echo @@ -231,11 +229,7 @@ run() { set +e # Must specify a value for "-j" option, otherwise Travis uses a huge value. - if [ "${BUILD_DISTRO}" != "${LEAK_TEST_DISTRO}" ]; then - ../../aux/btest/btest -j 4 -d - else - ../../aux/btest/btest -j 4 -d -g leaks - fi + ../../aux/btest/btest -j 4 -d if [ $? -ne 0 ]; then ret=1 @@ -278,11 +272,7 @@ run() { if [ -d zeek-testing ]; then cd zeek-testing - if [ "${BUILD_DISTRO}" != "${LEAK_TEST_DISTRO}" ]; then - make - else - make leaks - fi + make if [ $? -ne 0 ]; then showdiag @@ -294,11 +284,7 @@ run() { if [ -d zeek-testing-private ]; then cd zeek-testing-private - if [ "${BUILD_DISTRO}" != "${LEAK_TEST_DISTRO}" ]; then - make - else - make leaks - fi + make if [ $? -ne 0 ]; then showdiag diff --git a/ci/ubuntu-18.04/Dockerfile b/ci/ubuntu-18.04/Dockerfile index 67b711814e..64b84692d2 100644 --- a/ci/ubuntu-18.04/Dockerfile +++ b/ci/ubuntu-18.04/Dockerfile @@ -20,9 +20,6 @@ RUN apt-get update && apt-get -y install \ sqlite3 \ curl \ wget \ - google-perftools \ - libgoogle-perftools4 \ - libgoogle-perftools-dev \ && rm -rf /var/lib/apt/lists/* # Many distros adhere to PEP 394's recommendation for `python` = `python2` so