7290 ZFS test suite needs to control what utilities it can run
[unleashed.git] / usr / src / test / zfs-tests / tests / functional / cli_root / zfs_receive / zfs_receive_009_neg.ksh
blobd028acafada0adcce0e804bf6b714830927f69f6
1 #!/bin/ksh -p
3 # CDDL HEADER START
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.
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.
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]
20 # CDDL HEADER END
24 # Copyright 2007 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
29 # Copyright (c) 2016 by Delphix. All rights reserved.
32 . $STF_SUITE/tests/functional/cli_root/cli_common.kshlib
35 # DESCRIPTION:
36 # Verify 'zfs receive' fails with bad options, missing argument or too many
37 # arguments.
39 # STRATEGY:
40 # 1. Set a array of illegal arguments
41 # 2. Execute 'zfs receive' with illegal arguments
42 # 3. Verify the command should be failed
45 verify_runnable "both"
47 function cleanup
49 typeset ds
51 if snapexists $snap; then
52 log_must zfs destroy $snap
54 for ds in $ctr1 $ctr2 $fs1; do
55 if datasetexists $ds; then
56 log_must zfs destroy -rf $ds
58 done
59 if [[ -d $TESTDIR2 ]]; then
60 rm -rf $TESTDIR2
64 log_assert "Verify 'zfs receive' fails with bad option, missing or too many arguments"
65 log_onexit cleanup
67 set -A badopts "v" "n" "F" "d" "-V" "-N" "-f" "-D" "-VNfD" "-vNFd" "-vnFD" "-dVnF" \
68 "-vvvNfd" "-blah" "-12345" "-?" "-*" "-%"
69 set -A validopts "" "-v" "-n" "-F" "-vn" "-nF" "-vnF" "-vd" "-nd" "-Fd" "-vnFd"
71 ctr1=$TESTPOOL/$TESTCTR1
72 ctr2=$TESTPOOL/$TESTCTR2
73 fs1=$TESTPOOL/$TESTFS1
74 fs2=$TESTPOOL/$TESTFS2
75 fs3=$TESTPOOL/$TESTFS3
76 snap=$TESTPOOL/$TESTFS@$TESTSNAP
77 bkup=$TESTDIR2/bkup.$$
79 # Preparations for negative testing
80 for ctr in $ctr1 $ctr2; do
81 log_must zfs create $ctr
82 done
83 if [[ -d $TESTDIR2 ]]; then
84 rm -rf $TESTDIR2
86 log_must zfs create -o mountpoint=$TESTDIR2 $fs1
87 log_must zfs snapshot $snap
88 log_must eval "zfs send $snap > $bkup"
90 #Testing zfs receive fails with input from terminal
91 log_mustnot eval "zfs recv $fs3 </dev/console"
93 # Testing with missing argument and too many arguments
94 typeset -i i=0
95 while (( i < ${#validopts[*]} )); do
96 log_mustnot eval "zfs recv < $bkup"
98 echo ${validopts[i]} | grep "d" >/dev/null 2>&1
99 if (( $? != 0 )); then
100 log_mustnot eval "zfs recv ${validopts[i]} $fs2 $fs3 < $bkup"
101 else
102 log_mustnot eval "zfs recv ${validopts[i]} $ctr1 $ctr2 < $bkup"
105 (( i += 1 ))
106 done
108 # Testing with bad options
110 while (( i < ${#badopts[*]} ))
112 log_mustnot eval "zfs recv ${badopts[i]} $ctr1 < $bkup"
113 log_mustnot eval "zfs recv ${badopts[i]} $fs2 < $bkup"
115 (( i = i + 1 ))
116 done
118 log_pass "'zfs receive' as expected with bad options, missing or too many arguments."