1 #
   2 # CDDL HEADER START
   3 #
   4 # The contents of this file are subject to the terms of the
   5 # Common Development and Distribution License (the "License").
   6 # You may not use this file except in compliance with the License.
   7 #
   8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9 # or http://www.opensolaris.org/os/licensing.
  10 # See the License for the specific language governing permissions
  11 # and limitations under the License.
  12 #
  13 # When distributing Covered Code, include this CDDL HEADER in each
  14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15 # If applicable, add the following below this CDDL HEADER, with the
  16 # fields enclosed by brackets "[]" replaced with your own identifying
  17 # information: Portions Copyright [yyyy] [name of copyright owner]
  18 #
  19 # CDDL HEADER END
  20 #
  21 
  22 #
  23 # Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  24 # Use is subject to license terms.
  25 #
  26 # NFSv4 WRITE operation test - negative tests
  27 #       verify SERVER errors returned with invalid write.
  28 
  29 # include all test enironment
  30 source WRITE.env
  31 
  32 # connect to the test server
  33 Connect
  34 
  35 # setting local variables
  36 set TNAME $argv0
  37 set bfh [get_fh "$BASEDIRS"]
  38 
  39 
  40 # Start testing
  41 # --------------------------------------------------------------
  42 # a: Write a file w/an bad stateid (not from Open) - 
  43 #       expect BAD_STATEID|STALE_STATEID
  44 #
  45 set expcode "BAD_STATEID|STALE_STATEID"
  46 set ASSERTION "Write w/bad stateid (not from Open), expect $expcode"
  47 set tag "$TNAME{a}"
  48 putmsg stdout 0 "$tag: $ASSERTION"
  49 set stateid {12345 67890}
  50 set res [compound {Putfh $bfh; Lookup $env(RWFILE); 
  51         Write $stateid 0 u a "Write test neg02 \{a\}"}]
  52 ckres "Write" $status $expcode $res $PASS
  53 
  54 # Open a file for a valid stateid, then check for errors:
  55 set TRes 0
  56 set tfile "$TNAME.[pid]"
  57 set owner "[expr int([expr [expr rand()] * 100000000])]"
  58 set cid [getclientid $owner]
  59 if {$cid == -1} {
  60     set TRes 1
  61 } else {
  62     set otype 1
  63     set nfh [basic_open $bfh $tfile $otype "$cid $owner" open_sid oseqid status]
  64     if {$nfh == -1} {
  65         set TRes 2
  66     }
  67 }
  68 
  69 # Now do negative WRITE testing:
  70 if {$TRes == 0} {
  71     incr oseqid
  72     putmsg stderr 1  "  open_sid from OPEN = ($open_sid)"
  73     # b: Write a file with an invalid stateid (seqid+1) - expect BAD_STATEID
  74     #
  75     set expcode "BAD_STATEID"
  76     set ASSERTION "Write w/invalid stateid (seqid+1), expect $expcode"
  77     set tag "$TNAME{b}"
  78     putmsg stdout 0 "$tag: $ASSERTION"
  79     set bseqid [expr [lindex $open_sid 0] + 1]
  80     set bopen_sid "$bseqid [lindex $open_sid 1]"
  81     putmsg stderr 1 "  new open_sid with trashed seqid: bopen_sid=($bopen_sid)"
  82     set rres [compound {Putfh $nfh; 
  83         Write "$bopen_sid" 1 d a "Write test neg02 \{b\}"}]
  84     ckres "Write" $status $expcode $rres $PASS
  85 
  86     # c: Write a file with an invalid stateid (trash-other) - 
  87     #   expect BAD_STATEID|STALE_STATEID
  88     #
  89     set expcode "BAD_STATEID|STALE_STATEID"
  90     set ASSERTION "Write w/invalid stateid (trash-other), expect $expcode"
  91     set tag "$TNAME{c}"
  92     putmsg stdout 0 "$tag: $ASSERTION"
  93     set newS ""
  94     set oldS [lindex $open_sid 1]
  95     set l [string length $oldS]
  96     for {set i 0} {$i < $l} {incr i} {
  97         append newS [string index $oldS end-$i]
  98     }
  99     set copen_sid "[lindex $open_sid 0] $newS"
 100     putmsg stderr 1 "  new open_sid with trashed other: copen_sid=($copen_sid)"
 101     set rres [compound {Putfh $nfh; 
 102         Write "$copen_sid" 1 d a "Write test neg02 \{c\}"}]
 103     ckres "Write" $status $expcode $rres $PASS
 104 
 105     # d: Write a locked file with an open_stateid - expect OK
 106     #
 107     set expcode "OK"
 108     set ASSERTION "Write a locked file w/open stateid, expect $expcode"
 109     set tag "$TNAME{d}"
 110     putmsg stdout 0 "$tag: $ASSERTION"
 111     set lseqid 1
 112     set res [compound {Putfh $nfh; 
 113             Lock 2 F 2 10 T $open_sid $lseqid {$oseqid $cid $owner}}]
 114     incr oseqid
 115     if {$status != "OK"} {
 116         set TRes 3
 117     }
 118     set rres [compound {Putfh $nfh;  
 119             Write "$open_sid" 0 f a "Write test neg02 \{d\}"}]
 120     ckres "Write" $status $expcode $rres $PASS
 121     if {$TRes != 3} {
 122         # Unlock the lock for the Close next
 123         set lock_sid [lindex [lindex $res 1] 2]
 124         incr lseqid
 125         set rres [compound {Putfh $nfh;  Locku 2 $lseqid $lock_sid 2 10}]
 126     }
 127 
 128     # e: Write w/open_stateid from a wrong file - expect BAD_STATEID
 129     #
 130     set expcode "BAD_STATEID"
 131     set ASSERTION "Write w/open_stateid from wrong file, expect $expcode"
 132     set tag "$TNAME{e}"
 133     putmsg stdout 0 "$tag: $ASSERTION"
 134     set tfh [basic_open $bfh $env(RWFILE) 0 "$cid $owner" osid2 oseqid2 \
 135                                 status "$oseqid"]
 136     if {$tfh == -1} {
 137         putmsg stderr 0 "\t Test FAIL: basic_open2 failed on $env(RWFILE)"
 138     } else {
 139         incr oseqid2
 140         set rres [compound {Putfh $nfh; 
 141                 Write "$osid2" 0 d a "Write test neg02 \{e\}"}]
 142         ckres "Write" $status $expcode $rres $PASS
 143     }
 144 
 145 } elseif {$TRes == 1} {
 146     putmsg stdout 0 "$TNAME: test setup"
 147     putmsg stderr 0 "\t Test UNRESOLVED: Open failed"
 148     putmsg stdout 0 "\t   tests are not run.\n"
 149 } elseif {$TRes == 2} {
 150     putmsg stdout 0 "$TNAME: test setup"
 151     putmsg stderr 0 "\t Test UNRESOLVED: Open_confirm failed"
 152     putmsg stdout 0 "\t   tests are not run.\n"
 153 } elseif {$TRes == 3} {
 154     putmsg stdout 0 "$TNAME: test setup"
 155     putmsg stderr 0 "\t Test UNRESOLVED: Lock failed"
 156     putmsg stdout 0 "\t   tests are not run.\n"
 157 }
 158 
 159 # finally close the file:
 160 set res [compound {Putfh $nfh; Close $oseqid2 $open_sid}]
 161   putmsg stdout 2 "\nClose $oseqid $open_sid ... "
 162   putmsg stdout 2 "Res: $res"
 163 
 164 # f: Write w/open_stateid from a closed file - expect BAD_STATEID|OLD_STATEID
 165 #
 166 set expcode "BAD_STATEID|OLD_STATEID"
 167 set ASSERTION "Writew/open_stateid from closed file, expect $expcode"
 168 set tag "$TNAME{f}"
 169 putmsg stdout 0 "$tag: $ASSERTION"
 170 set res [compound {Putfh $nfh; 
 171         Write "$open_sid" 0 f a "Write test neg02 \{f\}"}]
 172 ckres "Write" $status $expcode $rres $PASS
 173 
 174 
 175 # --------------------------------------------------------------
 176 # Cleanup the temp file:
 177 set res [compound {Putfh $bfh; Remove $tfile}]
 178 if { "$status" != "OK" } {
 179         putmsg stderr 0 "\t WARNING: cleanup to remove $tfile failed"
 180         putmsg stderr 0 "\t          status=$status; please cleanup manually."
 181         putmsg stderr 1 "\t   res=($res)"
 182         putmsg stderr 1 "  "
 183         exit $WARNING
 184 }
 185 
 186 # disconnect and exit
 187 Disconnect
 188 exit $PASS