1#!/usr/local/bin/ksh93 -p
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22
23# $FreeBSD$
24
25#
26# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29# ident	"@(#)zpool_002_pos.ksh	1.2	09/01/12 SMI"
30#
31. $STF_SUITE/include/libtest.kshlib
32
33################################################################################
34#
35# __stc_assertion_start
36#
37# ID: zpool_002_pos
38#
39# DESCRIPTION:
40# With ZFS_ABORT set, all zpool commands should be able to abort and generate a core file.
41#
42# STRATEGY:
43# 1. Create an array of zpool command
44# 2. Execute each command in the array
45# 3. Verify the command aborts and generate a core file
46#
47# TESTABILITY: explicit
48#
49# TEST_AUTOMATION_LEVEL: automated
50#
51# CODING_STATUS: COMPLETED (2007-06-29)
52#
53# __stc_assertion_end
54#
55################################################################################
56
57verify_runnable "global"
58
59function cleanup
60{
61	unset ZFS_ABORT
62
63	if [[ -d $corepath ]]; then
64		$RM -rf $corepath
65	fi
66	if poolexists $pool; then
67		log_must $ZPOOL destroy -f $pool
68	fi
69}
70
71log_assert "With ZFS_ABORT set, all zpool commands can abort and generate a core file."
72log_onexit cleanup
73
74#preparation work for testing
75corepath=$TESTDIR/core
76if [[ -d $corepath ]]; then
77	$RM -rf $corepath
78fi
79$MKDIR $corepath
80
81pool=pool.${TESTCASE_ID}
82vdev1=$TESTDIR/file1
83vdev2=$TESTDIR/file2
84vdev3=$TESTDIR/file3
85log_must create_vdevs $vdev1 $vdev2 $vdev3
86
87set -A cmds "create $pool mirror $vdev1 $vdev2" "list $pool" "iostat $pool" \
88	"status $pool" "upgrade $pool" "get delegation $pool" "set delegation=off $pool" \
89	"export $pool" "import -d $TESTDIR $pool" "offline $pool $vdev1" \
90	"online $pool $vdev1" "clear $pool" "detach $pool $vdev2" \
91	"attach $pool $vdev1 $vdev2" "replace $pool $vdev2 $vdev3" \
92	"scrub $pool" "destroy -f $pool"
93
94set -A badparams "" "create" "destroy" "add" "remove" "list *" "iostat" "status" \
95		"online" "offline" "clear" "attach" "detach" "replace" "scrub" \
96		"import" "export" "upgrade" "history -?" "get" "set"
97
98$COREADM -p ${corepath}/core.%f
99export ZFS_ABORT=yes
100
101for subcmd in "${cmds[@]}" "${badparams[@]}"; do
102	$ZPOOL $subcmd >/dev/null 2>&1
103	corefile=${corepath}/core.zpool
104	if [[ ! -e $corefile ]]; then
105		log_fail "$ZPOOL $subcmd cannot generate core file  with ZFS_ABORT set."
106	fi
107	$RM -f $corefile
108done
109
110log_pass "With ZFS_ABORT set, zpool command can abort and generate core file as expected."
111