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