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. $STF_SUITE/tests/functional/cli_root/cli_common.kshlib 29 30# 31# DESCRIPTION: 32# Verify 'zfs receive' fails with bad options, missing argument or too many 33# arguments. 34# 35# STRATEGY: 36# 1. Set a array of illegal arguments 37# 2. Execute 'zfs receive' with illegal arguments 38# 3. Verify the command should be failed 39# 40 41verify_runnable "both" 42 43function cleanup 44{ 45 typeset ds 46 47 if snapexists $snap; then 48 log_must $ZFS destroy $snap 49 fi 50 for ds in $ctr1 $ctr2 $fs1; do 51 if datasetexists $ds; then 52 log_must $ZFS destroy -rf $ds 53 fi 54 done 55 if [[ -d $TESTDIR2 ]]; then 56 $RM -rf $TESTDIR2 57 fi 58} 59 60log_assert "Verify 'zfs receive' fails with bad option, missing or too many arguments" 61log_onexit cleanup 62 63set -A badopts "v" "n" "F" "d" "-V" "-N" "-f" "-D" "-VNfD" "-vNFd" "-vnFD" "-dVnF" \ 64 "-vvvNfd" "-blah" "-12345" "-?" "-*" "-%" 65set -A validopts "" "-v" "-n" "-F" "-vn" "-nF" "-vnF" "-vd" "-nd" "-Fd" "-vnFd" 66 67ctr1=$TESTPOOL/$TESTCTR1 68ctr2=$TESTPOOL/$TESTCTR2 69fs1=$TESTPOOL/$TESTFS1 70fs2=$TESTPOOL/$TESTFS2 71fs3=$TESTPOOL/$TESTFS3 72snap=$TESTPOOL/$TESTFS@$TESTSNAP 73bkup=$TESTDIR2/bkup.$$ 74 75# Preparations for negative testing 76for ctr in $ctr1 $ctr2; do 77 log_must $ZFS create $ctr 78done 79if [[ -d $TESTDIR2 ]]; then 80 $RM -rf $TESTDIR2 81fi 82log_must $ZFS create -o mountpoint=$TESTDIR2 $fs1 83log_must $ZFS snapshot $snap 84log_must eval "$ZFS send $snap > $bkup" 85 86#Testing zfs receive fails with input from terminal 87log_mustnot eval "$ZFS recv $fs3 </dev/console" 88 89# Testing with missing argument and too many arguments 90typeset -i i=0 91while (( i < ${#validopts[*]} )); do 92 log_mustnot eval "$ZFS recv < $bkup" 93 94 $ECHO ${validopts[i]} | $GREP "d" >/dev/null 2>&1 95 if (( $? != 0 )); then 96 log_mustnot eval "$ZFS recv ${validopts[i]} $fs2 $fs3 < $bkup" 97 else 98 log_mustnot eval "$ZFS recv ${validopts[i]} $ctr1 $ctr2 < $bkup" 99 fi 100 101 (( i += 1 )) 102done 103 104# Testing with bad options 105i=0 106while (( i < ${#badopts[*]} )) 107do 108 log_mustnot eval "$ZFS recv ${badopts[i]} $ctr1 < $bkup" 109 log_mustnot eval "$ZFS recv ${badopts[i]} $fs2 < $bkup" 110 111 (( i = i + 1 )) 112done 113 114log_pass "'zfs receive' as expected with bad options, missing or too many arguments." 115