Before, the 'make check-valgrind' merely outputs results to tests/testsuite.dir/*/valgrind* and depends on users to verify any errors in those files. This patch greps results and shows a summary.
The patch ignores the exit status of testsuite by adding '-' before $(SHELL), so that even if test case fails, the make continues executing 'valgrind-parse.sh' and reports total errors. The exit status is not important here becuase we assume 'make check' catches the testsuite error, so here 'make check-valgrind' focuses on valgrind's report. Signed-off-by: William Tu <u9012...@gmail.com> --- v3: https://patchwork.ozlabs.org/patch/604272/ v3->v4 - remove --erroddrs-for-leak-kinds=definite, definite and possible memory leak will be consider errors. - use /bin/sh insteaf of /bin/bash - code refactoring, fixing some unnecessary portability assumptions. An example run: ---------------------------------------------------------------------- Valgrind output can be found in tests/testsuite.dir/*/valgrind.*\n ---------------------------------------------------------------------- MemLeak: Definitely lost: ok MemLeak: Possibly lost: FAILED Invalid write/read: ok Invalid/Mismatched free: ok Conditional jump or move depends on uninitialised value: ok Syscall param write(buf) points to uninitialised: ok Source and destination overlap: ok ----------------- Total errors: 468 ----------------- Makefile:5872: recipe for target 'check-valgrind' failed make: *** [check-valgrind] Error 1 --- tests/automake.mk | 10 +++----- tests/valgrind-parse.sh | 65 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 6 deletions(-) create mode 100755 tests/valgrind-parse.sh diff --git a/tests/automake.mk b/tests/automake.mk index 0b77617..52be78e 100644 --- a/tests/automake.mk +++ b/tests/automake.mk @@ -10,7 +10,8 @@ EXTRA_DIST += \ tests/atlocal.in \ $(srcdir)/package.m4 \ $(srcdir)/tests/testsuite \ - $(srcdir)/tests/testsuite.patch + $(srcdir)/tests/testsuite.patch \ + $(srcdir)/tests/valgrind-parse.sh COMMON_MACROS_AT = \ tests/ovsdb-macros.at \ @@ -206,11 +207,8 @@ VALGRIND = valgrind --log-file=valgrind.%p --leak-check=full \ EXTRA_DIST += tests/glibc.supp tests/openssl.supp check-valgrind: all tests/atconfig tests/atlocal $(TESTSUITE) \ $(valgrind_wrappers) $(check_DATA) - $(SHELL) '$(TESTSUITE)' -C tests CHECK_VALGRIND=true VALGRIND='$(VALGRIND)' AUTOTEST_PATH='tests/valgrind:$(AUTOTEST_PATH)' -d $(TESTSUITEFLAGS) - @echo - @echo '----------------------------------------------------------------------' - @echo 'Valgrind output can be found in tests/testsuite.dir/*/valgrind.*' - @echo '----------------------------------------------------------------------' + -$(SHELL) '$(TESTSUITE)' -C tests CHECK_VALGRIND=true VALGRIND='$(VALGRIND)' AUTOTEST_PATH='tests/valgrind:$(AUTOTEST_PATH)' -d $(TESTSUITEFLAGS) + @EGREP='$(EGREP)' $(SHELL) $(abs_top_srcdir)/tests/valgrind-parse.sh # OFTest support. diff --git a/tests/valgrind-parse.sh b/tests/valgrind-parse.sh new file mode 100755 index 0000000..8be8683 --- /dev/null +++ b/tests/valgrind-parse.sh @@ -0,0 +1,65 @@ +#!/bin/sh +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +set -e + +EGREP=${EGREP-grep -E} +valgrind_output_dir='tests/testsuite.dir/[0-9]*/valgrind*' + +# Valgrind error pattern, see: +# http://valgrind.org/docs/manual/mc-manual.html#mc-manual.errormsgs +valgrind_def_leak='definitely lost in' +valgrind_pos_leak='possibly lost in' +valgrind_invalid_rw='Invalid (write|read) of size' +valgrind_invalid_free='(Invalid|Mismatched) free' +valgrind_uninit_jmp='Conditional jump or move depends on uninitialised value' +valgrind_uninit_syscall='Syscall param write(buf) points to uninitialised' +valgrind_overlap='Source and destination overlap in' + +printf "%s\n" "----------------------------------------------------------------------" +printf "%s\n" "Valgrind output can be found in tests/testsuite.dir/*/valgrind.*\n" +printf "%s\n" "----------------------------------------------------------------------" + +parse_and_check() { + printf "%s: " "$2" + if $EGREP -r "$1" $valgrind_output_dir > /dev/null; + then + printf "%s\n" "FAILED"; + else + printf "%s\n" "ok"; + fi +} + +parse_and_check "$valgrind_def_leak" "MemLeak: Definitely lost" +parse_and_check "$valgrind_pos_leak" "MemLeak: Possibly lost" +parse_and_check "$valgrind_invalid_rw" "Invalid write/read" +parse_and_check "$valgrind_invalid_free" "Invalid/Mismatched free" +parse_and_check "$valgrind_uninit_jmp" "$valgrind_uninit_jmp" +parse_and_check "$valgrind_uninit_syscall" "$valgrind_uninit_syscall" +parse_and_check "$valgrind_overlap" "Source and destination overlap" + +error_num=`find tests/testsuite.dir -name "valgrind.*" | xargs cat | \ + sed -n 's/.*ERROR\ SUMMARY:\ \([0-9]*\)\ errors.*/.+\1/p' | bc | tail -1` + +printf "%s\n" "-----------------" +printf "%s\n" "Total errors: $error_num" +printf "%s\n" "-----------------" + +if [ "$error_num" -eq "0" ]; +then + exit 0 +else + exit 1 +fi + -- 2.5.0 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev