Skip to content

Commit 0ccffb2

Browse files
Ryan Moellertonyhutter
authored andcommitted
ZTS: Improve cleanup in zpool tests
* Restore original kern.corefile value after the test. * Don't leave behind a frozen pool. * Clean up leftover vdev files. * Make zpool_002_pos and zpool_003_pos consistent in their handling of core files while here. Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Ryan Moeller <[email protected]> Closes #11694
1 parent 26cb87d commit 0ccffb2

File tree

2 files changed

+43
-33
lines changed

2 files changed

+43
-33
lines changed

tests/zfs-tests/tests/functional/cli_root/zpool/zpool_002_pos.ksh

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,31 +47,32 @@ function cleanup
4747
{
4848
unset ZFS_ABORT
4949

50-
if [[ -d $corepath ]]; then
51-
rm -rf $corepath
50+
if is_freebsd && [ -n "$old_corefile" ]; then
51+
sysctl kern.corefile=$old_corefile
5252
fi
5353

54-
if poolexists $pool; then
55-
log_must zpool destroy -f $pool
56-
fi
54+
# Clean up the pool created if we failed to abort.
55+
poolexists $pool && destroy_pool $pool
56+
57+
rm -rf $corepath $vdev1 $vdev2 $vdev3
5758
}
5859

5960
log_assert "With ZFS_ABORT set, all zpool commands can abort and generate a core file."
6061
log_onexit cleanup
6162

62-
#preparation work for testing
6363
corepath=$TESTDIR/core
64+
corefile=$corepath/zpool.core
6465
if [[ -d $corepath ]]; then
65-
rm -rf $corepath
66+
log_must rm -rf $corepath
6667
fi
67-
mkdir $corepath
68+
log_must mkdir $corepath
6869

6970
pool=pool.$$
7071
vdev1=$TESTDIR/file1
7172
vdev2=$TESTDIR/file2
7273
vdev3=$TESTDIR/file3
7374
for vdev in $vdev1 $vdev2 $vdev3; do
74-
mkfile $MINVDEVSIZE $vdev
75+
log_must mkfile $MINVDEVSIZE $vdev
7576
done
7677

7778
set -A cmds "create $pool mirror $vdev1 $vdev2" "list $pool" "iostat $pool" \
@@ -86,27 +87,25 @@ set -A badparams "" "create" "destroy" "add" "remove" "list *" "iostat" "status"
8687
"import" "export" "upgrade" "history -?" "get" "set"
8788

8889
if is_linux; then
89-
ulimit -c unlimited
90-
echo "$corepath/core.zpool" >/proc/sys/kernel/core_pattern
90+
echo $corefile >/proc/sys/kernel/core_pattern
9191
echo 0 >/proc/sys/kernel/core_uses_pid
92-
export ASAN_OPTIONS="abort_on_error=1:disable_coredump=0"
9392
elif is_freebsd; then
94-
ulimit -c unlimited
95-
log_must sysctl kern.corefile=$corepath/core.zpool
96-
export ASAN_OPTIONS="abort_on_error=1:disable_coredump=0"
97-
else
98-
coreadm -p ${corepath}/core.%f
93+
old_corefile=$(sysctl -n kern.corefile)
94+
log_must sysctl kern.corefile=$corefile
9995
fi
96+
ulimit -c unlimited
10097

98+
export ASAN_OPTIONS="abort_on_error=1:disable_coredump=0"
10199
export ZFS_ABORT=yes
102100

103101
for subcmd in "${cmds[@]}" "${badparams[@]}"; do
104-
corefile=${corepath}/core.zpool
105102
zpool $subcmd >/dev/null 2>&1
106103
if [[ ! -e $corefile ]]; then
107-
log_fail "zpool $subcmd cannot generate core file with ZFS_ABORT set."
104+
log_fail "zpool $subcmd cannot generate core file with ZFS_ABORT set."
108105
fi
109106
rm -f $corefile
110107
done
111108

109+
unset ZFS_ABORT
110+
112111
log_pass "With ZFS_ABORT set, zpool command can abort and generate core file as expected."

tests/zfs-tests/tests/functional/cli_root/zpool/zpool_003_pos.ksh

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,32 @@
4444

4545
function cleanup
4646
{
47+
unset ZFS_ABORT
48+
4749
if is_freebsd && [ -n "$old_corefile" ]; then
4850
sysctl kern.corefile=$old_corefile
4951
fi
52+
53+
rm -rf $corepath
54+
55+
# Don't leave the pool frozen.
56+
destroy_pool $TESTPOOL
57+
default_mirror_setup $DISKS
5058
}
5159

5260
verify_runnable "both"
5361

5462
log_assert "Debugging features of zpool should succeed."
5563
log_onexit cleanup
5664

57-
log_must zpool -? > /dev/null 2>&1
65+
corepath=$TESTDIR/core
66+
corefile=$corepath/zpool.core
67+
if [[ -d $corepath ]]; then
68+
log_must rm -rf $corepath
69+
fi
70+
log_must mkdir $corepath
71+
72+
log_must eval "zpool -? >/dev/null 2>&1"
5873

5974
if is_global_zone ; then
6075
log_must zpool freeze $TESTPOOL
@@ -65,26 +80,22 @@ fi
6580

6681
log_mustnot zpool freeze fakepool
6782

68-
# Remove corefile possibly left by previous failing run of this test.
69-
[[ -f core ]] && log_must rm -f core
70-
7183
if is_linux; then
72-
ulimit -c unlimited
73-
echo "core" >/proc/sys/kernel/core_pattern
84+
echo $corefile >/proc/sys/kernel/core_pattern
7485
echo 0 >/proc/sys/kernel/core_uses_pid
75-
export ASAN_OPTIONS="abort_on_error=1:disable_coredump=0"
7686
elif is_freebsd; then
77-
ulimit -c unlimited
7887
old_corefile=$(sysctl -n kern.corefile)
79-
log_must sysctl kern.corefile=core
80-
export ASAN_OPTIONS="abort_on_error=1:disable_coredump=0"
88+
log_must sysctl kern.corefile=$corefile
8189
fi
90+
ulimit -c unlimited
91+
92+
export ASAN_OPTIONS="abort_on_error=1:disable_coredump=0"
93+
export ZFS_ABORT=yes
94+
95+
zpool >/dev/null 2>&1
8296

83-
ZFS_ABORT=1; export ZFS_ABORT
84-
zpool > /dev/null 2>&1
8597
unset ZFS_ABORT
8698

87-
[[ -f core ]] || log_fail "zpool did not dump core by request."
88-
[[ -f core ]] && log_must rm -f core
99+
[[ -f $corefile ]] || log_fail "zpool did not dump core by request."
89100

90101
log_pass "Debugging features of zpool succeed."

0 commit comments

Comments
 (0)