1272343Sngie# $NetBSD: t_setattr.sh,v 1.5 2010/11/07 17:51:18 jmmv Exp $
2272343Sngie#
3272343Sngie# Copyright (c) 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc.
4272343Sngie# All rights reserved.
5272343Sngie#
6272343Sngie# Redistribution and use in source and binary forms, with or without
7272343Sngie# modification, are permitted provided that the following conditions
8272343Sngie# are met:
9272343Sngie# 1. Redistributions of source code must retain the above copyright
10272343Sngie#    notice, this list of conditions and the following disclaimer.
11272343Sngie# 2. Redistributions in binary form must reproduce the above copyright
12272343Sngie#    notice, this list of conditions and the following disclaimer in the
13272343Sngie#    documentation and/or other materials provided with the distribution.
14272343Sngie#
15272343Sngie# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16272343Sngie# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17272343Sngie# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18272343Sngie# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19272343Sngie# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20272343Sngie# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21272343Sngie# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22272343Sngie# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23272343Sngie# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24272343Sngie# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25272343Sngie# POSSIBILITY OF SUCH DAMAGE.
26272343Sngie#
27272343Sngie
28272343Sngie#
29272343Sngie# Verifies that the setattr vnode operation works, using several commands
30272343Sngie# that require this function.
31272343Sngie#
32272343Sngie
33272343Sngieatf_test_case chown
34272343Sngiechown_head() {
35272343Sngie	atf_set "descr" "Tests that the file owner can be changed"
36272343Sngie	atf_set "require.user" "root"
37272343Sngie}
38272343Sngiechown_body() {
39272343Sngie	test_mount
40272343Sngie
41272343Sngie	atf_check -s eq:0 -o empty -e empty mkdir own
42272343Sngie	eval $(stat -s own | sed -e 's|st_|ost_|g')
43272343Sngie	atf_check -s eq:0 -o empty -e empty chown 1234 own
44272343Sngie	eval $(stat -s own)
45272343Sngie	[ ${st_uid} -eq 1234 ] || atf_fail "uid was not set"
46272343Sngie	[ ${st_gid} -eq ${ost_gid} ] || atf_fail "gid was modified"
47272343Sngie
48272343Sngie	test_unmount
49272343Sngie}
50272343Sngie
51272343Sngieatf_test_case chown_kqueue
52272343Sngiechown_kqueue_head() {
53272343Sngie	atf_set "descr" "Tests that changing the file owner raises" \
54272343Sngie	                "NOTE_ATTRIB on it"
55272343Sngie	atf_set "require.user" "root"
56272343Sngie}
57272343Sngiechown_kqueue_body() {
58272343Sngie	test_mount
59272343Sngie
60272343Sngie	atf_check -s eq:0 -o empty -e empty mkdir ownq
61272343Sngie	echo 'chown 1234 ownq' | kqueue_monitor 1 ownq
62272343Sngie	kqueue_check ownq NOTE_ATTRIB
63272343Sngie
64272343Sngie	test_unmount
65272343Sngie}
66272343Sngie
67272343Sngieatf_test_case chgrp
68272343Sngiechgrp_head() {
69272343Sngie	atf_set "descr" "Tests that the file group can be changed"
70272343Sngie	atf_set "require.user" "root"
71272343Sngie}
72272343Sngiechgrp_body() {
73272343Sngie	test_mount
74272343Sngie
75272343Sngie	atf_check -s eq:0 -o empty -e empty mkdir grp
76272343Sngie	eval $(stat -s grp | sed -e 's|st_|ost_|g')
77272343Sngie	atf_check -s eq:0 -o empty -e empty chgrp 5678 grp
78272343Sngie	eval $(stat -s grp)
79272343Sngie	[ ${st_uid} -eq ${ost_uid} ] || atf_fail "uid was modified"
80272343Sngie	[ ${st_gid} -eq 5678 ] || atf_fail "gid was not set"
81272343Sngie
82272343Sngie	test_unmount
83272343Sngie}
84272343Sngie
85272343Sngieatf_test_case chgrp_kqueue
86272343Sngiechgrp_kqueue_head() {
87272343Sngie	atf_set "descr" "Tests that changing the file group raises" \
88272343Sngie	                "NOTE_ATTRIB on it"
89272343Sngie	atf_set "require.user" "root"
90272343Sngie}
91272343Sngiechgrp_kqueue_body() {
92272343Sngie	test_mount
93272343Sngie
94272343Sngie	atf_check -s eq:0 -o empty -e empty mkdir grpq
95272343Sngie	echo 'chgrp 1234 grpq' | kqueue_monitor 1 grpq
96272343Sngie	kqueue_check grpq NOTE_ATTRIB
97272343Sngie
98272343Sngie	test_unmount
99272343Sngie}
100272343Sngie
101272343Sngieatf_test_case chowngrp
102272343Sngiechowngrp_head() {
103272343Sngie	atf_set "descr" "Tests that the file owner and group can be" \
104272343Sngie	                "changed at once"
105272343Sngie	atf_set "require.user" "root"
106272343Sngie}
107272343Sngiechowngrp_body() {
108272343Sngie	test_mount
109272343Sngie
110272343Sngie	atf_check -s eq:0 -o empty -e empty mkdir owngrp
111272343Sngie	atf_check -s eq:0 -o empty -e empty chown 1234:5678 owngrp
112272343Sngie	eval $(stat -s owngrp)
113272343Sngie	[ ${st_uid} -eq 1234 ] || atf_fail "uid was not modified"
114272343Sngie	[ ${st_gid} -eq 5678 ] || atf_fail "gid was not modified"
115272343Sngie
116272343Sngie	test_unmount
117272343Sngie}
118272343Sngie
119272343Sngieatf_test_case chowngrp_kqueue
120272343Sngiechowngrp_kqueue_head() {
121272343Sngie	atf_set "descr" "Tests that changing the file owner and group" \
122272343Sngie	                "raises NOTE_ATTRIB on it"
123272343Sngie	atf_set "require.user" "root"
124272343Sngie}
125272343Sngiechowngrp_kqueue_body() {
126272343Sngie	test_mount
127272343Sngie
128272343Sngie	atf_check -s eq:0 -o empty -e empty mkdir owngrpp
129272343Sngie	echo 'chown 1234:5678 owngrpp' | kqueue_monitor 1 owngrpp
130272343Sngie	kqueue_check owngrpp NOTE_ATTRIB
131272343Sngie
132272343Sngie	test_unmount
133272343Sngie}
134272343Sngie
135272343Sngieatf_test_case chmod
136272343Sngiechmod_head() {
137272343Sngie	atf_set "descr" "Tests that the file mode can be changed"
138272343Sngie	atf_set "require.user" "root"
139272343Sngie}
140272343Sngiechmod_body() {
141272343Sngie	test_mount
142272343Sngie
143272343Sngie	atf_check -s eq:0 -o empty -e empty mkdir mode
144272343Sngie	atf_check -s eq:0 -o empty -e empty chmod 0000 mode
145272343Sngie	eval $(stat -s mode)
146272343Sngie	[ ${st_mode} -eq 40000 ] || af_fail "mode was not set"
147272343Sngie
148272343Sngie	test_unmount
149272343Sngie}
150272343Sngie
151272343Sngieatf_test_case chmod_kqueue
152272343Sngiechmod_kqueue_head() {
153272343Sngie	atf_set "descr" "Tests that changing the file mode raises" \
154272343Sngie	                "NOTE_ATTRIB on it"
155272343Sngie	atf_set "require.user" "root"
156272343Sngie}
157272343Sngiechmod_kqueue_body() {
158272343Sngie	test_mount
159272343Sngie
160272343Sngie	atf_check -s eq:0 -o empty -e empty mkdir modeq
161272343Sngie	echo 'chmod 0000 modeq' | kqueue_monitor 1 modeq
162272343Sngie	kqueue_check modeq NOTE_ATTRIB
163272343Sngie
164272343Sngie	test_unmount
165272343Sngie}
166272343Sngie
167272343Sngieatf_test_case chtimes
168272343Sngiechtimes_head() {
169272343Sngie	atf_set "descr" "Tests that file times can be changed"
170272343Sngie	atf_set "require.user" "root"
171272343Sngie}
172272343Sngiechtimes_body() {
173272343Sngie	test_mount
174272343Sngie
175272343Sngie	atf_check -s eq:0 -o empty -e empty mkdir times
176272343Sngie	atf_check -s eq:0 -o empty -e empty \
177272343Sngie	    -x 'TZ=GMT touch -t 200501010101 times'
178272343Sngie	eval $(stat -s times)
179272343Sngie	[ ${st_atime} = ${st_mtime} ] || \
180272343Sngie	    atf_fail "atime does not match mtime"
181272343Sngie	[ ${st_atime} = 1104541260 ] || atf_fail "atime does not match"
182272343Sngie
183272343Sngie	test_unmount
184272343Sngie}
185272343Sngie
186272343Sngieatf_test_case chtimes_kqueue
187272343Sngiechtimes_kqueue_head() {
188272343Sngie	atf_set "descr" "Tests that changing the file times raises" \
189272343Sngie	                "NOTE_ATTRIB on it"
190272343Sngie	atf_set "require.user" "root"
191272343Sngie}
192272343Sngiechtimes_kqueue_body() {
193272343Sngie	test_mount
194272343Sngie
195272343Sngie	atf_check -s eq:0 -o empty -e empty mkdir timesq
196272343Sngie	echo 'touch timesq' | kqueue_monitor 1 timesq
197272343Sngie	kqueue_check timesq NOTE_ATTRIB
198272343Sngie
199272343Sngie	test_unmount
200272343Sngie}
201272343Sngie
202272343Sngieatf_init_test_cases() {
203272343Sngie	. $(atf_get_srcdir)/../h_funcs.subr
204272343Sngie	. $(atf_get_srcdir)/h_funcs.subr
205272343Sngie
206272343Sngie	atf_add_test_case chown
207272343Sngie	atf_add_test_case chown_kqueue
208272343Sngie	atf_add_test_case chgrp
209272343Sngie	atf_add_test_case chgrp_kqueue
210272343Sngie	atf_add_test_case chowngrp
211272343Sngie	atf_add_test_case chowngrp_kqueue
212272343Sngie	atf_add_test_case chmod
213272343Sngie	atf_add_test_case chmod_kqueue
214272343Sngie	atf_add_test_case chtimes
215272343Sngie	atf_add_test_case chtimes_kqueue
216272343Sngie}
217