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 LOCK, LOCKT, LOCKU operation test - negative tests
27 # Verify server returns correct errors with negative requests.
28
29 # include all test enironment
30 source LOCKsid.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 set hid "[pid]-[expr int([expr [expr rand()] * 100000000])]"
39 set cid [getclientid $hid]
40 if {$cid == -1} {
41 putmsg stdout 0 "$TNAME: test setup - getclientid"
42 putmsg stderr 0 "\t Test UNRESOLVED: unable to get clientid"
43 exit $UNRESOLVED
44 }
45 set seqid 1
46
47 # Create a temp test file and get it's filehandle
48 set TFILE "$TNAME.[pid]"
49 set size 999
50 set open_owner $TFILE
51 set nfh [basic_open $bfh $TFILE 1 "$cid $open_owner" \
52 osid oseqid status $seqid 0 666 $size]
53 if {$nfh == -1} {
54 putmsg stdout 0 "$TNAME: test setup - basic_open"
55 putmsg stderr 0 "\t Test UNRESOLVED: failed to create tmp file=($TFILE)"
56 putmsg stderr 0 "\t\t basic_open failed, status=($status)."
57 exit $UNRESOLVED
58 }
59 incr oseqid
60
61
62 # Start testing
63 # --------------------------------------------------------------
64 # a: Lock without setting <cfh>, expect NOFILEHANDLE
65 set expcode "NOFILEHANDLE"
66 set ASSERTION "Lock without setting <cfh>, expect $expcode"
67 set tag "$TNAME{a}"
68 putmsg stdout 0 "$tag: $ASSERTION"
69 set lseqid 1
70 set res [compound {Lock 1 F 0 10 T $osid $lseqid "$oseqid $cid $open_owner"}]
71 ckres "Lock" $status $expcode $res $PASS
72
73
74 # b: Lock with <cfh> is a directory, expect ISDIR|BAD_STATEID
75 set expcode "ISDIR|BAD_STATEID"
76 set ASSERTION "Lock with <cfh> is a directory, expect $expcode"
77 set tag "$TNAME{b}"
78 putmsg stdout 0 "$tag: $ASSERTION"
79 set lseqid 1
80 set res [compound {Putfh $bfh;
81 Lock 1 F 0 10 T $osid $lseqid "$oseqid $cid $open_owner"}]
82 ckres "Lock" $status $expcode $res $PASS
83
84
85 # c: Lock with <cfh> is a symlink, expect INVAL|BAD_STATEID
86 set expcode "INVAL|BAD_STATEID"
87 set ASSERTION "Lock with <cfh> is a symlink, expect $expcode"
88 set tag "$TNAME{c}"
89 putmsg stdout 0 "$tag: $ASSERTION"
90 set lseqid 1
91 set res [compound {Putfh $bfh; Lookup $env(SYMLFILE);
92 Lock 1 F 0 10 T $osid $lseqid "$oseqid $cid $open_owner"}]
93 ckres "Lock" $status $expcode $res $PASS
94
95
96 # Now set a lock in the file for the following Lockt/Locku assertions:
97 putmsg stdout 0 " ** Now Set a WRITE lock to the file,"
98 putmsg stdout 0 " ** for the following assertions(h,i,j, r,s,t)."
99 # d: set new Lock(WR) with osid/oseqid, expect OK
100 set expcode "OK"
101 set ASSERTION "set new Lock(WR) with osid/oseqid, expect $expcode"
102 set tag "$TNAME{d}"
103 putmsg stdout 0 "$tag: $ASSERTION"
104 set res [compound {Putfh $nfh;
105 Lock 2 F 0 10 T $osid $lseqid "$oseqid $cid $open_owner"}]
106 if {$status != "OK"} {
107 putmsg stderr 0 \
108 "\t Test UNRESOLVED: Lock(WR) failed; expected=OK, got=$status"
109 putmsg stderr 0 "\t\t Assertions(r, s) will not run"
110 putmsg stderr 1 "\t\t Res=($res)"
111 } else {
112 logres "PASS"
113 set lsid [lindex [lindex $res 1] 2]
114 incr lseqid
115
116 # h: Lockt without setting <cfh>, expect NOFILEHANDLE
117 set expcode "NOFILEHANDLE"
118 set ASSERTION "Lockt without setting <cfh>, expect $expcode"
119 set tag "$TNAME{h}"
120 putmsg stdout 0 "$tag: $ASSERTION"
121 set res [compound {Lockt 2 $cid "lowner.[pid]-h" 0 10}]
122 ckres "Lockt" $status $expcode $res $PASS
123
124
125 # i: Lockt w/<cfh> is a directory, expect ISDIR|BAD_STATEID
126 set expcode "ISDIR|BAD_STATEID"
127 set ASSERTION "Lockt w/<cfh> is a directory, expect $expcode"
128 set tag "$TNAME{i}"
129 putmsg stdout 0 "$tag: $ASSERTION"
130 set res [compound {Putfh $bfh; Lockt 1 $cid "lowner.[pid]-i" 0 15}]
131 ckres "Lockt" $status $expcode $res $PASS
132
133
134 # j: Lockt w/<cfh> is a FIFO file, expect INVAL|BAD_STATEID
135 set expcode "INVAL|BAD_STATEID"
136 set ASSERTION "Lockt w/<cfh> is a FIFO file, expect $expcode"
137 set tag "$TNAME{j}"
138 putmsg stdout 0 "$tag: $ASSERTION"
139 set res [compound {Putfh $bfh; Lookup $env(FIFOFILE);
140 Lockt 1 $cid "lowner.[pid]-j" 0 15}]
141 ckres "Lockt" $status $expcode $res $PASS
142
143
144 # r: Locku without setting <cfh>, expect NOFILEHANDLE
145 set expcode "NOFILEHANDLE"
146 set ASSERTION "Locku without setting <cfh>, expect $expcode"
147 set tag "$TNAME{r}"
148 putmsg stdout 0 "$tag: $ASSERTION"
149 set res [compound {Locku 3 $lseqid $lsid 0 10}]
150 ckres "Locku" $status $expcode $res $PASS
151 # get new lock-stateid in case test failed and LOCK OK for next assertion:
152 if {$status == "OK"} {
153 set lsid [lindex [lindex $res 1] 2]
154 }
155
156
157 # s: Locku w/<cfh> is a directory, expect ISDIR|BAD_STATEID
158 set expcode "ISDIR|BAD_STATEID"
159 set ASSERTION "Locku w/<cfh> is a directory, expect $expcode"
160 set tag "$TNAME{s}"
161 putmsg stdout 0 "$tag: $ASSERTION"
162 set res [compound {Putfh $bfh; Getattr type; Locku 3 $lseqid $lsid 0 10}]
163 ckres "Locku" $status $expcode $res $PASS
164 # get new lock-stateid in case test failed and LOCKU OK for next assertion:
165 if {$status == "OK"} {
166 set lsid [lindex [lindex $res 2] 2]
167 }
168
169
170 # t: Locku w/<cfh> is a CHAR file, expect INVAL|BAD_STATEID
171 set expcode "INVAL|BAD_STATEID"
172 set ASSERTION "Locku w/<cfh> is a CHAR file, expect $expcode"
173 set tag "$TNAME{t}"
174 putmsg stdout 0 "$tag: $ASSERTION"
175 set res [compound {Putfh $bfh; Lookup $env(CHARFILE); Getattr type;
176 Locku 3 $lseqid $lsid 0 10}]
177 ckres "Locku" $status $expcode $res $PASS
178 # get new lock-stateid in case test failed and LOCKU OK for next assertion:
179 if {$status == "OK"} {
180 set lsid [lindex [lindex $res 3] 2]
181 }
182
183 # v: Locku w/length=0, expect INVAL
184 set expcode "INVAL"
185 set ASSERTION "Locku w/length=0, expect $expcode"
186 set tag "$TNAME{v}"
187 putmsg stdout 0 "$tag: $ASSERTION"
188 set res [compound {Putfh $nfh; Locku 2 $lseqid $lsid 1 0}]
189 ckres "Locku" $status $expcode $res $PASS
190 # get new lock-stateid in case test failed and LOCKU OK for next assertion:
191 if {$status == "OK"} {
192 set lsid [lindex [lindex $res 3] 2]
193 }
194
195 # w: Locku w/offset+length over max, expect INVAL
196 set expcode "INVAL"
197 set ASSERTION "Locku w/offset+length over max, expect $expcode"
198 set tag "$TNAME{w}"
199 putmsg stdout 0 "$tag: $ASSERTION"
200 incr lseqid
201 set halfmax 9300000000000000000
202 set res [compound {Putfh $nfh; Locku 2 $lseqid $lsid $halfmax $halfmax}]
203 ckres "Locku" $status $expcode $res $PASS
204 }
205
206
207 # --------------------------------------------------------------
208 # Now cleanup, and removed created tmp file
209 set tag "$TNAME-cleanup"
210 set res [compound {Putfh $bfh; Remove $TFILE}]
211 if {($status != "OK") && ($status != "NOENT")} {
212 putmsg stderr 0 "\t WARNING: cleanup to remove created tmp file 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 # --------------------------------------------------------------
220 # disconnect and exit
221 Disconnect
222 exit $PASS