From f9affd3a0c04d1a9b6c4753ca84819ab64a360c1 Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Mon, 13 Feb 2012 08:27:10 +0000 Subject: [PATCH] AddressSanitizer: Use FileCheck instead of grep for pure C output tests llvm-svn: 150366 --- compiler-rt/lib/asan/tests/test_output.sh | 23 +++++++++++++++++---- compiler-rt/lib/asan/tests/use-after-free.c | 3 +++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/compiler-rt/lib/asan/tests/test_output.sh b/compiler-rt/lib/asan/tests/test_output.sh index 385fba253250..f619244b46b5 100755 --- a/compiler-rt/lib/asan/tests/test_output.sh +++ b/compiler-rt/lib/asan/tests/test_output.sh @@ -7,22 +7,37 @@ CXX=$1 CC=$2 CXXFLAGS="-mno-omit-leaf-frame-pointer -fno-omit-frame-pointer -fno-optimize-sibling-calls" SYMBOLIZER=../scripts/asan_symbolize.py +FILE_CHECK=../../../../../build/Release+Asserts/bin/FileCheck + +# check_program exe_file src_file [check_prefix] +check_program() { + exe=$1 + src=$2 + prefix="CHECK" + if [ "z$3" != "z" ] ; then + prefix=$3 + fi + ./$exe 2>&1 | $SYMBOLIZER 2> /dev/null | c++filt | \ + $FILE_CHECK $src --check-prefix=$prefix +} C_TEST=use-after-free echo "Sanity checking a test in pure C" $CC -g -faddress-sanitizer -O2 $C_TEST.c -./a.out 2>&1 | grep "heap-use-after-free" > /dev/null +check_program a.out $C_TEST.c rm ./a.out echo "Sanity checking a test in pure C with -pie" $CC -g -faddress-sanitizer -O2 $C_TEST.c -pie -./a.out 2>&1 | grep "heap-use-after-free" > /dev/null +check_program a.out $C_TEST.c rm ./a.out echo "Testing sleep_before_dying" $CC -g -faddress-sanitizer -O2 $C_TEST.c -ASAN_OPTIONS=sleep_before_dying=1 ./a.out 2>&1 | grep "Sleeping for 1 second" > /dev/null -rm a.out +export ASAN_OPTIONS="sleep_before_dying=1" +check_program a.out $C_TEST.c CHECKSLEEP +export ASAN_OPTIONS="" +rm ./a.out for t in *.tmpl; do for b in 32 64; do diff --git a/compiler-rt/lib/asan/tests/use-after-free.c b/compiler-rt/lib/asan/tests/use-after-free.c index 60626bff778a..801d3f68a466 100644 --- a/compiler-rt/lib/asan/tests/use-after-free.c +++ b/compiler-rt/lib/asan/tests/use-after-free.c @@ -4,3 +4,6 @@ int main() { free(x); return x[5]; } + +// CHECK: heap-use-after-free +// CHECKSLEEP: Sleeping for 1 second