]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_009_neg.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / cli_root / zfs_receive / zfs_receive_009_neg.ksh
1 #!/bin/ksh -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 #
24 # Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
25 # Use is subject to license terms.
26 #
27
28 #
29 # Copyright (c) 2016 by Delphix. All rights reserved.
30 #
31
32 . $STF_SUITE/tests/functional/cli_root/cli_common.kshlib
33
34 #
35 # DESCRIPTION:
36 #       Verify 'zfs receive' fails with bad options, missing argument or too many
37 #       arguments.
38 #
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
43 #
44
45 verify_runnable "both"
46
47 function cleanup
48 {
49         typeset ds
50
51         if snapexists $snap; then
52                 log_must zfs destroy $snap
53         fi
54         for ds in $ctr1 $ctr2 $fs1; do
55                 if datasetexists $ds; then
56                         log_must zfs destroy -rf $ds
57                 fi
58         done
59         if [[ -d $TESTDIR2 ]]; then
60                 rm -rf $TESTDIR2
61         fi
62 }
63
64 log_assert "Verify 'zfs receive' fails with bad option, missing or too many arguments"
65 log_onexit cleanup
66
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"
70
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.$$
78
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
85 fi
86 log_must zfs create -o mountpoint=$TESTDIR2 $fs1
87 log_must zfs snapshot $snap
88 log_must eval "zfs send $snap > $bkup"
89
90 #Testing zfs receive fails with input from terminal
91 log_mustnot eval "zfs recv $fs3 </dev/console"
92
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"
97
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"
103         fi
104
105         (( i += 1 ))
106 done
107
108 # Testing with bad options
109 i=0
110 while (( i < ${#badopts[*]} ))
111 do
112         log_mustnot eval "zfs recv ${badopts[i]} $ctr1 < $bkup"
113         log_mustnot eval "zfs recv ${badopts[i]} $fs2 < $bkup"
114
115         (( i = i + 1 ))
116 done
117
118 log_pass "'zfs receive' as expected with bad options, missing or too many arguments."