aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorнаб <[email protected]>2022-03-16 14:27:04 +0100
committerBrian Behlendorf <[email protected]>2022-04-01 18:01:51 -0700
commit598fed7ecdade29e569067ba49d5556a78f1adc3 (patch)
treeb55367951ac85daf43f2ccf85cd9848d1effeaea /tests
parent912d2aa7d7c76dc021c67a090a472a82c6431b52 (diff)
tests: revert back to original coredump patterns on Linux, too
Otherwise, they leak past the tests and contaminate the running system, breaking coredumps entirely Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: John Kennedy <[email protected]> Reviewed-by: Ryan Moeller <[email protected]> Co-authored-by: Yannick Le Pennec <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Closes #13259
Diffstat (limited to 'tests')
-rw-r--r--tests/zfs-tests/include/libtest.shlib44
-rwxr-xr-xtests/zfs-tests/tests/functional/cli_root/zfs/zfs_002_pos.ksh44
-rwxr-xr-xtests/zfs-tests/tests/functional/cli_root/zpool/zpool_002_pos.ksh39
-rwxr-xr-xtests/zfs-tests/tests/functional/cli_root/zpool/zpool_003_pos.ksh39
4 files changed, 77 insertions, 89 deletions
diff --git a/tests/zfs-tests/include/libtest.shlib b/tests/zfs-tests/include/libtest.shlib
index b01d8bc82..c71f82252 100644
--- a/tests/zfs-tests/include/libtest.shlib
+++ b/tests/zfs-tests/include/libtest.shlib
@@ -3999,3 +3999,47 @@ function replay_directory_diff # dir_a dir_b
{
LIBTEST_DIFF_ZIL_REPLAY=1 directory_diff "$@"
}
+
+#
+# Put coredumps into $1/core.{basename}
+#
+# Output must be saved and passed to pop_coredump_pattern on cleanup
+#
+function push_coredump_pattern # dir
+{
+ ulimit -c unlimited
+ case $(uname) in
+ Linux)
+ cat /proc/sys/kernel/core_pattern /proc/sys/kernel/core_uses_pid
+ echo "$1/core.%e" >/proc/sys/kernel/core_pattern &&
+ echo 0 >/proc/sys/kernel/core_uses_pid
+ ;;
+ FreeBSD)
+ sysctl -n kern.corefile
+ sysctl kern.corefile="$1/core.%N" >/dev/null
+ ;;
+ *)
+ # Nothing to output – set only for this shell
+ coreadm -p "$1/core.%f"
+ ;;
+ esac
+}
+
+#
+# Put coredumps back into the default location
+#
+function pop_coredump_pattern
+{
+ [ -s "$1" ] || return 0
+ case $(uname) in
+ Linux)
+ typeset pat pid
+ { read -r pat; read -r pid; } < "$1"
+ echo "$pat" >/proc/sys/kernel/core_pattern &&
+ echo "$pid" >/proc/sys/kernel/core_uses_pid
+ ;;
+ FreeBSD)
+ sysctl kern.corefile="$(<"$1")" >/dev/null
+ ;;
+ esac
+}
diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs/zfs_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs/zfs_002_pos.ksh
index 796b38928..044ccb185 100755
--- a/tests/zfs-tests/tests/functional/cli_root/zfs/zfs_002_pos.ksh
+++ b/tests/zfs-tests/tests/functional/cli_root/zfs/zfs_002_pos.ksh
@@ -48,33 +48,23 @@ function cleanup
{
unset ZFS_ABORT
- if is_freebsd && [[ -n $savedcorefile ]]; then
- sysctl kern.corefile=$savedcorefile
- fi
+ log_must pop_coredump_pattern "$coresavepath"
- if [[ -d $corepath ]]; then
- rm -rf $corepath
- fi
for ds in $fs1 $fs $ctr; do
datasetexists $ds && destroy_dataset $ds -rRf
done
}
-log_assert "With ZFS_ABORT set, all zfs commands can abort and generate a " \
- "core file."
+log_assert "With ZFS_ABORT set, all zfs commands can abort and generate a core file."
log_onexit cleanup
+ctr=$TESTPOOL/$TESTCTR
+log_must zfs create -p $ctr
+
# Preparation work for testing
-savedcorefile=""
-corepath=$TESTDIR/core
+corepath=/$ctr
corefile=$corepath/core.zfs
-if [[ -d $corepath ]]; then
- rm -rf $corepath
-fi
-log_must mkdir $corepath
-
-ctr=$TESTPOOL/$TESTCTR
-log_must zfs create $ctr
+coresavepath=$corepath/save
fs=$ctr/$TESTFS
fs1=$ctr/$TESTFS1
@@ -93,24 +83,12 @@ typeset badparams=("" "create" "destroy" "snapshot" "rollback" "clone" \
"promote" "rename" "list -*" "set" "get -*" "inherit" "mount -A" \
"unmount" "share" "unshare" "send" "receive")
-if is_linux; then
- ulimit -c unlimited
- echo "$corefile" >/proc/sys/kernel/core_pattern
- echo 0 >/proc/sys/kernel/core_uses_pid
-elif is_freebsd; then
- ulimit -c unlimited
- savedcorefile=$(sysctl -n kern.corefile)
- log_must sysctl kern.corefile=$corepath/core.%N
-else
- log_must coreadm -p ${corepath}/core.%f
-fi
-
+log_must eval "push_coredump_pattern \"$corepath\" > \"$coresavepath\""
log_must export ZFS_ABORT=yes
for subcmd in "${cmds[@]}" "${badparams[@]}"; do
- log_mustnot eval "zfs $subcmd >/dev/null 2>&1"
- log_must rm $corefile
+ log_mustnot eval "zfs $subcmd"
+ log_must rm "$corefile"
done
-log_pass "With ZFS_ABORT set, zfs command can abort and generate core file " \
- "as expected."
+log_pass "With ZFS_ABORT set, zfs command can abort and generate core file as expected."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool/zpool_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool/zpool_002_pos.ksh
index e4ffa2a6c..ef88925dc 100755
--- a/tests/zfs-tests/tests/functional/cli_root/zpool/zpool_002_pos.ksh
+++ b/tests/zfs-tests/tests/functional/cli_root/zpool/zpool_002_pos.ksh
@@ -47,33 +47,27 @@ function cleanup
{
unset ZFS_ABORT
- if is_freebsd && [ -n "$old_corefile" ]; then
- sysctl kern.corefile=$old_corefile
- fi
+ log_must pop_coredump_pattern "$coresavepath"
+ log_must rm -rf $corepath $vdev1 $vdev2 $vdev3
# Clean up the pool created if we failed to abort.
poolexists $pool && destroy_pool $pool
-
- rm -rf $corepath $vdev1 $vdev2 $vdev3
}
log_assert "With ZFS_ABORT set, all zpool commands can abort and generate a core file."
log_onexit cleanup
corepath=$TESTDIR/core
-corefile=$corepath/zpool.core
-if [[ -d $corepath ]]; then
- log_must rm -rf $corepath
-fi
+corefile=$corepath/core.zpool
+coresavepath=$corepath/save
+log_must rm -rf $corepath
log_must mkdir $corepath
pool=pool.$$
vdev1=$TESTDIR/file1
vdev2=$TESTDIR/file2
vdev3=$TESTDIR/file3
-for vdev in $vdev1 $vdev2 $vdev3; do
- log_must mkfile $MINVDEVSIZE $vdev
-done
+log_must mkfile $MINVDEVSIZE $vdev1 $vdev2 $vdev3
set -A cmds "create $pool mirror $vdev1 $vdev2" "list $pool" "iostat $pool" \
"status $pool" "upgrade $pool" "get delegation $pool" "set delegation=off $pool" \
@@ -86,25 +80,12 @@ set -A badparams "" "create" "destroy" "add" "remove" "list *" "iostat" "status"
"online" "offline" "clear" "attach" "detach" "replace" "scrub" \
"import" "export" "upgrade" "history -?" "get" "set"
-if is_linux; then
- echo $corefile >/proc/sys/kernel/core_pattern
- echo 0 >/proc/sys/kernel/core_uses_pid
-elif is_freebsd; then
- old_corefile=$(sysctl -n kern.corefile)
- log_must sysctl kern.corefile=$corefile
-fi
-ulimit -c unlimited
-
-export ZFS_ABORT=yes
+log_must eval "push_coredump_pattern \"$corepath\" > \"$coresavepath\""
+log_must export ZFS_ABORT=yes
for subcmd in "${cmds[@]}" "${badparams[@]}"; do
- zpool $subcmd >/dev/null 2>&1
- if [[ ! -e $corefile ]]; then
- log_fail "zpool $subcmd cannot generate core file with ZFS_ABORT set."
- fi
- rm -f $corefile
+ log_mustnot eval "zpool $subcmd"
+ log_must rm "$corefile"
done
-unset ZFS_ABORT
-
log_pass "With ZFS_ABORT set, zpool command can abort and generate core file as expected."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool/zpool_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool/zpool_003_pos.ksh
index 6f15c09a5..00f24bdff 100755
--- a/tests/zfs-tests/tests/functional/cli_root/zpool/zpool_003_pos.ksh
+++ b/tests/zfs-tests/tests/functional/cli_root/zpool/zpool_003_pos.ksh
@@ -46,15 +46,12 @@ function cleanup
{
unset ZFS_ABORT
- if is_freebsd && [ -n "$old_corefile" ]; then
- sysctl kern.corefile=$old_corefile
- fi
-
- rm -rf $corepath
+ log_must pop_coredump_pattern "$coresavepath"
+ log_must rm -rf $corepath
# Don't leave the pool frozen.
- destroy_pool $TESTPOOL
- default_mirror_setup $DISKS
+ log_must destroy_pool $TESTPOOL
+ log_must default_mirror_setup $DISKS
}
verify_runnable "both"
@@ -63,15 +60,14 @@ log_assert "Debugging features of zpool should succeed."
log_onexit cleanup
corepath=$TESTDIR/core
-corefile=$corepath/zpool.core
-if [[ -d $corepath ]]; then
- log_must rm -rf $corepath
-fi
+corefile=$corepath/core.zpool
+coresavepath=$corepath/save
+log_must rm -rf $corepath
log_must mkdir $corepath
log_must eval "zpool -? >/dev/null 2>&1"
-if is_global_zone ; then
+if is_global_zone; then
log_must zpool freeze $TESTPOOL
else
log_mustnot zpool freeze $TESTPOOL
@@ -80,21 +76,10 @@ fi
log_mustnot zpool freeze fakepool
-if is_linux; then
- echo $corefile >/proc/sys/kernel/core_pattern
- echo 0 >/proc/sys/kernel/core_uses_pid
-elif is_freebsd; then
- old_corefile=$(sysctl -n kern.corefile)
- log_must sysctl kern.corefile=$corefile
-fi
-ulimit -c unlimited
-
-export ZFS_ABORT=yes
-
-zpool >/dev/null 2>&1
-
-unset ZFS_ABORT
+log_must eval "push_coredump_pattern \"$corepath\" > \"$coresavepath\""
+log_must export ZFS_ABORT=yes
-[[ -f $corefile ]] || log_fail "zpool did not dump core by request."
+log_mustnot eval "zpool >/dev/null 2>&1"
+log_must [ -f "$corefile" ]
log_pass "Debugging features of zpool succeed."