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 LOCK, LOCKT, LOCKU operation test - negative tests
  27 #       Verify server returns correct errors with negative requests.
  28 
  29 # include all test enironment
  30 source LOCKsid.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 set hid "[pid]-[expr int([expr [expr rand()] * 100000000])]"
  39 set cid [getclientid $hid]
  40 if {$cid == -1} {
  41         putmsg stdout 0 "$TNAME: test setup - getclientid"
  42         putmsg stderr 0 "\t Test UNRESOLVED: unable to get clientid"
  43         exit $UNRESOLVED
  44 }
  45 set seqid 1
  46 
  47 # Create a temp test file and get it's filehandle
  48 set TFILE "$TNAME.[pid]"
  49 set fsize 999
  50 set open_owner $TFILE
  51 set nfh [basic_open $bfh $TFILE 1 "$cid $open_owner" \
  52         osid oseqid status $seqid 0 666 $fsize]
  53 if {$nfh == -1} {
  54         putmsg stdout 0 "$TNAME: test setup - getclientid"
  55         putmsg stderr 0 "\t Test UNRESOLVED: failed to create tmp file=($TFILE)"
  56         putmsg stderr 0 "\t\t basic_open failed, status=($status)."
  57         exit $UNRESOLVED
  58 }
  59 incr oseqid
  60 putmsg stderr 1 "  Good osid=($osid)"
  61 
  62 # Set a lock(R) in file for testing
  63 set lowner "[pid].lo"
  64 set lseqid 1
  65 set res [compound {Putfh $nfh; 
  66         Lock 1 F 0 $fsize T $osid $lseqid "$oseqid $cid $lowner"}]
  67 if { $status != "OK" } {
  68         putmsg stdout 0 "$TNAME: test setup - set a Read-lock"
  69         putmsg stderr 0 "\t Test UNRESOLVED: Lock() returned status=$(status)"
  70         putmsg stderr 1 "\t\t  Res=($res)"
  71         exit $UNRESOLVED
  72 }
  73 set lsid_good [lindex [lindex $res 1] 2]
  74 
  75 # Start testing
  76 # --------------------------------------------------------------
  77 # a: Resend the LOCK(R), server should see it as dup, expect OK
  78 set expcode "OK"
  79 set ASSERTION "Resend the LOCK(R), server should see it as dup, expect $expcode"
  80 set tag "$TNAME{a}"
  81 putmsg stdout 0 "$tag: $ASSERTION"
  82 set res [compound {Putfh $nfh; 
  83         Lock 1 F 0 $fsize T $osid $lseqid "$oseqid $cid $lowner"}]
  84 if { [string first "BAD" $status] == -1} {
  85         incr oseqid
  86         incr lseqid
  87 }       
  88 if { [ckres "Lock(R)" $status $expcode $res $FAIL] == "true" } {
  89         set lsid [lindex [lindex $res 1] 2]
  90         if { "$lsid_good" != "$lsid" } {
  91                 putmsg stderr 0 "\t Test FAIL: lock_sid different on dup"
  92                 putmsg stderr 0 "\t\t  lsid_good=($lsid_good), lsid=($lsid)"
  93         } else {
  94                 logres "PASS"
  95                 putmsg stderr 1 "  Good lsid=($lsid)"
  96         }
  97 } else {
  98         set lsid $lsid_good
  99 }
 100 
 101 # a1: Resend the LOCK(R)w/new lockowner, server should see it as dup, expect OK
 102 set expcode "OK"
 103 set ASSERTION \
 104         "Resend the LOCK(R) w/new lockowner, server should see it as dup,"
 105 set ASSERTION "$ASSERTION expect $expcode"
 106 set tag "$TNAME{a1}"
 107 putmsg stdout 0 "$tag: $ASSERTION"
 108 set res [compound {Putfh $nfh;
 109         Lock 1 F 0 $fsize F $lsid $lseqid "oseqid clientid lowner"}]
 110 if { [string first "BAD" $status] == -1} {
 111         incr oseqid
 112         incr lseqid
 113 }       
 114 if { [ckres "Lock(R)" $status $expcode $res $FAIL] == "true" } {
 115         set lsid [lindex [lindex $res 1] 2]
 116         set tmp_lsid "[expr [lindex $lsid_good 0] + 1] [lindex $lsid_good 1]"
 117         if { "$tmp_lsid" != "$lsid" } {
 118                 putmsg stderr 0 \
 119                         "\t Test FAIL: lock_sid different on dup w/new lowner"
 120                 putmsg stderr 0 "\t\t  expt_lsid=($tmp_lsid), lsid=($lsid)"
 121         } else {
 122                 set lsid_new $lsid
 123                 logres "PASS"
 124                 putmsg stderr 1 "  Good lsid=($lsid) new lsid=($lsid_new)"
 125         }
 126 } else {
 127         set lsid $lsid_good
 128 }
 129 
 130 
 131 # b: new Lock w/bad open_seqid (0), expect BAD_SEQID
 132 set expcode "BAD_SEQID"
 133 set bseq 0
 134 set ASSERTION "new Lock w/bad open_oseqid ($bseq), expect $expcode"
 135 set tag "$TNAME{b}"
 136 putmsg stdout 0 "$tag: $ASSERTION"
 137 set res [compound {Putfh $nfh; 
 138         Lock 2 F 1024 10 T $osid 1 "$bseq $cid $lowner"}]
 139 ckres "Lock" $status $expcode $res $PASS
 140 
 141 # c: Lock(R) w/same lowner, but bad_lseqid(0), expect BAD_SEQID
 142 set expcode "BAD_SEQID"
 143 set bseq 0 
 144 set ASSERTION "Lock(R) same lowner, but bad_lseqid($bseq), expect $expcode"
 145 set tag "$TNAME{c}"
 146 putmsg stdout 0 "$tag: $ASSERTION"
 147 set res [compound {Putfh $nfh; 
 148         Lock 1 F 10 20 F $lsid $bseq "$oseqid $cid $lowner"}]
 149 ckres "Lock" $status $expcode $res $PASS
 150 
 151 # d: Locku(R,10,20) w/same lowner, but bad_lseqid, expect BAD_SEQID
 152 set expcode "BAD_SEQID"
 153 set bseq 0
 154 set ASSERTION "Locku(R,10,20) w/bad_lseqid($bseq), expect $expcode"
 155 set tag "$TNAME{d}"
 156 putmsg stdout 0 "$tag: $ASSERTION"
 157 set res [compound {Putfh $nfh; Locku 1 $bseq $lsid 10 20}]
 158 ckres "Locku" $status $expcode $res $PASS
 159 
 160 # f: new Lock w/bad stateid{1234567890 0987654321}
 161 set expcode "BAD_STATEID|STALE_STATEID"
 162 set ASSERTION "new Lock w/bad sid{1234567890 0987654321}, expect $expcode"
 163 set tag "$TNAME{f}"
 164 putmsg stdout 0 "$tag: $ASSERTION"
 165 set bad_osid {1234567890 0987654321}
 166 set res [compound {Putfh $nfh; 
 167         Lock 2 F 1024 10 T $bad_osid 2 "$oseqid $cid $lowner"}]
 168 ckres "Lock" $status $expcode $res $PASS
 169 
 170 # g: Locku(R) w/invalid stateid{0 1}  - expect BAD_STATEID|STALE_STATEID
 171 set expcode "BAD_STATEID|STALE_STATEID"
 172 set ASSERTION "Locku w/invalid sid{0 1}, expect $expcode"
 173 set tag "$TNAME{g}"
 174 putmsg stdout 0 "$tag: $ASSERTION"
 175 set bad_lsid {0 1}
 176 set res [compound {Putfh $nfh; Locku 1 $lseqid $bad_lsid 10 20}]
 177 ckres "Locku" $status $expcode $res $PASS
 178 
 179 # i: new Lock(R) w/invalid osid (seqid+1) - expect BAD_STATEID
 180 set expcode "BAD_STATEID"
 181 set ASSERTION "new Lock w/invalid osid (seqid+1), expect $expcode"
 182 set tag "$TNAME{i}"
 183 putmsg stdout 0 "$tag: $ASSERTION"
 184 set bseqid [expr [lindex $osid 0] + 1]
 185 set bad_osid "$bseqid [lindex $osid 1]"
 186 putmsg stderr 1 "  new osid with trashed seqid: bad_osid=($bad_osid)"
 187 set res [compound {Putfh $nfh; 
 188         Lock 1 F 30 10 T $bad_osid 30 "$oseqid $cid $lowner-2"}]
 189 ckres "Lock" $status $expcode $res $PASS
 190 
 191 # j: 2nd Lock(R) w/invalid lsid (seqid+1) - expect BAD_STATEID
 192 set expcode "BAD_STATEID"
 193 set ASSERTION "2nd Lock w/invalid lsid (seqid+1), expect $expcode"
 194 set tag "$TNAME{j}"
 195 putmsg stdout 0 "$tag: $ASSERTION"
 196 set bseqid [expr [lindex $lsid 0] + 1]
 197 set bad_lsid "$bseqid [lindex $lsid 1]"
 198 putmsg stderr 1 "  new lsid with trashed seqid: bad_lsid=($bad_lsid)"
 199 set res [compound {Putfh $nfh; 
 200         Lock 1 F 30 10 F $bad_lsid $lseqid "$oseqid $cid $lowner"}]
 201 ckres "Lock" $status $expcode $res $PASS
 202 
 203 # k: Locku(R) w/invalid lsid (seqid+1) - expect BAD_STATEID
 204 set expcode "BAD_STATEID"
 205 set ASSERTION "Locku w/invalid sid (seqid+1), expect $expcode"
 206 set tag "$TNAME{k}"
 207 putmsg stdout 0 "$tag: $ASSERTION"
 208 set res [compound {Putfh $nfh; Locku 1 $lseqid $bad_lsid 10 20}]
 209 ckres "Locku" $status $expcode $res $PASS
 210 
 211 # m: 2nd Lock(R) w/invalid lsid (trash-other) 
 212 set expcode "BAD_STATEID|STALE_STATEID"
 213 set ASSERTION "2nd Lock w/invalid sid (trash-other), expect $expcode"
 214 set tag "$TNAME{m}"
 215 putmsg stdout 0 "$tag: $ASSERTION"
 216 set newS ""
 217 set oldS [lindex $lsid 1]
 218 set l [string length $oldS]
 219 for {set i 0} {$i < $l} {incr i} {
 220         append newS [string index $oldS end-$i]
 221 }
 222 set bad_lsid "[lindex $lsid 0] $newS"
 223 putmsg stderr 1 "  new lsid with trashed other: bad_lsid=($bad_lsid)"
 224 set res [compound {Putfh $nfh; 
 225         Lock 1 F 30 10 F $bad_lsid 30 "$oseqid $cid $lowner-2"}]
 226 ckres "Lock" $status $expcode $res $PASS
 227 
 228 # n: Locku(R) w/invalid lsid (trash-other)
 229 set expcode "BAD_STATEID|STALE_STATEID"
 230 set ASSERTION "Locku w/invalid lsid (trash-other), expect $expcode"
 231 set tag "$TNAME{n}"
 232 putmsg stdout 0 "$tag: $ASSERTION"
 233 set res [compound {Putfh $nfh; Locku 1 $lseqid $bad_lsid 10 20}]
 234 ckres "Locku" $status $expcode $res $PASS
 235 
 236 # s: Check Lock(R) w/previous lsid - expect BAD_SEQID
 237 set expcode "BAD_SEQID"
 238 set ASSERTION "Check Lock(R) w/previous lsid, expect $expcode"
 239 set tag "$TNAME{s}"
 240 putmsg stdout 0 "$tag: $ASSERTION"
 241 set res [compound {Putfh $nfh; 
 242         Lock 1 F 100 10 F $lsid_good $lseqid "$oseqid $cid $lowner"}]
 243 ckres "Lock" $status $expcode $res $PASS
 244 putmsg stderr 1 "\t   Res=($res)"
 245 
 246 
 247 # t: Check Locku w/previous lsid - expect BAD_SEQID
 248 set expcode "BAD_SEQID"
 249 set ASSERTION "Check Locku w/previous lsid, expect $expcode"
 250 set tag "$TNAME{t}"
 251 putmsg stdout 0 "$tag: $ASSERTION"
 252 set res [compound {Putfh $nfh; Locku 1 $lseqid $lsid_good 100 20}]
 253 ckres "Locku" $status $expcode $res $PASS
 254 putmsg stderr 1 "\t   Res=($res)"
 255 
 256 
 257 # --------------------------------------------------------------
 258 # Now cleanup, and removed created tmp file
 259 set tag "$TNAME-cleanup"
 260 set res [compound {Putfh $bfh; Remove $TFILE}]
 261 if {($status != "OK") && ($status != "NOENT")} {
 262         putmsg stderr 0 "\t WARNING: cleanup to remove created tmp file failed"
 263         putmsg stderr 0 "\t          status=$status; please cleanup manually."
 264         putmsg stderr 1 "\t   res=($res)"
 265         putmsg stderr 1 "  "
 266         exit $WARNING
 267 }
 268 
 269 # --------------------------------------------------------------
 270 # disconnect and exit
 271 Disconnect
 272 exit $PASS