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 CREATE operation test - positive tests
27 # - testing successful creation of directories.
28
29 # include all test enironment
30 source CREATE.env
31
32 # connect to the test server
33 Connect
34
35
36 # setting local variables
37 set TNAME $argv0
38 set bfh [get_fh $BASEDIRS]
39
40 # Start testing
41 # --------------------------------------------------------------
42 # a: create a new dir, expect OK
43 set expcode "OK"
44 set ndir "newtd.[pid]"
45 set ASSERTION "Create a new dir under BASEDIR, expect $expcode"
46 set tag $TNAME{a}
47 putmsg stdout 0 "$tag: $ASSERTION"
48 set res [compound {Putfh $bfh; Create $ndir {{mode 0755}} d;
49 Getfh; Getattr type}]
50 set cont [ckres "Create" $status $expcode $res $FAIL]
51 # verify filehandle from CREATE should be good
52 set cont [verf_fh [lindex [lindex $res 2] 2] $cont $FAIL]
53 if {! [string equal $cont "false"]} {
54 # check new type must be a dir
55 set ntype [lindex [lindex [lindex [lindex $res 3] 2] 0] 1]
56 if { "$ntype" != "dir" } {
57 putmsg stderr 0 "\t Test FAIL: got unexpected type ($ntype)."
58 putmsg stderr 0 "\t expected type is (dir)."
59 putmsg stderr 1 "\t res=($res)"
60 putmsg stderr 1 " "
61 } else {
62 logres PASS
63 }
64 }
65
66
67 # b: create new dirs in several levels, expect OK
68 set expcode "OK"
69 set ASSERTION "Create new dirs in several levels, expect $expcode"
70 set tag $TNAME{b}
71 putmsg stdout 0 "$tag: $ASSERTION"
72 set fh [get_fh "$BASEDIRS $ndir"]
73 foreach nd {nd2 nd3 nd4 nd5} {
74 set res [compound {Putfh $fh; Create $nd {{mode 0775}} d; Getfh}]
75 set cont [ckres "Create" $status $expcode $res $FAIL]
76 if {! [string equal $cont "false"]} {
77 set fh [lindex [lindex $res 2] 2]
78 } else {
79 break
80 }
81 }
82 # verify filehandle from last CREATE should be same as new lookup
83 if {! [string equal $cont "false"]} {
84 set nfh [get_fh "$BASEDIRS $ndir nd2 nd3 nd4 nd5"]
85 fh_equal $fh $nfh $cont $PASS
86 }
87
88
89 # c: create new link under a new dir, expect OK
90 set expcode "OK"
91 set ndr2 "ndr2-[pid]"
92 set nln2 "ndr2-[pid]"
93 set ASSERTION "Create a new link under a new dir, expect $expcode"
94 set tag $TNAME{c}
95 putmsg stdout 0 "$tag: $ASSERTION"
96 set res [compound {Putfh $bfh; Create "$ndr2" {{mode 0755}} d;
97 Getfh; Create "$nln2" {{mode 0644}} l "."; Getfh}]
98 set cont [ckres "Create" $status $expcode $res $FAIL]
99 # Verify CFH changed
100 if {! [string equal $cont "false"]} {
101 set dfh [lindex [lindex $res 2] 2]
102 set sfh [lindex [lindex $res 4] 2]
103 if { [fh_equal $dfh $sfh $cont $FAIL] } {
104 putmsg stderr 0 "\t Test FAIL: CFH wasn't changed after Create."
105 putmsg stderr 1 "\t dfh=($dfh)"
106 putmsg stderr 1 "\t sfh=($sfh)"
107 putmsg stderr 1 " "
108 } else {
109 logres PASS
110 }
111 }
112
113
114 # d: create a new dir with space in name, expect OK
115 set expcode "OK"
116 set sdir "special [pid] name"
117 set ASSERTION "Create a new dir with space in name, expect $expcode"
118 set tag $TNAME{d}
119 putmsg stdout 0 "$tag: $ASSERTION"
120 set res [compound {Putfh $bfh; Getfh; Create "$sdir" {{mode 0711}} d; Getfh}]
121 set cont [ckres "Create" $status $expcode $res $FAIL]
122 # Verify CFH changed
123 if {! [string equal $cont "false"]} {
124 set dfh [lindex [lindex $res 1] 2]
125 set sfh [lindex [lindex $res 3] 2]
126 if { [fh_equal $dfh $sfh $cont $FAIL] } {
127 putmsg stderr 0 "\t Test FAIL: CFH wasn't changed after Create."
128 putmsg stderr 1 "\t dfh=($dfh)"
129 putmsg stderr 1 "\t sfh=($sfh)"
130 putmsg stderr 1 " "
131 } else {
132 logres PASS
133 }
134 }
135
136
137 # e: create a new dir with special attrs, expect OK
138 set expcode "OK"
139 set atdir "mkdir_attr.[pid]"
140 set ASSERTION "Verify new dir created attributes, expect $expcode"
141 set tag $TNAME{e}
142 putmsg stdout 0 "$tag: $ASSERTION"
143 set time_mod "[expr [clock seconds] - 218] 0"
144 set mode 567
145 set cklist "mode time_modify"
146 set res [compound {Putfh $bfh;
147 Create "$atdir" {{mode $mode} {time_modify_set {$time_mod}}} d;
148 Getattr {$cklist}; Getfh}]
149 set cont [ckres "Create" $status $expcode $res $FAIL]
150 if {! [string equal $cont "false"]} {
151 # Verify attributes set correctly
152 set cattr [lindex [lindex [lindex $res 1] 2] 3]
153 if {([lsearch -exact $cattr "mode"] < 0) && \
154 ([lsearch -exact $cattr "time_modify"] < 0)} {
155 putmsg stderr 0 "\t Test FAIL: Create didn't return the set attrs."
156 putmsg stderr 1 "\t cattr=($cattr)"
157 putmsg stderr 2 "\t res=($res)"
158 putmsg stderr 1 " "
159 } else {
160 # Verify attributes set correctly
161 set slist [lindex [lindex $res 2] 2]
162 foreach a $cklist {
163 set nval [extract_attr $slist $a]
164 if {("$a" == "mode") && ($nval != $mode)} {
165 putmsg stderr 0 "\t Test FAIL: attrs($a) not set correctly."
166 putmsg stderr 1 "\t slist=($slist)"
167 putmsg stderr 1 " "
168 break
169 } else {
170 if {("$a" == "time_modify") && ("$nval" != "$time_mod")} {
171 putmsg stderr 0 "\t Test FAIL: attrs($a) not set correctly."
172 putmsg stderr 1 "\t slist=($slist)"
173 putmsg stderr 1 " "
174 break
175 }
176 }
177 }
178 logres PASS
179 }
180 }
181
182
183 # --------------------------------------------------------------
184 # Final cleanup
185 # cleanup remove the created dir
186 set res [compound {Putfh $nfh; Lookupp; Remove nd5;
187 Lookupp; Remove nd4; Lookupp; Remove nd3; Lookupp; Remove nd2;
188 Lookupp; Remove $ndir;
189 Lookup $ndr2; Remove $nln2; Putfh $bfh; Remove $ndr2;
190 Putfh $bfh; Remove $sdir; Putfh $bfh; Remove $atdir}]
191 if { ("$status" != "OK") && ("$status" != "NOENT") } {
192 putmsg stderr 0 "\t WARNING: cleanup to remove created dir failed"
193 putmsg stderr 0 "\t status=$status; please cleanup manually."
194 putmsg stderr 1 "\t res=($res)"
195 putmsg stderr 1 " "
196 exit $WARNING
197 }
198
199
200 # disconnect and exit
201 Disconnect
202 exit $PASS