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 fsize 999
50 set open_owner $TFILE
51 set nfh [basic_open $bfh $TFILE 1 "$cid $open_owner" \
52 osid oseqid status $seqid 0 666 $fsize]
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 set oseqid [expr $oseqid + 1]
60
61 # Set a lock(R) in whole file for testing
62 set lowner "[pid].lo"
63 set lseqid 1
64 set ltype 1
65 set res [compound {Putfh $nfh;
66 Lock $ltype F 0 $fsize T $osid $lseqid "$oseqid $cid $lowner"}]
67 if { $status != "OK" } {
68 putmsg stdout 0 "$TNAME: test setup - lock(R) for following testing"
69 putmsg stderr 0 "\t Test UNRESOLVED: Lock() returned status=($status)"
70 putmsg stderr 1 "\t\t Res=($res)"
71 exit $UNRESOLVED
72 }
73 set lsid [lindex [lindex $res 1] 2]
74 set lseqid [expr $lseqid + 1]
75 incr oseqid
76
77
78 # Start testing
79 # --------------------------------------------------------------
80 # a: Lock(W,12,99) with different lowner, expect DENIED
81 set expcode "DENIED"
82 set ASSERTION "Lock(W,12,99) with different lowner, expect $expcode"
83 set tag "$TNAME{a}"
84 putmsg stdout 0 "$tag: $ASSERTION"
85 set lowner2 "$lowner-2"
86 set lseqid2 1
87 set res [compound {Putfh $nfh;
88 Lock 2 F 12 99 T $osid $lseqid2 "$oseqid $cid $lowner2"}]
89 if { $status != "DENIED" } {
90 putmsg stderr 0 "\t Test FAIL: Lock(W) returned status=($status)"
91 putmsg stderr 1 "\t Res=($res)"
92 set exp ""
93 } else {
94 # Check for conflict info
95 set olt [lindex [lindex $res 1] 2]
96 set exp [list 0 $fsize $ltype]
97 if { $olt != $exp } {
98 putmsg stderr 0 \
99 "\t Test FAIL: good return status, but conflict off/len/type incorrect"
100 putmsg stderr 0 "\t exp=($exp), got=($olt)"
101 putmsg stderr 1 "\t Res=($res)"
102 } else {
103 set ncid [lindex [lindex [lindex $res 1] 3] 0]
104 if { $ncid != $cid } {
105 putmsg stderr 0 \
106 "\t Test FAIL: good return status, conflict cid incorrect"
107 putmsg stderr 0 "\t exp=($cid), got=($ncid)"
108 putmsg stderr 1 "\t Res=($res)"
109 } else {
110 logres "PASS"
111 }
112 }
113 }
114
115 # b: Lockt(W) with different lowner, expect DENIED
116 set expcode "DENIED"
117 set ASSERTION "Lockt(W,88,10) with different lowner, expect $expcode"
118 set tag "$TNAME{b}"
119 putmsg stdout 0 "$tag: $ASSERTION"
120 set lowner3 "$lowner-3"
121 set res [compound {Putfh $nfh; Lockt 2 $cid $lowner3 88 10}]
122 if { $status != "DENIED" } {
123 putmsg stderr 0 "\t Test FAIL: Lockt(W) returned status=($status)"
124 putmsg stderr 1 "\t Res=($res)"
125 } else {
126 # Check for conflict info
127 set olt [lindex [lindex $res 1] 2]
128 if { $olt != $exp } {
129 putmsg stderr 0 \
130 "\t Test FAIL: good return status, but conflict off/len/type incorrect"
131 putmsg stderr 0 "\t exp=($exp), got=($olt)"
132 if { $exp == ""} {
133 putmsg stderr 0 \
134 "\t the previous LOCK was not set correctly?"
135 }
136 putmsg stderr 1 "\t Res=($res)"
137 } else {
138 set ncid [lindex [lindex [lindex $res 1] 3] 0]
139 if { $ncid != $cid } {
140 putmsg stderr 0 \
141 "\t Test FAIL: good return status, conflict cid incorrect"
142 putmsg stderr 0 "\t exp=($cid), got=($ncid)"
143 putmsg stderr 1 "\t Res=($res)"
144 } else {
145 logres "PASS"
146 }
147 }
148 }
149
150
151 # --------------------------------------------------------------
152 # Now cleanup, and removed created tmp file
153 set res [compound {Putfh $bfh; Remove $TFILE}]
154 if {($status != "OK") && ($status != "NOENT")} {
155 putmsg stderr 0 "\t WARNING: cleanup to remove created tmp file failed"
156 putmsg stderr 0 "\t status=$status; please cleanup manually."
157 putmsg stderr 1 "\t res=($res)"
158 putmsg stderr 1 " "
159 exit $WARNING
160 }
161
162 # --------------------------------------------------------------
163 # disconnect and exit
164 Disconnect
165 exit $PASS