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 2007 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29# ident	"@(#)zfs_receive_004_neg.ksh	1.4	07/10/09 SMI"
30#
31
32. $STF_SUITE/tests/cli_root/cli_common.kshlib
33
34#################################################################################
35#
36# __stc_assertion_start
37#
38# ID: zfs_receive_004_neg
39#
40# DESCRIPTION:
41#	Verify 'zfs receive' fails with malformed parameters.
42#
43# STRATEGY:
44#	1. Denfine malformed parameters array
45#	2. Feed the malformed parameters to 'zfs receive'
46#	3. Verify the command should be failed
47#
48# TESTABILITY: explicit
49#
50# TEST_AUTOMATION_LEVEL: automated
51#
52# CODING_STATUS: COMPLETED (2005-09-06)
53#
54# __stc_assertion_end
55#
56################################################################################
57
58verify_runnable "both"
59
60function cleanup
61{
62	typeset snap
63	typeset bkup
64
65	for snap in $init_snap $inc_snap $init_topsnap $inc_topsnap ; do
66		snapexists $snap && \
67			log_must $ZFS destroy -Rf $snap
68	done
69
70	for bkup in $full_bkup $inc_bkup $full_topbkup $inc_topbkup; do
71		[[ -e $bkup ]] && \
72			log_must $RM -f $bkup
73	done
74}
75
76log_assert "Verify that invalid parameters to 'zfs receive' are caught."
77log_onexit cleanup
78
79init_snap=$TESTPOOL/$TESTFS@initsnap
80inc_snap=$TESTPOOL/$TESTFS@incsnap
81full_bkup=$TMPDIR/full_bkup.${TESTCASE_ID}
82inc_bkup=$TMPDIR/inc_bkup.${TESTCASE_ID}
83
84init_topsnap=$TESTPOOL@initsnap
85inc_topsnap=$TESTPOOL@incsnap
86full_topbkup=$TMPDIR/full_topbkup.${TESTCASE_ID}
87inc_topbkup=$TMPDIR/inc_topbkup.${TESTCASE_ID}
88
89log_must $ZFS snapshot $init_topsnap
90log_must eval "$ZFS send $init_topsnap > $full_topbkup"
91
92log_must $ZFS snapshot $inc_topsnap
93log_must eval "$ZFS send -i $init_topsnap $inc_topsnap > $inc_topbkup"
94
95log_must $ZFS snapshot $init_snap
96log_must eval "$ZFS send $init_snap > $full_bkup"
97
98log_must $ZFS snapshot $inc_snap
99log_must eval "$ZFS send -i $init_snap $inc_snap > $inc_bkup"
100
101set -A badargs \
102	"" "nonexistent-snap" "blah@blah" "$snap1" "$snap1 $snap2" \
103	"-d" "-d nonexistent-dataset" \
104	"$TESTPOOL/fs@" "$TESTPOOL/fs@@mysnap" "$TESTPOOL/fs@@" \
105	"$TESTPOOL/fs/@mysnap" "$TESTPOOL/fs@/mysnap" \
106	"$TESTPOOL/nonexistent-fs/nonexistent-fs" \
107	"-d $TESTPOOL/nonexistent-fs" "-d $TESTPOOL/$TESTFS/nonexistent-fs"
108
109typeset -i i=0
110while (( i < ${#badargs[*]} ))
111do
112	for bkup in $full_bkup $inc_bkup $full_topbkup $inc_topbkup ; do
113		log_mustnot eval "$ZFS receive ${badargs[i]} < $bkup"
114	done
115
116	(( i = i + 1 ))
117done
118
119log_pass "Invalid parameters to 'zfs receive' are caught as expected."
120