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 SETATTR operation test - positive tests
27 # verify setattr to with different attrs and file types
28
29 # include all test enironment
30 source SETATTR.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 # Start testing
40 # --------------------------------------------------------------
41 # a: Setattr of a file w/supported-set'ble attrs, expect OK
42 set expcode "OK"
43 set ASSERTION "Setattr of a file w/none-size attrs, expect $expcode"
44 set tag "$TNAME{a}"
45 putmsg stdout 0 "$tag: $ASSERTION"
46 set newf "Sattr_Fa.[pid]"
47 set ffh [creatv4_file [file join $BASEDIR $newf]]
48 if { $ffh != $NULL } {
49 # now the Setattr test, no change in size w/stateid=0:
50 set stateid {0 0}
51 set ntime "[clock seconds] 0"
52 set attrl "{mode 123} {time_access_set {$ntime}} {time_modify_set 0}"
53 set res [compound {Putfh $ffh; Setattr $stateid {$attrl};
54 Getfh; Getattr {mode time_access type}}]
55 set cont [ckres "Setattr" $status $expcode $res $FAIL]
56 if {$cont == "true"} {
57 set nattrs [lindex [lindex $res 3] 2]
58 foreach al $nattrs {
59 set name [lindex $al 0]
60 set val [lindex $al 1]
61 switch -exact -- $name {
62 mode { if {"$val" != "123"} {
63 putmsg stderr 0 "\t Test FAIL: attr($al) returned unexpected."
64 putmsg stderr 0 "\t expected=(mode=123)"
65 set cont false
66 break
67 } }
68 time_access { if {"$val" != "$ntime"} {
69 putmsg stderr 0 "\t Test FAIL: attr($al) returned unexpected."
70 putmsg stderr 0 "\t expected=(time_access=$ntime)"
71 set cont false
72 break
73 } }
74 type { if {"$val" != "reg"} {
75 putmsg stderr 0 "\t Test FAIL: attr($al) returned unexpected."
76 putmsg stderr 0 "\t expected=(type=reg)"
77 set cont false
78 break
79 } }
80 default {
81 break
82 }
83 }
84 }
85 }
86 } else {
87 putmsg stderr 0 "\t Test UNINITIATED: unable to create temp file."
88 putmsg stderr 1 "\t res=($res)"
89 set cont "false"
90 }
91 # verify FH is not changed after successful Setattr op
92 set fh1 [lindex [lindex $res 2] 2]
93 fh_equal $fh1 $ffh $cont $PASS
94
95
96 # b: Setattr on a dir w/none-size attrs, expect OK
97 set expcode "OK"
98 set ASSERTION "Setattr of a dir w/none-size attrs, expect $expcode"
99 set tag "$TNAME{b}"
100 putmsg stdout 0 "$tag: $ASSERTION"
101 set newd "Sattr_Db.[pid]"
102 set stateid {0 0}
103 set ntime "[clock seconds] 0"
104 set ntime "[string replace $ntime 4 4 8]"
105 set attrl "{mode 751} {time_access_set {$ntime}}"
106 set res [compound {Putfh $bfh; Create $newd {{mode 0751}} d; Getfh;
107 Setattr $stateid {$attrl}; Getfh; Getattr {mode time_access}}]
108 set cont [ckres "Setattr" $status $expcode $res $FAIL]
109 # verify attr returned have good value
110 if {! [string equal $cont "false"]} {
111 set attrs [lindex [lindex $res 5] 2]
112 foreach al $attrs {
113 set name [lindex $al 0]
114 set val [lindex $al 1]
115 switch -exact -- $name {
116 mode { if {"$val" != "751"} {
117 putmsg stderr 0 "\t Test FAIL: attr($al) returned unexpected."
118 putmsg stderr 0 "\t expected=(mode=751)"
119 set cont false
120 break
121 } }
122 default {
123 break
124 }
125 }
126 }
127 }
128 # verify FH is not changed after successful Setattr op
129 set fh1 [lindex [lindex $res 2] 2]
130 set fh2 [lindex [lindex $res 4] 2]
131 fh_equal $fh1 $fh2 $cont $PASS
132
133
134 # c: Setattr on a symlink w/no changes in attrs, expect OK
135 set expcode "OK"
136 set ASSERTION "Setattr of a symlink w/no changes in attrs, expect $expcode"
137 set tag "$TNAME{c}"
138 putmsg stdout 0 "$tag: $ASSERTION"
139 set newl "Sattr_Lc.[pid]"
140 set res [compound {Putfh $bfh; Create $newl {{mode 0666}} l $newd;
141 Getfh; Getattr {mode time_modify}}]
142 set cont [ckres "Getattr" $status $expcode $res $FAIL]
143 # verify attr returned have good value
144 if {! [string equal $cont "false"]} {
145 set lfh [lindex [lindex $res 2] 2]
146 set attrs [lindex [lindex $res 3] 2]
147 # now set the same attributes, but change "time_modify" to set
148 set md [lindex [lindex $attrs 0] 1]
149 set nt [lindex [lindex $attrs 1] 1]
150 set nat "{mode $md} {time_modify_set {$nt}}"
151 set stateid {0 0}
152 set res [compound {Putfh $lfh; Setattr $stateid {$nat};
153 Getfh; Getattr {mode time_modify}}]
154 set cont [ckres "Setattr" $status $expcode $res $FAIL]
155 if {! [string equal $cont "false"]} {
156 set attrl [lindex [lindex $res 3] 2]
157 if {"$attrs" != "$attrl"} {
158 putmsg stderr 0 "\t Test FAIL: attrs != attrl."
159 }
160 }
161 } else {
162 set lfh ""
163 }
164 # verify FH is not changed after successful Setattr op
165 set fh2 [lindex [lindex $res 2] 2]
166 fh_equal $lfh $fh2 $cont $PASS
167
168
169
170 # --------------------------------------------------------------
171 # Final cleanup
172 # cleanup remove the created file/dir
173 set res [compound {Putfh $bfh; Remove $newf; Remove $newd; Remove $newl}]
174 if { "$status" != "OK" } {
175 putmsg stderr 0 "\t WARNING: cleanup to remove created dir failed"
176 putmsg stderr 0 "\t status=$status; please cleanup manually."
177 putmsg stderr 1 "\t res=($res)"
178 putmsg stderr 1 " "
179 exit $WARNING
180 }
181
182 # disconnect and exit
183 Disconnect
184 exit $PASS