xref: /netbsd-src/tests/fs/tmpfs/t_setattr.sh (revision 404fbe5fb94ca1e054339640cabb2801ce52dd30)
1# $NetBSD: t_setattr.sh,v 1.2 2008/04/30 13:11:00 martin Exp $
2#
3# Copyright (c) 2005, 2006, 2007 The NetBSD Foundation, Inc.
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9# 1. Redistributions of source code must retain the above copyright
10#    notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright
12#    notice, this list of conditions and the following disclaimer in the
13#    documentation and/or other materials provided with the distribution.
14#
15# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25# POSSIBILITY OF SUCH DAMAGE.
26#
27
28#
29# Verifies that the setattr vnode operation works, using several commands
30# that require this function.
31#
32
33atf_test_case chown
34chown_head() {
35	atf_set "descr" "Tests that the file owner can be changed"
36	atf_set "require.user" "root"
37}
38chown_body() {
39	test_mount
40
41	atf_check 'mkdir own' 0 null null
42	eval $(stat -s own | sed -e 's|st_|ost_|g')
43	atf_check 'chown 1234 own' 0 null null
44	eval $(stat -s own)
45	[ ${st_uid} -eq 1234 ] || atf_fail "uid was not set"
46	[ ${st_gid} -eq ${ost_gid} ] || atf_fail "gid was modified"
47
48	test_unmount
49}
50
51atf_test_case chown_kqueue
52chown_kqueue_head() {
53	atf_set "descr" "Tests that changing the file owner raises" \
54	                "NOTE_ATTRIB on it"
55	atf_set "require.user" "root"
56}
57chown_kqueue_body() {
58	test_mount
59
60	atf_check 'mkdir ownq' 0 null null
61	echo 'chown 1234 ownq' | kqueue_monitor 1 ownq
62	kqueue_check ownq NOTE_ATTRIB
63
64	test_unmount
65}
66
67atf_test_case chgrp
68chgrp_head() {
69	atf_set "descr" "Tests that the file group can be changed"
70	atf_set "require.user" "root"
71}
72chgrp_body() {
73	test_mount
74
75	atf_check 'mkdir grp' 0 null null
76	eval $(stat -s grp | sed -e 's|st_|ost_|g')
77	atf_check 'chgrp 5678 grp' 0 null null
78	eval $(stat -s grp)
79	[ ${st_uid} -eq ${ost_uid} ] || atf_fail "uid was modified"
80	[ ${st_gid} -eq 5678 ] || atf_fail "gid was not set"
81
82	test_unmount
83}
84
85atf_test_case chgrp_kqueue
86chgrp_kqueue_head() {
87	atf_set "descr" "Tests that changing the file group raises" \
88	                "NOTE_ATTRIB on it"
89	atf_set "require.user" "root"
90}
91chgrp_kqueue_body() {
92	test_mount
93
94	atf_check 'mkdir grpq' 0 null null
95	echo 'chgrp 1234 grpq' | kqueue_monitor 1 grpq
96	kqueue_check grpq NOTE_ATTRIB
97
98	test_unmount
99}
100
101atf_test_case chowngrp
102chowngrp_head() {
103	atf_set "descr" "Tests that the file owner and group can be" \
104	                "changed at once"
105	atf_set "require.user" "root"
106}
107chowngrp_body() {
108	test_mount
109
110	atf_check 'mkdir owngrp' 0 null null
111	atf_check 'chown 1234:5678 owngrp' 0 null null
112	eval $(stat -s owngrp)
113	[ ${st_uid} -eq 1234 ] || atf_fail "uid was not modified"
114	[ ${st_gid} -eq 5678 ] || atf_fail "gid was not modified"
115
116	test_unmount
117}
118
119atf_test_case chowngrp_kqueue
120chowngrp_kqueue_head() {
121	atf_set "descr" "Tests that changing the file owner and group" \
122	                "raises NOTE_ATTRIB on it"
123	atf_set "require.user" "root"
124}
125chowngrp_kqueue_body() {
126	test_mount
127
128	atf_check 'mkdir owngrpp' 0 null null
129	echo 'chown 1234:5678 owngrpp' | kqueue_monitor 1 owngrpp
130	kqueue_check owngrpp NOTE_ATTRIB
131
132	test_unmount
133}
134
135atf_test_case chmod
136chmod_head() {
137	atf_set "descr" "Tests that the file mode can be changed"
138	atf_set "require.user" "root"
139}
140chmod_body() {
141	test_mount
142
143	atf_check 'mkdir mode' 0 null null
144	atf_check 'chmod 0000 mode' 0 null null
145	eval $(stat -s mode)
146	[ ${st_mode} -eq 40000 ] || af_fail "mode was not set"
147
148	test_unmount
149}
150
151atf_test_case chmod_kqueue
152chmod_kqueue_head() {
153	atf_set "descr" "Tests that changing the file mode raises" \
154	                "NOTE_ATTRIB on it"
155	atf_set "require.user" "root"
156}
157chmod_kqueue_body() {
158	test_mount
159
160	atf_check 'mkdir modeq' 0 null null
161	echo 'chmod 0000 modeq' | kqueue_monitor 1 modeq
162	kqueue_check modeq NOTE_ATTRIB
163
164	test_unmount
165}
166
167atf_test_case chtimes
168chtimes_head() {
169	atf_set "descr" "Tests that file times can be changed"
170	atf_set "require.user" "root"
171}
172chtimes_body() {
173	test_mount
174
175	atf_check 'mkdir times' 0 null null
176	atf_check 'TZ=GMT touch -t 200501010101 times' 0 null null
177	eval $(stat -s times)
178	[ ${st_atime} = ${st_mtime} ] || \
179	    atf_fail "atime does not match mtime"
180	[ ${st_atime} = 1104541260 ] || atf_fail "atime does not match"
181
182	test_unmount
183}
184
185atf_test_case chtimes_kqueue
186chtimes_kqueue_head() {
187	atf_set "descr" "Tests that changing the file times raises" \
188	                "NOTE_ATTRIB on it"
189	atf_set "require.user" "root"
190}
191chtimes_kqueue_body() {
192	test_mount
193
194	atf_check 'mkdir timesq' 0 null null
195	echo 'touch timesq' | kqueue_monitor 1 timesq
196	kqueue_check timesq NOTE_ATTRIB
197
198	test_unmount
199}
200
201atf_init_test_cases() {
202	. $(atf_get_srcdir)/../h_funcs.subr
203	. $(atf_get_srcdir)/h_funcs.subr
204
205	atf_add_test_case chown
206	atf_add_test_case chown_kqueue
207	atf_add_test_case chgrp
208	atf_add_test_case chgrp_kqueue
209	atf_add_test_case chowngrp
210	atf_add_test_case chowngrp_kqueue
211	atf_add_test_case chmod
212	atf_add_test_case chmod_kqueue
213	atf_add_test_case chtimes
214	atf_add_test_case chtimes_kqueue
215}
216