commit:     bf1eba183f9253a9013ce36a7b0a6d72acb90038
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Fri Nov 29 16:03:14 2019 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sat Nov 30 16:26:39 2019 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=bf1eba18

tests: allow running all tests using valgrind

use Q_RUN_WITH_VALGRIND to run the tests using valgrind

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 tests/init.sh.in                 | 10 ++++++++++
 tests/qfile/dotest               | 16 ++++++++--------
 tests/valgrind-wrapper/qvalgrind | 21 +++++++++++++++++++++
 3 files changed, 39 insertions(+), 8 deletions(-)

diff --git a/tests/init.sh.in b/tests/init.sh.in
index 875e2af..8f52086 100644
--- a/tests/init.sh.in
+++ b/tests/init.sh.in
@@ -31,6 +31,16 @@ export TZ='UTC 0'
 # create symlinks for applets
 q -i -q
 
+# inject valgrind wrapper if necessary
+if [[ -n ${Q_RUN_WITH_VALGRIND} ]] ; then
+       chmod 755 "@abs_top_srcdir@/tests/valgrind-wrapper/qvalgrind"
+       for f in @abs_top_builddir@/q?* ; do
+               [[ -L ${f} ]] || continue
+               f=${f##*/}
+               eval "$f() { 
"@abs_top_srcdir@/tests/valgrind-wrapper/qvalgrind" $f \"\${@}\" ; }"
+       done
+fi
+
 tret=0
 tpassed=0
 tfailed=0

diff --git a/tests/qfile/dotest b/tests/qfile/dotest
index 7769a51..023630e 100755
--- a/tests/qfile/dotest
+++ b/tests/qfile/dotest
@@ -6,28 +6,28 @@ export ROOT=${as}/root
 export Q_VDB=/
 
 tests=(
-       "q file -Cq /bin/bash /bin/XXXXX"
+       "qfile -Cq /bin/bash /bin/XXXXX"
        "app-shells/bash"
 
-       "q file -Co /bin/bash /bin/XXXXX"
+       "qfile -Co /bin/bash /bin/XXXXX"
        "/bin/XXXXX"
 
-       "q file -Co -x bash /bin/bash"
+       "qfile -Co -x bash /bin/bash"
        "/bin/bash"
 
-       "q file -Co -x app-shells/bash /bin/bash"
+       "qfile -Co -x app-shells/bash /bin/bash"
        "/bin/bash"
 
-       "q file -Co -x bash:0 /bin/bash"
+       "qfile -Co -x bash:0 /bin/bash"
        "/bin/bash"
 
-       "q file -Co -x app-shells/bash:0 /bin/bash"
+       "qfile -Co -x app-shells/bash:0 /bin/bash"
        "/bin/bash"
 
-       "(cd ${ROOT}/bin; q file -RCq bash)"
+       "(cd ${ROOT}/bin; qfile -RCq bash)"
        "app-shells/bash"
 
-       "(cd ${ROOT}/; q file -Co whatever)"
+       "(cd ${ROOT}/; qfile -Co whatever)"
        "whatever"
 )
 

diff --git a/tests/valgrind-wrapper/qvalgrind b/tests/valgrind-wrapper/qvalgrind
new file mode 100755
index 0000000..679c387
--- /dev/null
+++ b/tests/valgrind-wrapper/qvalgrind
@@ -0,0 +1,21 @@
+#!/usr/bin/env bash
+
+# --errors-for-leak-kinds= drop possible due to Solaris libc/_findbuf
+valgrind \
+       --leak-check=full \
+       --track-fds=yes \
+       --malloc-fill=0xdb \
+       --free-fill=0xbd \
+       --log-file=q-valgrind.log \
+       --errors-for-leak-kinds=definite \
+       --error-exitcode=234 \
+       "${@}"
+ret=$?
+if [[ ${ret} == 234 ]] ; then
+       mv q-valgrind.log q-valgrind.$$.log
+       echo "valgrind log can be found at ${PWD}/q-valgrind.$$.log" > 
/dev/stderr
+else
+       rm q-valgrind.log
+fi
+
+exit ${ret}

Reply via email to