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 # NFSv4 WRITE operation test - positive tests
27 # verify writing to a file without Open using different offset/count
28
29 # include all test enironment
30 source WRITE.env
31
32 # connect to the test server
33 Connect
34
35 # setting local variables
36 set TNAME $argv0
37 set bfh [get_fh "$BASEDIRS"]
38
39 # Create a temp file (size 0) for writing
40 set newF "WRfile.[pid]"
41 set tffh [creatv4_file [file join $BASEDIR $newF] 0666 0]
42 if { $tffh == $NULL } {
43 putmsg stdout 0 "$TNAME: test setup - createv4_file"
44 putmsg stderr 0 "\t UNINITIATED: unable to create tmp file, $newF"
45 putmsg stderr 1 " "
46 exit $UNINITIATED
47 }
48
49
50 # Start testing
51 # --------------------------------------------------------------
52 # a: Write 1023 bytes ascii without Open, offset=0 - expect OK
53 set expcode "OK"
54 set ASSERTION "Write 1023 bytes ascii without Open, offset=0, expect $expcode"
55 set tag "$TNAME{a}"
56 putmsg stdout 0 "$tag: $ASSERTION"
57 set count 1023
58 set data [string repeat "a" $count]
59 set stateid {0 0}
60 set res [compound {Putfh $tffh; Write $stateid 0 f a $data; Getfh}]
61 set cont [ckres "Write" $status $expcode $res $FAIL]
62 if {! [string equal $cont "false"]} {
63 set wcnt [lindex [lindex [lindex $res 1] 2] 0]
64 if {$wcnt != $count} {
65 putmsg stderr 0 \
66 "\t Test FAIL: Write returned count=($wcnt), expected=($count)"
67 putmsg stderr 1 "\t res=($res)"
68 set cont false
69 }
70 }
71 # verify FH is not changed after successful Write op
72 set nfh [lindex [lindex $res 2] 2]
73 fh_equal $tffh $nfh $cont $PASS
74
75
76 # b: Write 0 byte ascii without Open, offset=1 - expect OK
77 set expcode "OK"
78 set ASSERTION "Write byte ascii without Open, offset=1, expect $expcode"
79 set tag "$TNAME{b}"
80 putmsg stdout 0 "$tag: $ASSERTION"
81 set count 0
82 set stateid {0 0}
83 set res [compound {Putfh $tffh; Write $stateid 1 f a ""; Getfh}]
84 set cont [ckres "Write" $status $expcode $res $FAIL]
85 if {! [string equal $cont "false"]} {
86 set wcnt [lindex [lindex [lindex $res 1] 2] 0]
87 if {$wcnt != $count} {
88 putmsg stderr 0 \
89 "\t Test FAIL: Write returned count=($wcnt), expected=($count)"
90 putmsg stderr 1 "\t res=($res)"
91 set cont false
92 }
93 }
94 # verify FH is not changed after successful Write op
95 set nfh [lindex [lindex $res 2] 2]
96 fh_equal $tffh $nfh $cont $PASS
97
98
99
100 # c: Write 1025 bytes ascii without Open, offset=fsize - expect OK
101 set expcode "OK"
102 set ASSERTION "Write 1025B ascii without Open, offset=fsize, expect $expcode"
103 set tag "$TNAME{c}"
104 putmsg stdout 0 "$tag: $ASSERTION"
105 # get the size of the file
106 set res [compound {Putfh $tffh; Getattr size}]
107 set fsize [lindex [lindex [lindex [lindex $res 1] 2] 0] 1]
108 set count 1025
109 set data [string repeat "c" $count]
110 set stateid {0 0}
111 set res [compound {Putfh $tffh; Write $stateid $fsize u a $data;
112 Getfh; Commit $fsize $count; Getattr size}]
113 set cont [ckres "Write" $status $expcode $res $FAIL]
114 if {! [string equal $cont "false"]} {
115 set wcnt [lindex [lindex [lindex $res 1] 2] 0]
116 if {$wcnt != $count} {
117 putmsg stderr 0 \
118 "\t Test FAIL: Write returned count=($wcnt), expected=($count)"
119 putmsg stderr 1 "\t res=($res)"
120 set cont false
121 } else {
122 set nfsz [lindex [lindex [lindex [lindex $res 4] 2] 0] 1]
123 set expsz [expr $fsize + $count]
124 if {$nfsz != $expsz} {
125 putmsg stderr 0 \
126 "\t Test FAIL: Write/Commit had fsize=($nfsz), expected=($expsz)"
127 putmsg stderr 1 "\t res=($res)"
128 set cont false
129 }
130 }
131 }
132 # verify FH is not changed after successful Write op
133 set nfh [lindex [lindex $res 2] 2]
134 fh_equal $tffh $nfh $cont $PASS
135
136
137 # d: Write 1024 bytes ascii without Open, offset>fsize - expect OK
138 set expcode "OK"
139 set ASSERTION "Write 1024B ascii without Open, offset>fsize, expect $expcode"
140 set tag "$TNAME{d}"
141 putmsg stdout 0 "$tag: $ASSERTION"
142 # get the size of the file
143 set res [compound {Putfh $tffh; Getattr size}]
144 set fsize [lindex [lindex [lindex [lindex $res 1] 2] 0] 1]
145 set offset [expr $fsize + 2]
146 set count 1024
147 set data [string repeat "d" $count]
148 set stateid {0 0}
149 set res [compound {Putfh $tffh; Write $stateid $offset u a $data;
150 Getfh; Commit $fsize $count; Getattr size}]
151 set cont [ckres "Write" $status $expcode $res $FAIL]
152 if {! [string equal $cont "false"]} {
153 set wcnt [lindex [lindex [lindex $res 1] 2] 0]
154 if {$wcnt != $count} {
155 putmsg stderr 0 \
156 "\t Test FAIL: Write returned count=($wcnt), expected=($count)"
157 putmsg stderr 1 "\t res=($res)"
158 set cont false
159 } else {
160 set nfsz [lindex [lindex [lindex [lindex $res 4] 2] 0] 1]
161 set expsz [expr $offset + $count]
162 if {$nfsz != $expsz} {
163 putmsg stderr 0 \
164 "\t Test FAIL: Write/Commit had fsize=($nfsz), expected=($expsz)"
165 putmsg stderr 1 "\t res=($res)"
166 set cont false
167 }
168 }
169 }
170 # verify FH is not changed after successful Write op
171 set nfh [lindex [lindex $res 2] 2]
172 fh_equal $tffh $nfh $cont $PASS
173
174
175 # e: Write skipping 3 bytes without Open, offset>fsize - expect OK
176 set expcode "OK"
177 set ASSERTION "Write skipping 3B without Open, offset>fsize, expect $expcode"
178 set tag "$TNAME{e}"
179 putmsg stdout 0 "$tag: $ASSERTION"
180 # get the size of the file
181 set res [compound {Putfh $tffh; Getattr size}]
182 set fsize [lindex [lindex [lindex [lindex $res 1] 2] 0] 1]
183 set off [expr $fsize + 1]
184 set off 16
185 set data "EEE"
186 set stateid {0 0}
187 set res [compound {Putfh $tffh; Setattr $stateid {{size $off}};
188 for {set i $off} {$i <= [expr $off + 188]} {set i [expr $i + 16]} \
189 {Write $stateid $i f a $data};
190 Read {0 0} [expr $off + 16] 3; Getfh}]
191 set cont [ckres "Write" $status $expcode $res $FAIL]
192 if {! [string equal $cont "false"]} {
193 # verify data read back
194 set ndata [lindex [lindex [lindex $res end-1] 2] 2]
195 if {! [string equal $data $ndata]} {
196 putmsg stderr 0 \
197 "\t Test FAIL: data read back does not match w/data written"
198 putmsg stderr 0 \
199 "\t server returned ndata=($ndata), expected=($data)"
200 putmsg stderr 1 "\t res=($res)"
201 set cont false
202 }
203 }
204 # verify FH is not changed after successful Write op
205 set nfh [lindex [lindex $res end] 2]
206 fh_equal $tffh $nfh $cont $PASS
207
208 # --------------------------------------------------------------
209 # Cleanup the temp file:
210 set res [compound {Putfh $bfh; Remove $newF}]
211 if { "$status" != "OK" } {
212 putmsg stderr 0 "\t WARNING: cleanup to remove $newF failed"
213 putmsg stderr 0 "\t status=$status; please cleanup manually."
214 putmsg stderr 1 "\t res=($res)"
215 putmsg stderr 1 " "
216 exit $WARNING
217 }
218
219 # disconnect and exit
220 Disconnect
221 exit $PASS