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 # TCL procedure for READ operation testing
  27 
  28 #---------------------------------------------------------
  29 # Test procedure to Open and Read a file and check for len and EOF flag.
  30 #  Usage: ckread dfh fname off cnt expcode explen expeof prn
  31 #       dfh:     the directory filehandle where $fname located
  32 #       fname:   the filename of the file to be Opened/Read
  33 #       off:     the offset to Read
  34 #       cnt:     the count of bytes to Read
  35 #       expcode: the expected status code from the Read op
  36 #       explen:  the expected length Read
  37 #       expeof:  the expected EOF flag from Read op
  38 #       prn:     the flag to print PASS/FAIL message
  39 #
  40 #  Return: 
  41 #       0:      Write success
  42 #       -1:     things failed during the process
  43 #
  44 proc ckread {dfh fname off cnt expcode explen expeof {prn 0}} {
  45     global DEBUG OPEN4_RESULT_CONFIRM
  46 
  47     # Open the file for read
  48     set owner "[pid]-[expr int([expr [expr rand()] * 100000000])]"
  49     set clientid [getclientid $owner]
  50       putmsg stdout 2 "\ngetclientid $owner ..."
  51     set oseqid 1
  52     set otype 0
  53     set mode 0664
  54     set oclaim 0
  55     set res [compound {Putfh $dfh; 
  56         Open $oseqid 1 0 {$clientid $owner} \
  57         {$otype 0 {{mode $mode} {size $size}}} {$oclaim $fname};
  58         Getfh; Getattr {mode}}]
  59       putmsg stdout 2 "\nOpen $fname ..."
  60       putmsg stdout 2 "Res: $res"
  61       if {$status != "OK"} {
  62         putmsg stderr 0 "\t Test UNRESOLVED: Open failed"
  63         putmsg stdout 0 "\t   Open ($fname) returned $status"
  64         putmsg stderr 0 "\t Res=($res)\n"
  65         return -1
  66       }
  67     set open_sid [lindex [lindex $res 1] 2]
  68     set rflags [lindex [lindex $res 1] 4] 
  69     set nfh [lindex [lindex $res 2] 2]
  70     set attr [lindex [lindex $res 3] 2]
  71     incr oseqid
  72     if {[expr $rflags & $OPEN4_RESULT_CONFIRM] == $OPEN4_RESULT_CONFIRM} {
  73         set res [compound {Putfh $nfh; Open_confirm "$open_sid" $oseqid}]
  74           putmsg stdout 2 "\nOpen_confirm {$open_sid} $oseqid ..."
  75           putmsg stdout 2 "Res: $res"
  76         if {$status != "OK"} {
  77             putmsg stderr 0 "\t Test UNRESOLVED: Open_confirm failed"
  78             putmsg stdout 0 "\t   Open_confirm returned $status"
  79             putmsg stderr 0 "\t Res=($res)\n"
  80             return -1
  81         }
  82         set open_sid [lindex [lindex $res 1] 2]
  83         incr oseqid
  84     }
  85     # Now read the file
  86     if {($cnt == 0) || (($cnt > 1) && ($cnt < 32768))} {
  87         set rres [compound {Putfh $nfh; Read "$open_sid" $off $cnt}]
  88         set rstatus $status
  89           putmsg stdout 2 "\nRead {$open_sid} $off $cnt ..."
  90           putmsg stdout 2 "Res: $rres"
  91     } else {
  92         set eof "false"
  93         while {$eof != "true"} {
  94             set rres [compound {Putfh $nfh; Read "$open_sid" $off $cnt}]
  95             set rstatus $status
  96               putmsg stdout 2 "\nRead {$open_sid} $off $cnt ..."
  97               putmsg stdout 2 "Res: $rres"
  98             set eof [lindex [lindex [lindex [lindex $rres 1] 2] 0 ] 1]
  99             set off [expr $off + $cnt] 
 100         }
 101     }
 102     set res [compound {Putfh $nfh; Close $oseqid $open_sid}]
 103       putmsg stdout 2 "\nClose $oseqid $open_sid ... "
 104       putmsg stdout 2 "Res: $res"
 105 
 106     # Now check for expected results
 107     if {$rstatus != $expcode} {
 108         putmsg stderr 0 \
 109                 "\t Test FAIL: Read returned ($status), expected ($expcode)"
 110         putmsg stderr 1 "\t   res=($rres)"
 111         putmsg stderr 1 "  "
 112         return -1
 113     } else {
 114         if {$prn == 0} {
 115             putmsg stdout 0 "\t Test PASS"
 116         }
 117         return 0
 118     }
 119 }