From: Thomas Haller <thaller@redhat.com>
To: NetFilter <netfilter-devel@vger.kernel.org>
Cc: Thomas Haller <thaller@redhat.com>
Subject: [PATCH nft 04/11] tests/shell: fix handling failures with VALGRIND=y
Date: Fri, 8 Sep 2023 00:07:16 +0200 [thread overview]
Message-ID: <20230907220833.2435010-5-thaller@redhat.com> (raw)
In-Reply-To: <20230907220833.2435010-1-thaller@redhat.com>
With VALGRIND=y, on memleaks the tests did not fail. Fix that by passing
"--error-exitcode=122" to valgrind.
But just returning 122 from $NFT command may not correctly fail the test.
Instead, ensure to write a "rc-failed-valrind" file, which is picked up
by "test-wrapper.sh" to properly handle the valgrind failure (and fail
with error code 122 itself).
Also, accept NFT_TEST_VALGRIND_OPTS variable to a pass additional
arguments to valgrind. For example a "--suppressions" file.
Also show the special error code [VALGRIND] in "run-test.sh".
Signed-off-by: Thomas Haller <thaller@redhat.com>
---
tests/shell/helpers/nft-valgrind-wrapper.sh | 15 ++++++++++++++-
tests/shell/helpers/test-wrapper.sh | 13 +++++++++----
tests/shell/run-tests.sh | 4 +++-
3 files changed, 26 insertions(+), 6 deletions(-)
diff --git a/tests/shell/helpers/nft-valgrind-wrapper.sh b/tests/shell/helpers/nft-valgrind-wrapper.sh
index 9da50d4d9d1d..ad8cc74bc781 100755
--- a/tests/shell/helpers/nft-valgrind-wrapper.sh
+++ b/tests/shell/helpers/nft-valgrind-wrapper.sh
@@ -1,6 +1,6 @@
#!/bin/bash -e
-SUFFIX="$(date '+%Y%m%d-%H%M%S.%6N')"
+SUFFIX="$(date "+%Y%m%d-%H%M%S.%6N.$$")"
rc=0
libtool \
@@ -10,8 +10,21 @@ libtool \
--trace-children=yes \
--leak-check=full \
--show-leak-kinds=all \
+ --num-callers=100 \
+ --error-exitcode=122 \
+ $NFT_TEST_VALGRIND_OPTS \
"$NFT_REAL" \
"$@" \
|| rc=$?
+if [ "$rc" -eq 122 ] ; then
+ shopt -s nullglob
+ FILES=( "$NFT_TEST_TESTTMPDIR/valgrind.$SUFFIX."*".log" )
+ shopt -u nullglob
+ (
+ printf '%s\n' "args: $*"
+ printf '%s\n' "${FILES[*]}"
+ ) >> "$NFT_TEST_TESTTMPDIR/rc-failed-valgrind"
+fi
+
exit $rc
diff --git a/tests/shell/helpers/test-wrapper.sh b/tests/shell/helpers/test-wrapper.sh
index f8b27b1e9291..405e70c86751 100755
--- a/tests/shell/helpers/test-wrapper.sh
+++ b/tests/shell/helpers/test-wrapper.sh
@@ -78,13 +78,18 @@ if [ "$rc_dump" -ne 0 ] ; then
echo "$DUMPFILE" > "$NFT_TEST_TESTTMPDIR/rc-failed-dump"
fi
+rc_valgrind=0
+[ -f "$NFT_TEST_TESTTMPDIR/rc-failed-valgrind" ] && rc_valgrind=122
+
rc_tainted=0
if [ "$tainted_before" != "$tainted_after" ] ; then
echo "$tainted_after" > "$NFT_TEST_TESTTMPDIR/rc-failed-tainted"
rc_tainted=123
fi
-if [ "$rc_tainted" -ne 0 ] ; then
+if [ "$rc_valgrind" -ne 0 ] ; then
+ rc_exit="$rc_valgrind"
+elif [ "$rc_tainted" -ne 0 ] ; then
rc_exit="$rc_tainted"
elif [ "$rc_test" -ge 118 -a "$rc_test" -le 124 ] ; then
# Special exit codes are reserved. Coerce them.
@@ -101,9 +106,9 @@ fi
# We always write the real exit code of the test ($rc_test) to one of the files
# rc-{ok,skipped,failed}, depending on which it is.
#
-# Note that there might be other rc-failed-{dump,tainted} files with additional
-# errors. Note that if such files exist, the overall state will always be
-# failed too (and an "rc-failed" file exists).
+# Note that there might be other rc-failed-{dump,tainted,valgrind} files with
+# additional errors. Note that if such files exist, the overall state will
+# always be failed too (and an "rc-failed" file exists).
#
# On failure, we also write the combined "$rc_exit" code from "test-wrapper.sh"
# to "rc-failed-exit" file.
diff --git a/tests/shell/run-tests.sh b/tests/shell/run-tests.sh
index c8688587bbc4..ab91fd4d9053 100755
--- a/tests/shell/run-tests.sh
+++ b/tests/shell/run-tests.sh
@@ -527,7 +527,9 @@ print_test_result() {
else
((failed++))
result_msg_level="W"
- if [ "$rc_got" -eq 123 ] ; then
+ if [ "$rc_got" -eq 122 ] ; then
+ result_msg_status="VALGRIND"
+ elif [ "$rc_got" -eq 123 ] ; then
result_msg_status="TAINTED"
elif [ "$rc_got" -eq 124 ] ; then
result_msg_status="DUMP FAIL"
--
2.41.0
next prev parent reply other threads:[~2023-09-07 22:09 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-07 22:07 [PATCH nft 00/11] tests/shell: colorize output, fix VALGRIND mode Thomas Haller
2023-09-07 22:07 ` [PATCH nft 01/11] tests/shell: cleanup result handling in "test-wrapper.sh" Thomas Haller
2023-09-07 22:07 ` [PATCH nft 02/11] tests/shell: cleanup print_test_result() and show TAINTED error code Thomas Haller
2023-09-07 22:07 ` [PATCH nft 03/11] tests/shell: colorize terminal output with test result Thomas Haller
2023-09-07 22:07 ` Thomas Haller [this message]
2023-09-07 22:07 ` [PATCH nft 05/11] tests/shell: print the NFT setting with the VALGRIND=y wrapper Thomas Haller
2023-09-07 22:07 ` [PATCH nft 06/11] tests/shell: don't redirect error/warning messages to stderr Thomas Haller
2023-09-07 22:07 ` [PATCH nft 07/11] tests/shell: redirect output of test script to file too Thomas Haller
2023-09-07 22:07 ` [PATCH nft 08/11] tests/shell: print "kernel is tainted" separate from test result Thomas Haller
2023-09-07 22:07 ` [PATCH nft 09/11] tests/shell: no longer enable verbose output when selecting a test Thomas Haller
2023-09-07 22:07 ` [PATCH nft 10/11] tests/shell: record wall time of test run in result data Thomas Haller
2023-09-07 22:07 ` [PATCH nft 11/11] tests/shell: set NFT_TEST_JOBS based on $(nproc) Thomas Haller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230907220833.2435010-5-thaller@redhat.com \
--to=thaller@redhat.com \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).