Skip to content

Commit ed07c8f

Browse files
pmachatakuba-moo
authored andcommitted
selftests: defer: Introduce DEFER_PAUSE_ON_FAIL
The fact that all cleanup (ideally) goes through the defer framework makes debugging of these commands a bit tricky. However, this also gives us a nice point to place a hook along the lines of PAUSE_ON_FAIL. When the environment variable DEFER_PAUSE_ON_FAIL is set, and a cleanup command results in non-zero exit status, show a bit of debuginfo and give the user an opportunity to interrupt the execution altogether. Signed-off-by: Petr Machata <[email protected]> Acked-by: Nikolay Aleksandrov <[email protected]> Link: https://patch.msgid.link/2a07d24568ede6c42e4701657fa0b738e490fe59.1757004393.git.petrm@nvidia.com Signed-off-by: Jakub Kicinski <[email protected]>
1 parent d89d3b2 commit ed07c8f

File tree

1 file changed

+16
-0
lines changed
  • tools/testing/selftests/net/lib/sh

1 file changed

+16
-0
lines changed

tools/testing/selftests/net/lib/sh/defer.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#!/bin/bash
22
# SPDX-License-Identifier: GPL-2.0
33

4+
# Whether to pause and allow debugging when an executed deferred command has a
5+
# non-zero exit code.
6+
: "${DEFER_PAUSE_ON_FAIL:=no}"
7+
48
# map[(scope_id,track,cleanup_id) -> cleanup_command]
59
# track={d=default | p=priority}
610
declare -A __DEFER__JOBS
@@ -38,8 +42,20 @@ __defer__run()
3842
local track=$1; shift
3943
local defer_ix=$1; shift
4044
local defer_key=$(__defer__defer_key $track $defer_ix)
45+
local ret
4146

4247
eval ${__DEFER__JOBS[$defer_key]}
48+
ret=$?
49+
50+
if [[ "$DEFER_PAUSE_ON_FAIL" == yes && "$ret" -ne 0 ]]; then
51+
echo "Deferred command (track $track index $defer_ix):"
52+
echo " ${__DEFER__JOBS[$defer_key]}"
53+
echo "... ended with an exit status of $ret"
54+
echo "Hit enter to continue, 'q' to quit"
55+
read a
56+
[[ "$a" == q ]] && exit 1
57+
fi
58+
4359
unset __DEFER__JOBS[$defer_key]
4460
}
4561

0 commit comments

Comments
 (0)