Commit b9244352 authored by Paul Luse's avatar Paul Luse Committed by Jim Harris
Browse files

unittests.sh: use valgrind if installed and not using ASAN



Automatically uses valgrind with the same options as CI does
provided that it is available ASAN is not enabled.

NOTE: if you don't want to use valgrind then enable ASAN

Change-Id: I44f8322680eb2608464eb128d49d20dc1d311f0c
Signed-off-by: default avatarPaul Luse <paul.e.luse@intel.com>
Reviewed-on: https://review.gerrithub.io/369064


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 36a0d1e5
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ timing_exit rbd_setup

if [ $SPDK_TEST_UNITTEST -eq 1 ]; then
	timing_enter unittest
	valgrind="$valgrind" run_test ./unittest.sh
	run_test ./unittest.sh
	timing_exit unittest
fi

+5 −7
Original line number Diff line number Diff line
@@ -27,6 +27,11 @@ fi
: ${SPDK_RUN_ASAN=0}; export SPDK_RUN_ASAN
: ${SPDK_RUN_UBSAN=1}; export SPDK_RUN_UBSAN

# pass our valgrind desire on to unittest.sh
if [ $SPDK_RUN_VALGRIND -eq 0 ]; then
	export valgrind=''
fi

config_params='--enable-debug --enable-werror'

export UBSAN_OPTIONS='halt_on_error=1:print_stacktrace=1:abort_on_error=1'
@@ -102,13 +107,6 @@ if [ -z "$output_dir" ]; then
	export output_dir
fi

# Valgrind does not work well when ASAN is enabled, so only use valgrind if ASAN is disabled
if [ $SPDK_RUN_ASAN -eq 0 ] && [ $SPDK_RUN_VALGRIND -eq 1 ] && hash valgrind &> /dev/null; then
	valgrind='valgrind --leak-check=full --error-exitcode=2'
else
	valgrind=''
fi

function timing() {
	direction="$1"
	testname="$2"
+16 −1
Original line number Diff line number Diff line
#!/usr/bin/env bash
#
# Environment variables:
#  $valgrind    Valgrind executable name, if desired
#  $valgrind    Specify the valgrind command line, if not
#               then a default command line is used

set -xe

# if ASAN is enabled, use it.  If not use valgrind if installed but allow
# the env variable to override the default shown below.
if [ -z ${valgrind+x} ]; then
	if grep -q '#undef SPDK_CONFIG_ASAN' config.h && hash valgrind; then
		valgrind='valgrind --leak-check=full --error-exitcode=2'
	else
		valgrind=''
	fi
fi

# setup local unit test coverage if cov is available
if hash lcov && grep -q '#define SPDK_CONFIG_COVERAGE 1' config.h; then
	cov_avail="yes"
@@ -105,5 +116,9 @@ if [ "$cov_avail" = "yes" ]; then
else
	echo "WARN: lcov not installed or SPDK built without coverage!"
fi
if grep -q '#undef SPDK_CONFIG_ASAN' config.h && [ "$valgrind" = "" ]; then
	echo "WARN: neither valgrind nor ASAN is enabled!"
fi

echo
echo