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 WRITE operation testing
  27 
  28 #---------------------------------------------------------
  29 # Test procedure to Open and Write a file and check for wct and EOF flag.
  30 #  Usage: ckwrite dfh fname off wct expcode expwct prn
  31 #       dfh:     the directory filehandle where $fname located
  32 #       fname:   the filename of the file to be Opened/Write
  33 #       off:     the offset to Write
  34 #       wct:     the count of bytes to Write
  35 #       expcode: the expected status code from the Write op
  36 #       expwct:  the expected length Write
  37 #       prn:     the flag to print PASS/FAIL message
  38 #
  39 #  Return: 
  40 #       0:      Write success
  41 #       -1:     things failed during the process
  42 #
  43 proc ckwrite {dfh fname off wct expcode expwct {prn 0}} {
  44     global DEBUG OPEN4_RESULT_CONFIRM
  45 
  46     # Create the file for write
  47     set owner "[pid]-[expr int([expr [expr rand()] * 100000000])]"
  48     set clientid [getclientid $owner]
  49       putmsg stdout 2 "\ngetclientid $owner ..."
  50     set oseqid 1
  51     set otype 1
  52     if {$wct == 0} {set otype 0}
  53     set mode 0664
  54     set oclaim 0
  55     set res [compound {Putfh $dfh; 
  56         Open $oseqid 3 0 {$clientid $owner} \
  57         {$otype 0 {{mode $mode}}} {$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 write data to the file
  86     set data [string repeat "*" $wct]
  87     if {($wct == 0) || (($wct > 1) && ($wct < 32768))} {
  88         set wres [compound {Putfh $nfh; Write "$open_sid" $off f a $data}]
  89         set wstatus $status
  90           putmsg stdout 2 "\nWrite {$open_sid} $off $wct ..."
  91           putmsg stdout 2 "Res: $wres"
  92         # try to read back some data
  93         set rres [compound {Putfh $nfh; Read "$open_sid" $off $wct}]
  94         if {$status != "OK"} {
  95             putmsg stderr 0 "\t Test FAIL: Read failed"
  96             putmsg stdout 0 "\t   Read returned $status\n"
  97             putmsg stderr 0 "\t Res=($res)\n"
  98             return -1
  99         }
 100     } else {
 101         while {$off <= 1026 } {
 102             set wres [compound {Putfh $nfh; 
 103                 Write "$open_sid" $off d a "B"}]
 104             set wstatus $status
 105               putmsg stdout 2 "\nWrite {$open_sid} $off 1B ..."
 106               putmsg stdout 2 "Res: $wres"
 107             set off [expr $off + $wct + 1] 
 108         }
 109     }
 110     set res [compound {Putfh $nfh; Commit 0 0; Close $oseqid $open_sid}]
 111       putmsg stdout 2 "\nClose $oseqid $open_sid ... "
 112       putmsg stdout 2 "Res: $res"
 113 
 114     # Now check for expected results
 115     if {$wstatus != $expcode} {
 116         putmsg stderr 0 \
 117                 "\t Test FAIL: Write returned ($status), expected ($expcode)"
 118         putmsg stderr 1 "\t   res=($wres)"
 119         putmsg stderr 1 "  "
 120         return -1
 121     } else {
 122         set nwct [lindex [lindex [lindex $wres 1] 2] 0]
 123         if {($expwct != -1) && ($nwct != $expwct)} {
 124             putmsg stderr 0 \
 125             "\t Test FAIL: Write returned wct=($nwct), expected=($expwct)"
 126             putmsg stderr 1 "  "
 127             return -1
 128         } 
 129         if {$prn == 0} {
 130             putmsg stdout 0 "\t Test PASS"
 131         }
 132         return 0
 133     }
 134 }