Expand PMF_FN_* macros.
[netbsd-mini2440.git] / tests / fs / tmpfs / t_rmdir.sh
blobcf69d17f1753a0e0b2342472fc4fd4de1e87f2ed
1 # $NetBSD: t_rmdir.sh,v 1.2 2008/04/30 13:11:00 martin Exp $
3 # Copyright (c) 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc.
4 # All rights reserved.
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.
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.
29 # Verifies that rmdir works by creating and removing directories. Also
30 # checks multiple error conditions.
33 atf_test_case mntpt
34 mntpt_head() {
35 atf_set "descr" "Checks that the mount point cannot be removed"
36 atf_set "require.user" "root"
38 mntpt_body() {
39 test_mount
41 atf_check -s eq:1 -o empty -e ignore rmdir ${Mount_Point}
43 test_unmount
46 atf_test_case non_existent
47 non_existent_head() {
48 atf_set "descr" "Checks that non-existent directories cannot" \
49 "be removed"
50 atf_set "require.user" "root"
52 non_existent_body() {
53 test_mount
55 atf_check -s eq:1 -o empty -e ignore rmdir non-existent
57 test_unmount
60 atf_test_case single
61 single_head() {
62 atf_set "descr" "Checks that removing a single directory works"
63 atf_set "require.user" "root"
65 single_body() {
66 test_mount
68 atf_check -s eq:0 -o empty -e empty mkdir a
69 eval $(stat -s ${Mount_Point})
70 [ ${st_nlink} = 3 ] || \
71 atf_fail "Incorrect number of links after creation"
72 atf_check -s eq:0 -o empty -e empty rmdir a
73 eval $(stat -s ${Mount_Point})
74 [ ${st_nlink} = 2 ] || \
75 atf_fail "Incorrect number of links after removal"
77 test_unmount
80 atf_test_case nested
81 nested_head() {
82 atf_set "descr" "Checks that removing nested directories works"
83 atf_set "require.user" "root"
85 nested_body() {
86 test_mount
88 atf_check -s eq:0 -o empty -e empty mkdir -p a/b/c
89 atf_check -s eq:0 -o empty -e empty rmdir a/b/c
90 atf_check -s eq:0 -o empty -e empty rmdir a/b
91 atf_check -s eq:0 -o empty -e empty rmdir a
93 test_unmount
96 atf_test_case dots
97 dots_head() {
98 atf_set "descr" "Checks that '.' and '..' cannot be removed"
99 atf_set "require.user" "root"
101 dots_body() {
102 test_mount
104 atf_check -s eq:0 -o empty -e empty mkdir a
105 atf_check -s eq:1 -o empty -e ignore rmdir a/.
106 atf_check -s eq:1 -o empty -e ignore rmdir a/..
107 atf_check -s eq:0 -o empty -e empty rmdir a
109 test_unmount
112 atf_test_case non_empty
113 non_empty_head() {
114 atf_set "descr" "Checks that non-empty directories cannot be removed"
115 atf_set "require.user" "root"
117 non_empty_body() {
118 test_mount
120 atf_check -s eq:0 -o empty -e empty mkdir a
121 atf_check -s eq:0 -o empty -e empty mkdir a/b
122 atf_check -s eq:0 -o empty -e empty mkdir a/c
123 atf_check -s eq:1 -o empty -e ignore rmdir a
124 atf_check -s eq:0 -o empty -e empty rmdir a/b
125 atf_check -s eq:0 -o empty -e empty rmdir a/c
126 atf_check -s eq:0 -o empty -e empty rmdir a
128 test_unmount
131 atf_test_case links
132 links_head() {
133 atf_set "descr" "Checks the root directory's links after removals"
134 atf_set "require.user" "root"
136 links_body() {
137 test_mount
139 atf_check -s eq:0 -o empty -e empty mkdir a
140 atf_check -s eq:0 -o empty -e empty mkdir a/b
141 atf_check -s eq:0 -o empty -e empty mkdir c
143 atf_check -s eq:0 -o empty -e empty rmdir c
144 atf_check -s eq:0 -o empty -e empty rmdir a/b
145 atf_check -s eq:0 -o empty -e empty rmdir a
147 eval $(stat -s ${Mount_Point})
148 [ ${st_nlink} = 2 ] || atf_fail "Incorrect number of links"
150 test_unmount
153 atf_test_case curdir
154 curdir_head() {
155 atf_set "descr" "Checks that the current directory cannot be removed"
156 atf_set "require.user" "root"
158 curdir_body() {
159 test_mount
161 atf_check -s eq:0 -o empty -e empty mkdir a
162 # Catch a bug that would panic the system when accessing the
163 # current directory after being deleted: vop_open cannot assume
164 # that open files are still linked to a directory.
165 atf_check -s eq:1 -o empty -e ignore -x '( cd a && rmdir ../a && ls )'
166 atf_check -s eq:1 -o empty -e empty test -e a
168 test_unmount
171 atf_test_case kqueue
172 kqueue_head() {
173 atf_set "descr" "Checks that removing a directory raises the" \
174 "correct kqueue events"
175 atf_set "require.user" "root"
177 kqueue_body() {
178 test_mount
180 atf_check -s eq:0 -o empty -e empty mkdir dir
181 atf_check -s eq:0 -o empty -e empty mkdir dir/a
182 echo 'rmdir dir/a' | kqueue_monitor 3 dir dir/a
183 kqueue_check dir/a NOTE_DELETE
184 kqueue_check dir NOTE_LINK
185 kqueue_check dir NOTE_WRITE
186 atf_check -s eq:0 -o empty -e empty rmdir dir
188 test_unmount
191 atf_init_test_cases() {
192 . $(atf_get_srcdir)/../h_funcs.subr
193 . $(atf_get_srcdir)/h_funcs.subr
195 atf_add_test_case mntpt
196 atf_add_test_case non_existent
197 atf_add_test_case single
198 atf_add_test_case nested
199 atf_add_test_case dots
200 atf_add_test_case non_empty
201 atf_add_test_case links
202 atf_add_test_case curdir
203 atf_add_test_case kqueue