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.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
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.
35 atf_set
"descr" "Checks that the mount point cannot be removed"
36 atf_set
"require.user" "root"
41 atf_check
-s eq
:1 -o empty
-e ignore
rmdir ${Mount_Point}
46 atf_test_case non_existent
48 atf_set
"descr" "Checks that non-existent directories cannot" \
50 atf_set
"require.user" "root"
55 atf_check
-s eq
:1 -o empty
-e ignore
rmdir non-existent
62 atf_set
"descr" "Checks that removing a single directory works"
63 atf_set
"require.user" "root"
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"
82 atf_set
"descr" "Checks that removing nested directories works"
83 atf_set
"require.user" "root"
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
98 atf_set
"descr" "Checks that '.' and '..' cannot be removed"
99 atf_set
"require.user" "root"
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
112 atf_test_case non_empty
114 atf_set
"descr" "Checks that non-empty directories cannot be removed"
115 atf_set
"require.user" "root"
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
133 atf_set
"descr" "Checks the root directory's links after removals"
134 atf_set
"require.user" "root"
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"
155 atf_set
"descr" "Checks that the current directory cannot be removed"
156 atf_set
"require.user" "root"
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
173 atf_set
"descr" "Checks that removing a directory raises the" \
174 "correct kqueue events"
175 atf_set
"require.user" "root"
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
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