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.
This commit is contained in:
Jon Siwek 2020-01-02 13:16:25 -08:00
parent e6f4e01041
commit 38505589e1
4 changed files with 23 additions and 91 deletions

View file

@ -3,7 +3,7 @@ btest_jobs: &BTEST_JOBS 8
memory: &MEMORY 8GB memory: &MEMORY 8GB
config: &CONFIG --build-type=release --enable-cpp-tests 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 resources_template: &RESOURCES_TEMPLATE
cpu: *CPUS cpu: *CPUS
@ -16,8 +16,7 @@ ci_template: &CI_TEMPLATE
$CIRRUS_BRANCH =~ 'release/.*' $CIRRUS_BRANCH =~ 'release/.*'
# Default timeout is 60 minutes, Cirrus hard limit is 120 minutes for free # 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 # tasks, so may as well ask for full time.
# to universally asking for the maximum.
timeout_in: 120m timeout_in: 120m
sync_submodules_script: git submodule update --recursive --init sync_submodules_script: git submodule update --recursive --init
@ -114,13 +113,11 @@ freebsd_task:
prepare_script: ./ci/freebsd/prepare.sh prepare_script: ./ci/freebsd/prepare.sh
<< : *CI_TEMPLATE << : *CI_TEMPLATE
leakcheck_task: memcheck_task:
container: 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 dockerfile: ci/ubuntu-18.04/Dockerfile
<< : *RESOURCES_TEMPLATE << : *RESOURCES_TEMPLATE
<< : *CI_TEMPLATE << : *CI_TEMPLATE
env: env:
ZEEK_CI_LEAK_CHECK: true ZEEK_CI_CONFIGURE_FLAGS: *MEMCHECK_CONFIG
ZEEK_CI_CONFIGURE_FLAGS: *LEAK_CONFIG
ZEEK_CI_BTEST_JOBS: 7

View file

@ -2,8 +2,7 @@
# It's possible to use this script locally from the zeek repo's root dir. # 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 parallelism level when running tests locally is $1 if provided, else
# the value of `nproc` if available, otherwise just a single core. Run with # the value of `nproc` if available, otherwise just a single core.
# ZEEK_CI_LEAK_CHECK set to do just the leak checks.
result=0 result=0
BTEST=$(pwd)/aux/btest/btest BTEST=$(pwd)/aux/btest/btest
@ -102,57 +101,10 @@ function run_external_btests
fi 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" banner "Start tests: ${ZEEK_CI_CPUS} cpus, ${ZEEK_CI_BTEST_JOBS} btest jobs"
if [[ -n "${ZEEK_CI_LEAK_CHECK}" ]]; then run_unit_tests
run_leak_tests run_btests
else run_external_btests
run_unit_tests
run_btests
run_external_btests
fi
exit ${result} exit ${result}

View file

@ -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" 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}) ${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" 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 ./configure --build-type=Release --disable-broker-tests --enable-cpp-tests --disable-python --disable-zeekctl && make -j 2
else else
echo "Configuring zeek to build for leak testing" 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 fi
} }
@ -209,21 +209,19 @@ run() {
ulimit -a ulimit -a
ret=0 ret=0
if [ "${BUILD_DISTRO}" != "${LEAK_TEST_DISTRO}" ]; then echo
echo echo "Running unit tests ##################################################"
echo "Running unit tests ##################################################" echo
echo
set +e set +e
( cd build && . ./zeek-path-dev.sh && zeek --test ) ( cd build && . ./zeek-path-dev.sh && zeek --test )
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
ret=1 ret=1
fi
set -e
fi fi
set -e
echo echo
echo "Running baseline tests ##############################################" echo "Running baseline tests ##############################################"
echo echo
@ -231,11 +229,7 @@ run() {
set +e set +e
# Must specify a value for "-j" option, otherwise Travis uses a huge value. # 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
../../aux/btest/btest -j 4 -d
else
../../aux/btest/btest -j 4 -d -g leaks
fi
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
ret=1 ret=1
@ -278,11 +272,7 @@ run() {
if [ -d zeek-testing ]; then if [ -d zeek-testing ]; then
cd zeek-testing cd zeek-testing
if [ "${BUILD_DISTRO}" != "${LEAK_TEST_DISTRO}" ]; then make
make
else
make leaks
fi
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
showdiag showdiag
@ -294,11 +284,7 @@ run() {
if [ -d zeek-testing-private ]; then if [ -d zeek-testing-private ]; then
cd zeek-testing-private cd zeek-testing-private
if [ "${BUILD_DISTRO}" != "${LEAK_TEST_DISTRO}" ]; then make
make
else
make leaks
fi
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
showdiag showdiag

View file

@ -20,9 +20,6 @@ RUN apt-get update && apt-get -y install \
sqlite3 \ sqlite3 \
curl \ curl \
wget \ wget \
google-perftools \
libgoogle-perftools4 \
libgoogle-perftools-dev \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# Many distros adhere to PEP 394's recommendation for `python` = `python2` so # Many distros adhere to PEP 394's recommendation for `python` = `python2` so