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 2008 Sun Microsystems, Inc.  All rights reserved.
  24 # Use is subject to license terms.
  25 #
  26 # NFSv4 READDIR operation test - negative tests
  27 #       verify SERVER errors returned with invalid Getattr.
  28 
  29 # include all test enironment
  30 source READDIR.env
  31 
  32 Connect
  33 
  34 # setting local variables
  35 set TNAME $argv0
  36 set bfh [get_fh $BASEDIRS]
  37 
  38 # setting parameters for the basic_open function
  39 set cid [getclientid $TNAME.[pid]]
  40 if {$cid == -1} {
  41         putmsg stdout 0 "$TNAME: test setup - getclientid"
  42         putmsg stdout 0 "\t Test UNINITIATED: unable to get clientid"
  43         exit $UNINITIATED
  44 }
  45 set owner "$TNAME-OpenOwner"
  46 set otype 1;#   create file
  47 set ctype 0;#   create unchecked
  48 set seqid 1
  49 set close 1;#   close after create
  50 set mode 666
  51 set size 0
  52 set access 3;#  R/W access
  53 set deny 0;#    deny none
  54 
  55 # Start testing
  56 # --------------------------------------------------------------
  57 # a: Readdir with a file filehandle, expect NOTDIR
  58 set expcode "NOTDIR"
  59 set ASSERTION "Readdir with a file filehandle, expect $expcode"
  60 set tag "$TNAME{a}"
  61 putmsg stdout 0 "$tag: $ASSERTION"
  62 set res [compound {Putfh $bfh; Lookup "$env(RWFILE)";
  63         Readdir 0 0 512 1024 type}]
  64 ckres "Readdir" $status $expcode $res $PASS
  65 
  66 
  67 # b: Readdir with a symldir filehandle, expect NOTDIR
  68 set expcode "NOTDIR"
  69 set ASSERTION "Readdir with a symldir filehandle, expect $expcode"
  70 set tag "$TNAME{b}"
  71 putmsg stdout 0 "$tag: $ASSERTION"
  72 set res [compound {Putfh $bfh; Lookup "$env(SYMLDIR)";
  73         Readdir 0 0 512 1024 type}]
  74 ckres "Readdir" $status $expcode $res $PASS
  75 
  76 
  77 # c: Readdir with a FIFO filehandle, expect NOTDIR
  78 set expcode "NOTDIR"
  79 set ASSERTION "Readdir with a FIFO filehandle, expect $expcode"
  80 set tag "$TNAME{c}"
  81 putmsg stdout 0 "$tag: $ASSERTION"
  82 set res [compound {Putfh $bfh; Lookup "$env(FIFOFILE)";
  83         Readdir 0 0 512 1024 type}]
  84 ckres "Readdir" $status $expcode $res $PASS
  85 
  86 
  87 # e: Readdir with cookie=1, expect OK|BAD_COOKIE
  88 #    Spec says, arg.cookie of 1 should not be used.
  89 set expcode "OK|BAD_COOKIE"
  90 set ASSERTION "Readdir with cookie=1, expect $expcode"
  91 set tag "$TNAME{e}"
  92 putmsg stdout 0 "$tag: $ASSERTION"
  93 set cookie 1
  94 set res [compound {Putfh $bfh; 
  95         Readdir $cookie 0 1024 8192 {time_modify type}}]
  96 ckres "Readdir" $status $expcode $res $PASS
  97 
  98 
  99 # f: Readdir with cookie=2, expect OK|BAD_COOKIE
 100 #    Spec says, arg.cookie of 2 should not be used.
 101 set expcode "OK|BAD_COOKIE"
 102 set ASSERTION "Readdir with cookie=2, expect $expcode"
 103 set tag "$TNAME{f}"
 104 putmsg stdout 0 "$tag: $ASSERTION"
 105 set cookie 2
 106 set res [compound {Putfh $bfh; 
 107         Readdir $cookie 0 1024 8192 {size acl filehandle}}]
 108 ckres "Readdir" $status $expcode $res $PASS
 109 
 110 
 111 # i: Readdir with maxcount=0, expect TOOSMALL
 112 set expcode "TOOSMALL"
 113 set ASSERTION "Readdir with maxcount=0, expect $expcode"
 114 set tag "$TNAME{i}"
 115 putmsg stdout 0 "$tag: $ASSERTION"
 116 set dircount 1024
 117 set maxcount 0
 118 set res [compound {Putfh $bfh; Readdir 0 0 $dircount $maxcount type}]
 119 ckres "Readdir" $status $expcode $res $PASS
 120 
 121 
 122 # j: Readdir with maxcount=1, expect TOOSMALL
 123 set expcode "TOOSMALL"
 124 set ASSERTION "Readdir with maxcount=1, expect $expcode"
 125 set tag "$TNAME{j}"
 126 putmsg stdout 0 "$tag: $ASSERTION"
 127 set dircount 1024
 128 set maxcount 1
 129 set res [compound {Putfh $bfh; Readdir 0 0 $dircount $maxcount type}]
 130 ckres "Readdir" $status $expcode $res $PASS
 131 
 132 
 133 # k: Readdir with maxcount=smallest for OTW entry, expect TOOSMALL
 134 set expcode "TOOSMALL"
 135 set ASSERTION "Readdir with maxcount=smallest for OTW entry, expect $expcode"
 136 set tag "$TNAME{k}"
 137 putmsg stdout 0 "$tag: $ASSERTION"
 138 set dircount 1024
 139 set maxcount 23
 140 set res [compound {Putfh $bfh; Readdir 0 0 $dircount $maxcount type}]
 141 ckres "Readdir" $status $expcode $res $PASS
 142 
 143 
 144 # l: Readdir with maxcount=24 bytes, but entry name in dir > 4 bytes, 
 145 #       expect TOOSMALL for Solaris, but maybe OK for other vendors.
 146 set expcode "TOOSMALL|OK"
 147 set A "Readdir w/maxcount=24 bytes, but entry name in dir > 4 bytes;\n"
 148 set ASSERTION "$A \t\texpect TOOSMALL for Solaris, maybe OK for other vendors"
 149 set tag "$TNAME{l}"
 150 putmsg stdout 0 "$tag: $ASSERTION"
 151 set dircount 1024
 152 set maxcount 24
 153 set res [compound {Putfh $bfh; Lookup $env(ATTRFILE); Openattr f;
 154         Readdir 0 0 $dircount $maxcount type}]
 155 if { $env(SRVOS) == "Solaris" } {
 156         ckres "Readdir" $status "TOOSMALL" $res $PASS
 157 } else {
 158         ckres "Readdir" $status $expcode $res $PASS
 159 }
 160 
 161 
 162 # Following assertions assume "root" is a pesudo node:
 163 # p: Readdir root (pesudo node) with maxcount=0, expect TOOSMALL
 164 set expcode "TOOSMALL"
 165 set ASSERTION "Readdir root (pesudo node) with maxcount=0, expect $expcode"
 166 set tag "$TNAME{p}"
 167 putmsg stdout 0 "$tag: $ASSERTION"
 168 set dircount 8192
 169 set maxcount 0
 170 set res [compound {Putrootfh; Readdir 0 0 $dircount $maxcount type}]
 171 ckres "Readdir" $status $expcode $res $PASS
 172 
 173 
 174 # q: Readdir root (pesudo node) with maxcount=1, expect TOOSMALL
 175 set expcode "TOOSMALL"
 176 set ASSERTION "Readdir root (pesudo node) with maxcount=1, expect $expcode"
 177 set tag "$TNAME{q}"
 178 putmsg stdout 0 "$tag: $ASSERTION"
 179 set dircount 8192
 180 set maxcount 1
 181 set res [compound {Putrootfh; Readdir 0 0 $dircount $maxcount type}]
 182 ckres "Readdir" $status $expcode $res $PASS
 183 
 184 
 185 # r: Readdir root (pesudo node) with maxcount=23, expect TOOSMALL
 186 set expcode "TOOSMALL"
 187 set ASSERTION "Readdir root (pesudo node) with maxcount=23, expect $expcode"
 188 set tag "$TNAME{r}"
 189 putmsg stdout 0 "$tag: $ASSERTION"
 190 set dircount 8192
 191 set maxcount 23
 192 set res [compound {Putrootfh; Readdir 0 0 $dircount $maxcount type}]
 193 ckres "Readdir" $status $expcode $res $PASS
 194 
 195 # t: Readdir of large filename with maxcount=48, expect TOOSMALL
 196 set tag "$TNAME{t}"
 197 set expcode "TOOSMALL"
 198 set ASSERTION \
 199     "Readdir of large file name with maxcount=48, expect $expcode"
 200 putmsg stdout 0 "$tag: $ASSERTION"
 201 set ndir "newtd.[pid]"
 202 set res [compound {Putfh $bfh; Create $ndir {{mode 0755}} d; Getfh}]
 203 putmsg stdout 1 "compound {Putfh $bfh;"
 204 putmsg stdout 1 "\t Create $ndir {{mode 0755}} d; Getfh}"
 205 if {$status != "OK"} {
 206     putmsg stderr 0 "\t Test UNINITIATED: "
 207     putmsg stderr 0 "\t   Create failed, status=($status)"
 208 } else {
 209     set nfh [lindex [lindex $res 2] 2]
 210     set TFILE "012345678901234567890123456789012345678901234567890123456789"
 211     set fh1 [basic_open $nfh $TFILE $otype "$cid $owner" osid oseqid \
 212         status $seqid $close $mode $size $access $deny $ctype]
 213     if { $fh1 == -1 } {
 214         putmsg stderr 0 "\t Test UNINITIATED: "
 215         putmsg stderr 0 \
 216             "\t   basic_open(acc=R/W,deny=N) failed, status=($status)"
 217     } else {
 218         set dircount 1024
 219         set maxcount 48
 220         set res [compound {Putfh $nfh;
 221             Readdir 0 0 $dircount $maxcount type}]
 222         putmsg stdout 1 "compound {Putfh $nfh;"
 223         putmsg stdout 1 "\t Readdir 0 0 $dircount $maxcount type}"
 224         ckres "Readdir" $status $expcode $res $PASS
 225 
 226         # Now cleanup, and remove created tmp file
 227         set res [compound {Putfh $nfh; Remove $TFILE}]
 228         putmsg stdout 1 "compound {Putfh $nfh;"
 229         putmsg stdout 1 "\t Remove $TFILE}"
 230         if {$status != "OK"} {
 231             putmsg stderr 0 "\t WARNING: cleanup to remove created tmp file failed"
 232             putmsg stderr 0 "\t          status=$status; please cleanup manually."
 233             putmsg stderr 1 "\t   res=($res)"
 234             putmsg stderr 1 "  "
 235         }
 236     }
 237 
 238     # Now cleanup, and remove created tmp directory
 239     set res [compound {Putfh $bfh; Remove $ndir}]
 240     putmsg stdout 1 "compound {Putfh $bfh;"
 241     putmsg stdout 1 "\t Remove $ndir}"
 242     if {$status != "OK"} {
 243         putmsg stderr 0 "\t WARNING: cleanup to remove created tmp directory failed"
 244         putmsg stderr 0 "\t          status=$status; please cleanup manually."
 245         putmsg stderr 1 "\t   res=($res)"
 246         putmsg stderr 1 "  "
 247     }
 248 }
 249 
 250 # u1: Readdir of first file name with maxcount=96, expect OK,
 251 # u2: Readdir of second file name with maxcount=96, expect TOOSMALL,
 252 #     {u2} depends on {u1}; if {u1} fails, {u2} will skip.
 253 set tag "$TNAME{u1}"
 254 set expcode "OK"
 255 set attr "type size mode owner_group"
 256 set dircount 1024
 257 set maxcount 96
 258 set ASSERTION \
 259     "Readdir of first file name with maxcount=$maxcount, expect $expcode"
 260 putmsg stdout 0 "$tag: $ASSERTION"
 261 set ndir "newtd1.[pid]"
 262 set res [compound {Putfh $bfh; Create $ndir {{mode 0755}} d; Getfh}]
 263 putmsg stdout 1 "compound {Putfh $bfh;"
 264 putmsg stdout 1 "\t Create $ndir {{mode 0755}} d; Getfh}"
 265 if {$status != "OK"} {
 266     putmsg stderr 0 "\t Test UNINITIATED: "
 267     putmsg stderr 0 "\t   Create failed, status=($status)"
 268 } else {
 269     set nfh [lindex [lindex $res 2] 2]
 270     set TFILE1 "01"
 271     incr oseqid;#   oseqid is returned from previous basic_open call
 272     set fh1 [basic_open $nfh $TFILE1 $otype "$cid $owner" osid oseqid \
 273         status $oseqid $close $mode $size $access $deny $ctype]
 274     if { $fh1 == -1 } {
 275         putmsg stderr 0 "\t Test UNINITIATED: "
 276         putmsg stderr 0 \
 277             "\t basic_open(acc=R/W,deny=N) failed, status=($status)"
 278     } else {
 279         set res [compound {Putfh $nfh; \
 280             Readdir 0 0 $dircount $maxcount $attr}]
 281         putmsg stdout 1 "compound {Putfh $nfh;"
 282         putmsg stdout 1 "\t Readdir 0 0 $dircount $maxcount $attr}"
 283         if {$status == $expcode} {
 284             putmsg stdout 0 "\t Test PASS"
 285             
 286             # remove created tmp file 1
 287             set res [compound {Putfh $nfh; Remove $TFILE1}]
 288             putmsg stdout 1 "compound {Putfh $nfh;"
 289             putmsg stdout 1 "\t Remove $TFILE1}"
 290             if {$status != "OK"} {
 291                 putmsg stderr 0 \
 292                     "\t WARNING: cleanup to remove created tmp file 1 failed"
 293                 putmsg stderr 0 \
 294                     "\t          status=$status; please cleanup manually."
 295                 putmsg stderr 1 "\t   res=($res)"
 296                 putmsg stderr 1 "  "
 297             }
 298 
 299             # u2: Readdir of second file name with maxcount=96,
 300             #     expect TOOSMALL.  
 301             #  The assertion will return UNRESOLVED if u1 fails
 302 
 303             set tag "$TNAME{u2}"
 304             set expcode1 "TOOSMALL"
 305             set A "Readdir of second file name with maxcount=$maxcount,"
 306             set ASSERTION "$A expect $expcode1"
 307             putmsg stdout 0 "$tag: $ASSERTION"
 308 
 309             set TFILE2 \
 310                 "012345678901234567890123456789012345678901234567890123456789"
 311             incr oseqid
 312             set fh2 [basic_open $nfh $TFILE2 $otype "$cid $owner" osid oseqid \
 313                 status $oseqid $close $mode $size $access $deny $ctype]
 314             if { $fh2 == -1 } {
 315                 putmsg stderr 0 "\t Test UNINITIATED: "
 316                 putmsg stderr 0 \
 317                     "\t basic_open(acc=R/W,deny=N) failed, status=($status)"
 318             } else {
 319                 set cookie [lindex [lindex [lindex [lindex $res 1] 3] 0] 0]
 320                 set res [compound {Putfh $nfh; \
 321                     Readdir $cookie 0 $dircount $maxcount $attr}]
 322                 putmsg stdout 1 "compound {Putfh $nfh;"
 323                 putmsg stdout 1 "\tReaddir $cookie 0 $dircount $maxcount $attr}"
 324                 ckres "Readdir" $status $expcode1 $res $PASS
 325                
 326                 # Now cleanup, and remove created tmp file 2
 327                 set res [compound {Putfh $nfh; Remove $TFILE2}]
 328                 putmsg stdout 1 "compound {Putfh $nfh;"
 329                 putmsg stdout 1 "\t Remove $TFILE2}"
 330                 if {$status != "OK"} {
 331                     putmsg stderr 0 \
 332                         "\t WARNING: cleanup to remove created tmp file 2 failed"
 333                     putmsg stderr 0 \
 334                             "\t          status=$status; please cleanup manually."
 335                     putmsg stderr 1 "\t   res=($res)"
 336                     putmsg stderr 1 "  "
 337                 }
 338             }
 339         } else {
 340                 putmsg stdout 0 \
 341                     "\t Test FAIL: Readdir returned ($status), expected ($expcode)"
 342                 set tag "$TNAME{u2}"
 343                 set expcode1 "TOOSMALL"
 344                 # continue cleanup, to remove created tmp file 1
 345                 set res [compound {Putfh $nfh; Remove $TFILE1}]
 346 
 347                 set A "Readdir of second file name with maxcount=$maxcount,"
 348                 set ASSERTION "$A expect $expcode1"
 349                 putmsg stdout 0 "$tag: $ASSERTION"
 350                 putmsg stdout 0 \
 351                    "\t Test UNRESOLVED: assertion depends on {u1} which failed."
 352         }
 353     }
 354 
 355     # finally remove parent tmp directory
 356     set res [compound {Putfh $bfh; Remove $ndir}]
 357     putmsg stdout 1 "compound {Putfh $bfh;"
 358     putmsg stdout 1 "\t Remove $ndir}"
 359     if {$status != "OK"} {
 360         putmsg stderr 0 \
 361                 "\t WARNING: cleanup to remove created tmp directory failed"
 362         putmsg stderr 0 "\t          status=$status; please cleanup manually."
 363         putmsg stderr 1 "\t   res=($res)"
 364         putmsg stderr 1 "  "
 365     }
 366 }
 367 
 368 
 369 # --------------------------------------------------------------
 370 # disconnect and exit
 371 Disconnect
 372 exit $PASS