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 888
50 set open_owner "[pid][clock seconds]"
51 set nfh [basic_open $bfh $TFILE 1 "$cid $open_owner" \
52 osid oseqid status $seqid 0 666 $size 3]
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
60
61 # Start testing
62 # --------------------------------------------------------------
63 # a: Lock w/length=0, expect INVAL
64 set expcode "INVAL"
65 set ASSERTION "Lock w/length=0, expect $expcode"
66 set tag "$TNAME{a}"
67 putmsg stdout 0 "$tag: $ASSERTION"
68 incr oseqid
69 set lseqid 1
70 set res [compound {Putfh $nfh;
71 Lock 2 F 0 0 T $osid $lseqid "$oseqid $cid $open_owner"}]
72 ckres "Lock" $status $expcode $res $PASS
73
74
75 # b: Lock w/offset+length over max, expect INVAL
76 set expcode "INVAL"
77 set ASSERTION "Lock with offset+length over max, expect $expcode"
78 set tag "$TNAME{b}"
79 putmsg stdout 0 "$tag: $ASSERTION"
80 set lseqid 5
81 incr oseqid
82 set halfmax 9300000000000000000
83 set res [compound {Putfh $nfh;
84 Lock 2 F $halfmax $halfmax T $osid $lseqid "$oseqid $cid $open_owner"}]
85 ckres "Lock" $status $expcode $res $PASS
86
87
88 # e: Lockt w/length=0, expect INVAL
89 set expcode "INVAL"
90 set ASSERTION "Lockt w/length=0, expect $expcode"
91 set tag "$TNAME{e}"
92 putmsg stdout 0 "$tag: $ASSERTION"
93 set res [compound {Putfh $nfh; Lockt 2 $cid "lowner.[pid]-b" 1 0}]
94 ckres "Lockt" $status $expcode $res $PASS
95
96
97 # f: Lockt w/offset+length over max, expect INVAL
98 set expcode "INVAL"
99 set ASSERTION "Lockt w/offset+length over max, expect $expcode"
100 set tag "$TNAME{f}"
101 putmsg stdout 0 "$tag: $ASSERTION"
102 set halfmax 9300000000000000000
103 set res [compound {Putfh $nfh;
104 Lockt 2 $cid "lowner.[pid]-b" $halfmax $halfmax }]
105 ckres "Lockt" $status $expcode $res $PASS
106
107
108 putmsg stdout 0 \
109 "\n ** Now downgrade the ($TFILE)) to access=W for following cases;"
110 putmsg stdout 0 \
111 " If fails, assertions(i,j) will not be run."
112 # h: Open_downgrade the file to WRONLY, expect OK
113 set expcode "OK"
114 set ASSERTION "Open_downgrade the file to WRONLY, expect $expcode"
115 set tag "$TNAME{h}"
116 putmsg stdout 0 "$tag: $ASSERTION"
117 incr oseqid
118 set tag "$TNAME-Open_downgrade"
119 set res [compound {Putfh $nfh; Open_downgrade $osid $oseqid 2 0}]
120 if {$status != "OK"} {
121 putmsg stderr 0 \
122 "\t Test UNRESOLVED: Open_downgrade failed status=$status."
123 putmsg stderr 1 "\t Res=$res"
124 } else {
125 logres "PASS"
126
127 # get new stateid from Open_downgrade
128 set osid [lindex [lindex $res 1] 2]
129
130 # i: Try to set a READ Lock, expect OPENMODE
131 set expcode "OPENMODE"
132 set ASSERTION "Try to set a READ Lock, expect $expcode"
133 set tag "$TNAME{i}"
134 putmsg stdout 0 "$tag: $ASSERTION"
135 incr oseqid
136 incr lseqid
137 set res [compound {Putfh $nfh;
138 Lock 1 F 1024 10 T $osid $lseqid "$oseqid $cid $open_owner"}]
139 ckres "Lock(RD)" $status $expcode $res $PASS
140
141 # j: Try to set a READW Lock, expect OPENMODE
142 set expcode "OPENMODE"
143 set ASSERTION "Try to set a READW Lock, expect $expcode"
144 set tag "$TNAME{j}"
145 putmsg stdout 0 "$tag: $ASSERTION"
146 incr oseqid
147 incr lseqid
148 set res [compound {Putfh $nfh;
149 Lock 3 F 512 10 T $osid $lseqid "$oseqid $cid $open_owner"}]
150 ckres "Lock(RDW)" $status $expcode $res $PASS
151 }
152
153
154 putmsg stdout 0 \
155 "\n ** Now Open ($env(ROFILE)) w/out Confirm for the following assertions(n):"
156
157 # m: OPEN a file without confirm for next Lock test, expect OK
158 set expcode "OK"
159 set ASSERTION "OPEN a file without confirm, expect $expcode"
160 set tag "$TNAME{m}"
161 putmsg stdout 0 "$tag: $ASSERTION"
162 set oseqid 100
163 set tag "$TNAME{m}"
164 set open_owner2 "$tag-oowner"
165 set res [compound {Putfh $bfh; Open $oseqid 1 0 "$cid $open_owner2" \
166 {0 0 {{mode 0644}}} {0 $env(ROFILE)}; Getfh}]
167 if {$status != "OK"} {
168 putmsg stderr 0 \
169 "\t Test UNRESOLVED: unable to Open $env(ROFILE)"
170 putmsg stderr 0 "\t\t Assertions(n) will not run"
171 putmsg stderr 1 "\t Res=($res)."
172 } else {
173 logres "PASS"
174 set osid [lindex [lindex $res 1] 2]
175 set nfh [lindex [lindex $res 2] 2]
176
177 # n: Try to lock the file, expect BAD_STATEID
178 set expcode "BAD_STATEID"
179 set ASSERTION "Lock on un-conformed file, expect $expcode"
180 set tag "$TNAME{n}"
181 putmsg stdout 0 "$tag: $ASSERTION"
182 # make sure rflags requires a confirm
183 set rflags [lindex [lindex $res 1] 4]
184 if {[expr $rflags & $OPEN4_RESULT_CONFIRM] == $OPEN4_RESULT_CONFIRM} {
185 incr oseqid
186 set res [compound {Putfh $nfh;
187 Lock 1 F 10 20 T $osid 2 "$oseqid $cid $open_owner"}]
188 ckres "Lock" $status $expcode $res $PASS
189 } else {
190 putmsg stderr 0 \ "\t Test NOTINUSE: no OPEN_CONFIRM is required."
191 }
192 }
193
194
195 # --------------------------------------------------------------
196 # Now cleanup, and removed created tmp file
197 set tag "$TNAME-cleanup"
198 set res [compound {Putfh $bfh; Remove $TFILE}]
199 if {($status != "OK") && ($status != "NOENT")} {
200 putmsg stderr 0 "\t WARNING: cleanup to remove created tmp file failed"
201 putmsg stderr 0 "\t status=$status; please cleanup manually."
202 putmsg stderr 1 "\t res=($res)"
203 putmsg stderr 1 " "
204 exit $WARNING
205 }
206
207 # --------------------------------------------------------------
208 # disconnect and exit
209 Disconnect
210 exit $PASS