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 READ/WRITE operation test - positive boundary tests
  27 #       verify reading/writing of a file around the boundary
  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 # First create a tmp file for testing
  40 set hid "[pid][clock seconds]"
  41 set cid [getclientid $hid]
  42 if {$cid == -1} {
  43         putmsg stdout 0 "$TNAME: test setup - getclientid"
  44         putmsg stderr 0 "\t Test UNRESOLVED: unable to get clientid"
  45         exit $UNRESOLVED
  46 }
  47 # Open to create the temp file:
  48 set TFILE "$TNAME.[pid]"
  49 set owner "owner-$TFILE"
  50 set otype 1
  51 set cid_owner "$cid $owner"
  52 set nfh [basic_open $bfh $TFILE $otype $cid_owner open_sid oseqid status]
  53 if {$nfh == -1} {
  54         putmsg stdout 0 "$TNAME: test setup - basic_open"
  55         putmsg stderr 0 \
  56                 "\t Test UNRESOLVED: create $TFILE failed, status=$status"
  57         exit $UNRESOLVED
  58 }
  59 
  60 set 2G 2147483648
  61 
  62 
  63 # Start testing
  64 # --------------------------------------------------------------
  65 # a: Write up to 2G boundary (offset=2g-4K, data=4K) - expect OK
  66 set expcode "OK"
  67 set ASSERTION "Write up to 2G boundary (off=2g-4K, data=4K), expect $expcode"
  68 set tag "$TNAME{a}"
  69 putmsg stdout 0 "$tag: $ASSERTION"
  70 set count 4096
  71 set off [expr $2G - $count]
  72 set data [string repeat "A" $count]
  73 set res [compound {Putfh $nfh; Write $open_sid $off f a $data; Getattr size}]
  74 if {$status != "OK"} {
  75         putmsg stderr 0 "\t Test FAIL: failed to write at $off for 4K."
  76         putmsg stderr 1 "\t\t Res: $res"
  77 } else {
  78     set fsize [lindex [lindex [lindex [lindex $res 2] 2] 0] 1]
  79     if {$fsize != $2G} {
  80         putmsg stderr 0 "\t Test FAIL: incorrect file size after Write"
  81         putmsg stderr 0 "\t\t expected=(2G); got=($fsize)"
  82         putmsg stderr 1 "\t\t Res: $res"
  83     } else {
  84         logres PASS
  85     }
  86 }
  87 
  88 
  89 # b: Read up to 2G boundary (offset=2g-4K, count=4K) - expect OK
  90 set expcode "OK"
  91 set ASSERTION "Read up to 2G boundary (off=2g-4K, count=4K), expect $expcode"
  92 set tag "$TNAME{b}"
  93 putmsg stdout 0 "$tag: $ASSERTION"
  94 set res [compound {Putfh $nfh; Read $open_sid $off $count; Getattr size}]
  95 if {$status != "OK"} {
  96         putmsg stderr 0 "\t Test FAIL: failed to read at $off for $count."
  97         putmsg stderr 1 "\t\t Res: $res"
  98 } else {
  99     set rsize [lindex [lindex [lindex [lindex $res 1] 2] 1] 1]
 100     if {$rsize != $count} {
 101         putmsg stderr 0 "\t Test FAIL: incorrect read len"
 102         putmsg stderr 0 "\t\t expected=($count); got=($rsize)"
 103         putmsg stderr 1 "\t\t Res: $res"
 104     } else {
 105         logres PASS
 106     }
 107 }
 108 
 109 
 110 # c: Write over 2G boundary (offset=2g-4K, data=8K) - expect OK
 111 set expcode "OK"
 112 set ASSERTION "Write over 2G boundary (off=2g-4K, data=8K), expect $expcode"
 113 set tag "$TNAME{c}"
 114 putmsg stdout 0 "$tag: $ASSERTION"
 115 set count 4096
 116 set off [expr $2G - $count]
 117 set data [string repeat "B" [expr $count * 2]]
 118 set res [compound {Putfh $nfh; Write $open_sid $off f a $data; Getattr size}]
 119 if {$status != "OK"} {
 120         putmsg stderr 0 "\t Test FAIL: failed to write at $off for 4K."
 121         putmsg stderr 1 "\t\t Res: $res"
 122 } else {
 123     set fsize [lindex [lindex [lindex [lindex $res 2] 2] 0] 1]
 124     if {[expr $fsize - $count] != $2G} {
 125         putmsg stderr 0 "\t Test FAIL: incorrect file size after Write"
 126         putmsg stderr 0 "\t\t expected=(2G+4K); got=($fsize)"
 127         putmsg stderr 1 "\t\t Res: $res"
 128     } else {
 129         logres PASS
 130     }
 131 }
 132 
 133 
 134 # d: Read over 2G boundary (offset=2g-4K, count=8K) - expect OK
 135 set expcode "OK"
 136 set ASSERTION "Read over 2G boundary (off=2g-4K, count=8K), expect $expcode"
 137 set tag "$TNAME{d}"
 138 putmsg stdout 0 "$tag: $ASSERTION"
 139 set count 8192
 140 set res [compound {Putfh $nfh; Read $open_sid $off $count; Getattr size}]
 141 if {$status != "OK"} {
 142         putmsg stderr 0 "\t Test FAIL: failed to read at $off for $count."
 143         putmsg stderr 1 "\t\t Res: $res"
 144 } else {
 145     set rsize [lindex [lindex [lindex [lindex $res 1] 2] 1] 1]
 146     if {$rsize != $count} {
 147         putmsg stderr 0 "\t Test FAIL: incorrect read len"
 148         putmsg stderr 0 "\t\t expected=($count); got=($rsize)"
 149         putmsg stderr 1 "\t\t Res: $res"
 150     } else {
 151         logres PASS
 152     }
 153 }
 154 
 155 
 156 # --------------------------------------------------------------
 157 # Cleanup the temp file:
 158 incr oseqid
 159 set res [compound {Putfh $nfh; Close $oseqid $open_sid; 
 160         Putfh $bfh; Remove $TFILE}]
 161 if { "$status" != "OK" } {
 162         putmsg stderr 0 "\t WARNING: cleanup to remove $TFILE failed"
 163         putmsg stderr 0 "\t          status=$status; please cleanup manually."
 164         putmsg stderr 1 "\t   res=($res)"
 165         putmsg stderr 1 "  "
 166         exit $WARNING
 167 }
 168 
 169 # disconnect and exit
 170 Disconnect
 171 exit $PASS