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
45
46 # First set/get the clientid
47 set owner "[pid]-[expr int([expr [expr rand()] * 100000000])]"
48 set cid [getclientid $owner 0 0 0]
49 if {$cid == -1} {
50 putmsg stderr 0 "\t Test UNRESOLVED: getclientid failed"
51 return -1
52 }
53 set cid_owner "$cid $owner"
54
55 # Create the file for write
56 set otype 1
57 if {$wct == 0} {set otype 0}
58 set nfh [basic_open $dfh $fname $otype $cid_owner open_sid oseqid status]
59 if {$nfh == -1} {
60 putmsg stderr 0 "\t Test UNRESOLVED: basic_open failed, status=$status"
61 return -1
62 }
63
64 # Now write data to the file
65 set data [string repeat "*" $wct]
66 if {($wct == 0) || (($wct > 1) && ($wct < 32768))} {
67 set wres [compound {Putfh $nfh; Write "$open_sid" $off f a $data}]
68 set wstatus $status
69 putmsg stdout 2 "\nWrite {$open_sid} $off $wct ..."
70 putmsg stdout 2 "Res: $wres"
71 # try to read back some data
72 set rres [compound {Putfh $nfh; Read "$open_sid" $off $wct}]
73 if {$status != "OK"} {
74 putmsg stderr 0 "\t Test UNINITIATED: Read failed"
75 putmsg stdout 0 "\t Read returned $status\n"
76 return -1
77 }
78 set ndata [lindex [lindex [lindex [lindex $rres 1] 2] 2 ] 0]
79 if {[string compare $data $ndata] != 0} {
80 putmsg stderr 0 "\t Test FAIL: Data read back does not match"
81 return -1
82 }
83 } else {
84 while {$off <= 1026 } {
85 set wres [compound {Putfh $nfh;
86 Write "$open_sid" $off d a "B"}]
87 set wstatus $status
88 putmsg stdout 2 "\nWrite {$open_sid} $off 1B ..."
89 putmsg stdout 2 "Res: $wres"
90 set off [expr $off + $wct + 1]
91 }
92 }
93 set res [compound {Putfh $nfh; Commit 0 0; Close $oseqid $open_sid}]
94 putmsg stdout 2 "\nClose $oseqid $open_sid ... "
95 putmsg stdout 2 "Res: $res"
96
97 # Now check for expected results
98 if {$wstatus != $expcode} {
99 putmsg stderr 0 \
100 "\t Test FAIL: Write returned ($status), expected ($expcode)"
101 putmsg stderr 1 "\t res=($wres)"
102 putmsg stderr 1 " "
103 return -1
104 } else {
105 set nwct [lindex [lindex [lindex $wres 1] 2] 0]
106 if {($expwct != -1) && ($nwct != $expwct)} {
107 putmsg stderr 0 \
108 "\t Test FAIL: Write returned wct=($nwct), expected=($expwct)"
109 putmsg stderr 1 " "
110 return -1
111 }
112 if {$prn == 0} {
113 putmsg stdout 0 "\t Test PASS"
114 }
115 return 0
116 }
117 }