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 server state recovery test - negative tests
  27 #       - network partition
  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 
  39 # Get server lease time
  40 set leasetm $LEASE_TIME
  41 
  42 # First, basic setup
  43 putmsg stdout 0 \
  44   "\n  ** Frist basic setup for $TNAME, if fails, program will exit ..."
  45 
  46 # Start testing
  47 # --------------------------------------------------------------
  48 # a: Setclientid/Setclient_confirm, expect OK
  49 set expcode "OK"
  50 set ASSERTION "Setclientid/Setclient_confirm, expect $expcode"
  51 set tag "$TNAME{a}"
  52 putmsg stdout 0 "$tag: $ASSERTION"
  53 set hid "[pid]-[expr int([expr [expr rand()] * 100000000])]"
  54 set cid [getclientid $hid]
  55 if {$cid == -1} {
  56         putmsg stderr 0 "Test FAIL: unable to get clientid"
  57         exit $FAIL
  58 } else {
  59         logres PASS
  60 }
  61 
  62 
  63 # b: Open and READ a test file w/good clientid, expect OK
  64 set expcode "OK"
  65 set ASSERTION "Open and READ a test file w/good clientid, expect $expcode"
  66 set tag "$TNAME{b}"
  67 putmsg stdout 0 "$tag: $ASSERTION"
  68 set oseqid 1
  69 set TFILE "$TNAME.[pid]-b"
  70 set fs 8192
  71 set open_owner $TFILE
  72 set res [compound {Putfh $bfh; 
  73         Open $oseqid 3 0 "$cid $open_owner" \
  74                 {1 0 {{mode 0664} {size 0}}} {0 $TFILE}; Getfh}]
  75 if { $status == "OK" } {
  76         set osid [lindex [lindex $res 1] 2]
  77         set nfh [lindex [lindex $res 2] 2]
  78         set rflags [lindex [lindex $res 1] 4]
  79         putmsg stderr 1 "osid=($osid), rflags=($rflags), nfh=($nfh)"
  80         global OPEN4_RESULT_CONFIRM
  81         # do open_confirm if needed, e.g. rflags has OPEN4_RESULT_CONFIRM set
  82         if {[expr $rflags & $OPEN4_RESULT_CONFIRM] == $OPEN4_RESULT_CONFIRM} {
  83                 incr oseqid
  84                 set res [compound {Putfh $nfh; Open_confirm $osid $oseqid}]
  85                 if {$status != "OK"} {
  86                         putmsg stderr 0 \
  87                          "\t Test FAIL: Open_confirm failed, status=($status)"
  88                         putmsg stderr 0 "\t\t program exiting, and ..."
  89                         putmsg stderr 0 \
  90                          "\t\t   the following assertions (c,d,e) will not run."
  91                         putmsg stderr 1 "\t    Res=($res)"
  92                         exit $FAIL
  93                 }
  94                 set osid [lindex [lindex $res 1] 2]
  95         }
  96         set res [compound {Putfh $nfh; Setattr $osid {{size $fs}}; 
  97                 Read "$osid" 1024 2}]
  98         ckres "Read" $status $expcode $res $PASS
  99         incr oseqid
 100 } else {
 101         putmsg stderr 0 "\t Test FAIL: Open failed, status=($status)"
 102         putmsg stderr 0 "\t\t program exiting, and ..."
 103         putmsg stderr 0 "\t\t   the following assertions (c,d,e) will not run."
 104         putmsg stderr 1 "\t    Res=($res)"
 105         exit $FAIL
 106 }
 107 
 108 putmsg stdout 0 \
 109   "  ** Now wait for lease($leasetm) to expire, then do the following (c,d,e):"
 110 exec sleep [expr $leasetm + 12]
 111 
 112 # c: Now try to WRITE the test file w/osid, expect EXPIRED|BAD_STATEID
 113 set expcode "EXPIRED|BAD_STATEID"
 114 set ASSERTION "Now try to WRITE the test file w/osid, expect $expcode"
 115 set tag "$TNAME{c}"
 116 putmsg stdout 0 "$tag: $ASSERTION"
 117 set data [string repeat "C" 128]
 118 set res [compound {Putfh $nfh; Write "$osid" 512 f a $data}]
 119 ckres "Write" $status $expcode $res $PASS
 120 
 121 
 122 # d: Try to LOCK the test file w/cid+osid, expect EXPIRED|BAD_STATEID
 123 set expcode "EXPIRED|BAD_STATEID"
 124 set ASSERTION "Try to LOCK the test file w/cid+osid, expect $expcode"
 125 set tag "$TNAME{d}"
 126 putmsg stdout 0 "$tag: $ASSERTION"
 127 set lseqid 1
 128 set res [compound {Putfh $nfh; 
 129         Lock 1 F 0 10 T $osid $lseqid "$oseqid $cid $open_owner"}]
 130 ckres "Lock" $status $expcode $res $PASS
 131 
 132   
 133 # e: Try LOCKT the test file w/cid, expect STALE_CLIENTID
 134 set expcode "STALE_CLIENTID"
 135 set ASSERTION "Try LOCKT the test file w/cid, expect $expcode"
 136 set tag "$TNAME{e}"
 137 putmsg stdout 0 "$tag: $ASSERTION"
 138 #set lseqid 1
 139 #set res [compound {Putfh $nfh; Lockt 2 $cid "lock_owner" 0 22}]
 140 #ckres "Lockt" $status $expcode $res $PASS
 141 putmsg stdout 0 "\t Test UNSUPPORTED: invalid in Solaris"
 142 putmsg stdout 1 "\t   This assertion is based on the variability of"
 143 putmsg stdout 1 "\t   interpretation for the server implementation."
 144   
 145 
 146 # --------------------------------------------------------------
 147 # Now cleanup, and removed created tmp file
 148 set res [compound {Putfh $bfh; Remove $TFILE}]
 149 if {($status != "OK") && ($status != "NOENT")} {
 150         putmsg stderr 0 "\t WARNING: cleanup to remove created tmp file failed"
 151         putmsg stderr 0 "\t          status=$status; please cleanup manually."
 152         putmsg stderr 1 "\t   res=($res)"
 153         putmsg stderr 1 "  "
 154         exit $WARNING
 155 }
 156 
 157 # --------------------------------------------------------------
 158 # disconnect and exit
 159 Disconnect
 160 exit $PASS