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
46
47 # First set/get the clientid
48 set owner "[pid]-[expr int([expr [expr rand()] * 100000000])]"
49 set clientid [getclientid $owner 0 0 0]
50 if {$clientid == -1} {
51 putmsg stderr 0 "\t Test UNRESOLVED: getclientid failed"
52 return -1
53 }
54 set cid_owner "$clientid $owner"
55
56 # Now open the file for read
57 set otype 0
58 set nfh [basic_open $dfh $fname $otype $cid_owner open_sid oseqid status\
59 10 0 600 0 1]
60 if {$nfh == -1} {
61 putmsg stderr 0 \
62 "\t Test UNRESOLVED: basic_open() failed, status=$status"
63 return -1
64 }
65
66 # Now read the file
67 if {($cnt == 0) || (($cnt > 1) && ($cnt < 32768))} {
68 set rres [compound {Putfh $nfh; Read "$open_sid" $off $cnt}]
69 set rstatus $status
70 putmsg stdout 2 "\nRead {$open_sid} $off $cnt ..."
71 putmsg stdout 2 "Res: $rres"
72 } else {
73 set eof "false"
74 while {$eof != "true"} {
75 set rres [compound {Putfh $nfh; Read "$open_sid" $off $cnt}]
76 set rstatus $status
77 putmsg stdout 2 "\nRead {$open_sid} $off $cnt ..."
78 putmsg stdout 2 "Res: $rres"
79 set eof [lindex [lindex [lindex [lindex $rres 1] 2] 0 ] 1]
80 set off [expr $off + $cnt]
81 }
82 }
83 set oseqid [expr $oseqid + 1]
84 set res [compound {Putfh $nfh; Close $oseqid $open_sid}]
85 putmsg stdout 2 "\nClose $oseqid $open_sid ... "
86 putmsg stdout 2 "Res: $res"
87
88 # Now check for expected results
89 if {$rstatus != $expcode} {
90 putmsg stderr 0 \
91 "\t Test FAIL: Read returned ($status), expected ($expcode)"
92 putmsg stderr 1 "\t res=($rres)"
93 putmsg stderr 1 " "
94 return -1
95 } else {
96 set len [lindex [lindex [lindex [lindex $rres 1] 2] 1 ] 1]
97 set eof [lindex [lindex [lindex [lindex $rres 1] 2] 0 ] 1]
98 if {($explen != -1) && ($len != $explen)} {
99 putmsg stderr 0 \
100 "\t Test FAIL: Read returned len=($len), expected=($explen)"
101 putmsg stderr 1 " "
102 return -1
103 }
104 if {("$expeof" != "") && ("$eof" != "$expeof")} {
105 putmsg stderr 0 \
106 "\t Test FAIL: Read returned eof=($eof), expected=($expeof)"
107 putmsg stderr 1 " "
108 return -1
109 }
110 if {$prn == 0} {
111 putmsg stdout 0 "\t Test PASS"
112 }
113 return 0
114 }
115 }