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 2008 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29# ident	"@(#)zfs_send_004_neg.ksh	1.5	08/02/27 SMI"
30#
31
32. $STF_SUITE/tests/cli_root/cli_common.kshlib
33
34#################################################################################
35#
36# __stc_assertion_start
37#
38# ID: zfs_send_004_neg
39#
40# DESCRIPTION:
41#	Verify 'zfs send' fails with malformed parameters.
42#
43# STRATEGY:
44#	1. Define malformed parameters in array
45#	2. Feed the parameters to 'zfs send'
46#	3. Verify the result
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 f
63
64	for snap in $snap1 $snap2 $snap3; do
65		snapexists $snap && \
66			log_must $ZFS destroy -f $snap
67	done
68
69	for f in $tmpfile1 $tmpfile2; do
70		if [[ -e $f ]]; then
71			$RM -f $f
72		fi
73	done
74}
75
76fs=$TESTPOOL/$TESTFS
77snap1=$fs@snap1
78snap2=$fs@snap2
79snap3=$fs@snap3
80
81set -A badargs \
82	"" "$TESTPOOL" "$TESTFS" "$fs" "$fs@nonexisten_snap" "?" \
83	"$snap1/blah" "$snap1@blah" "-i" "-x" "-i $fs" \
84	"-x $snap1 $snap2" "-i $snap1" \
85	"-i $snap2 $snap1" "$snap1 $snap2" "-i $snap1 $snap2 $snap3" \
86	"-ii $snap1 $snap2" "-iii $snap1 $snap2" " -i $snap2 $snap1/blah" \
87	"-i $snap2/blah $snap1" \
88	"-i $snap2/blah $snap1/blah" \
89	"-i $snap1 blah@blah" \
90	"-i blah@blah $snap1" \
91	"-i $snap1 ${snap2##*@}" "-i $snap1 @${snap2##*@}" \
92	"-i ${snap1##*@} ${snap2##*@}" "-i @${snap1##*@} @${snap2##*@}" \
93	"-i ${snap1##*@} $snap2/blah" "-i @${snap1##*@} $snap2/blah" \
94	"-i @@${snap1##*@} $snap2" "-i $snap1 -i $snap1 $snap2" \
95	"-i snap1 snap2" "-i $snap1 snap2" \
96	"-i $snap1 $snap2 -i $snap1 $snap2" \
97	"-i snap1 $snap2 -i snap1 $snap2"
98
99log_assert "Verify that invalid parameters to 'zfs send' are caught."
100log_onexit cleanup
101
102log_must $ZFS snapshot $snap1
103tmpfile1=$TESTDIR/testfile1.${TESTCASE_ID}
104log_must $TOUCH $tmpfile1
105log_must $ZFS snapshot $snap2
106tmpfile2=$TESTDIR/testfile2.${TESTCASE_ID}
107log_must $TOUCH $tmpfile2
108log_must $ZFS snapshot $snap3
109
110typeset -i i=0
111while (( i < ${#badargs[*]} ))
112do
113	log_mustnot eval "$ZFS send ${badargs[i]} >/dev/null"
114
115	(( i = i + 1 ))
116done
117
118#Testing zfs send fails by send backup stream to terminal
119for arg in "$snap1" "-i $snap1 $snap2"; do
120	log_mustnot eval "$ZFS send $arg >/dev/console"
121done
122
123log_pass "Invalid parameters to 'zfs send' are caught as expected."
124