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	"@(#)zfs_002_pos.ksh	1.3	09/06/22 SMI"
30#
31. $STF_SUITE/include/libtest.kshlib
32. $STF_SUITE/tests/userquota/userquota_common.kshlib
33
34################################################################################
35#
36# __stc_assertion_start
37#
38# ID: zfs_002_pos
39#
40# DESCRIPTION:
41# With ZFS_ABORT set, all zfs commands should be able to abort and generate a core file.
42#
43# STRATEGY:
44# 1. Create an array of zfs command
45# 2. Execute each command in the array
46# 3. Verify the command aborts and generate a core file
47#
48# TESTABILITY: explicit
49#
50# TEST_AUTOMATION_LEVEL: automated
51#
52# CODING_STATUS: COMPLETED (2007-06-29)
53#
54# __stc_assertion_end
55#
56################################################################################
57
58verify_runnable "both"
59
60function cleanup
61{
62	unset ZFS_ABORT
63
64	if [[ -d $corepath ]]; then
65		$RM -rf $corepath
66	fi
67	for ds in $fs1 $fs $ctr; do
68		if datasetexists $ds; then
69			log_must $ZFS destroy -rRf $ds
70		fi
71	done
72}
73
74log_assert "With ZFS_ABORT set, all zfs commands can abort and generate a core file."
75log_onexit cleanup
76
77#preparation work for testing
78corepath=$TESTDIR/core
79if [[ -d $corepath ]]; then
80	$RM -rf $corepath
81fi
82log_must $MKDIR $corepath
83
84ctr=$TESTPOOL/$TESTCTR
85log_must $ZFS create $ctr
86
87fs=$ctr/$TESTFS
88fs1=$ctr/$TESTFS1
89snap=$fs@$TESTSNAP
90clone=$ctr/$TESTCLONE
91streamf=$corepath/s.${TESTCASE_ID}
92
93set -A cmds "create $fs" "list $fs" "snapshot $snap" "set snapdir=hidden $fs" \
94	    "get snapdir $fs" "rollback $snap" "inherit snapdir $fs" \
95	    "rename $fs $fs-new" "rename $fs-new $fs" "unmount $fs" \
96	    "mount $fs" "share $fs" "unshare $fs" "send $snap \>$streamf" \
97	    "receive $fs1 \<$streamf" "clone $snap $clone" "promote $clone" \
98	    "promote $fs" "destroy -rRf $fs"
99
100set -A badparams "" "create" "destroy" "snapshot" "rollback" "clone" "promote" "rename" \
101		"list -*" "set" "get -*" "inherit" "mount -A" "unmount" "share" \
102		"unshare" "send" "receive"
103
104if ! is_userquota_supported; then
105	typeset -i i=${cmds[#]}
106	cmds[i]="allow everyone snapshot $fs"
107	cmds[((i+1))]="unallow everyone snapshot $fs"
108
109	i=${badparams[#]}
110	badparams[i]="allow"
111	badparams[((i+1))]="unallow"
112fi
113
114
115log_must $COREADM -p ${corepath}/core.%f
116log_must export ZFS_ABORT=yes
117
118for subcmd in "${cmds[@]}" "${badparams[@]}"; do
119	log_mustnot $ZFS $subcmd
120	corefile=${corepath}/core.zfs
121	if [[ ! -e $corefile ]]; then
122		log_fail "$ZFS $subcmd cannot generate core file  with ZFS_ABORT set."
123	fi
124	log_must $RM -f $corefile
125done
126
127log_pass "With ZFS_ABORT set, zfs command can abort and generate core file as expected."
128