t_rmdir.sh revision 1.1.8.1 1 # $NetBSD: t_rmdir.sh,v 1.1.8.1 2008/05/18 12:36:01 yamt 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 rmdir works by creating and removing directories. Also
30 # checks multiple error conditions.
31 #
32
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"
37 }
38 mntpt_body() {
39 test_mount
40
41 atf_check "rmdir ${Mount_Point}" 1 null ignore
42
43 test_unmount
44 }
45
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"
51 }
52 non_existent_body() {
53 test_mount
54
55 atf_check 'rmdir non-existent' 1 null ignore
56
57 test_unmount
58 }
59
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"
64 }
65 single_body() {
66 test_mount
67
68 atf_check 'mkdir a' 0 null null
69 eval $(stat -s ${Mount_Point})
70 [ ${st_nlink} = 3 ] || \
71 atf_fail "Incorrect number of links after creation"
72 atf_check 'rmdir a' 0 null null
73 eval $(stat -s ${Mount_Point})
74 [ ${st_nlink} = 2 ] || \
75 atf_fail "Incorrect number of links after removal"
76
77 test_unmount
78 }
79
80 atf_test_case nested
81 nested_head() {
82 atf_set "descr" "Checks that removing nested directories works"
83 atf_set "require.user" "root"
84 }
85 nested_body() {
86 test_mount
87
88 atf_check 'mkdir -p a/b/c' 0 null null
89 atf_check 'rmdir a/b/c' 0 null null
90 atf_check 'rmdir a/b' 0 null null
91 atf_check 'rmdir a' 0 null null
92
93 test_unmount
94 }
95
96 atf_test_case dots
97 dots_head() {
98 atf_set "descr" "Checks that '.' and '..' cannot be removed"
99 atf_set "require.user" "root"
100 }
101 dots_body() {
102 test_mount
103
104 atf_check 'mkdir a' 0 null null
105 atf_check 'rmdir a/.' 1 null ignore
106 atf_check 'rmdir a/..' 1 null ignore
107 atf_check 'rmdir a' 0 null null
108
109 test_unmount
110 }
111
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"
116 }
117 non_empty_body() {
118 test_mount
119
120 atf_check 'mkdir a' 0 null null
121 atf_check 'mkdir a/b' 0 null null
122 atf_check 'mkdir a/c' 0 null null
123 atf_check 'rmdir a' 1 null ignore
124 atf_check 'rmdir a/b' 0 null null
125 atf_check 'rmdir a/c' 0 null null
126 atf_check 'rmdir a' 0 null null
127
128 test_unmount
129 }
130
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"
135 }
136 links_body() {
137 test_mount
138
139 atf_check 'mkdir a' 0 null null
140 atf_check 'mkdir a/b' 0 null null
141 atf_check 'mkdir c' 0 null null
142
143 atf_check 'rmdir c' 0 null null
144 atf_check 'rmdir a/b' 0 null null
145 atf_check 'rmdir a' 0 null null
146
147 eval $(stat -s ${Mount_Point})
148 [ ${st_nlink} = 2 ] || atf_fail "Incorrect number of links"
149
150 test_unmount
151 }
152
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"
157 }
158 curdir_body() {
159 test_mount
160
161 atf_check 'mkdir a' 0 null null
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 '( cd a && rmdir ../a && ls )' 1 null ignore
166 atf_check 'test -e a' 1 null null
167
168 test_unmount
169 }
170
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"
176 }
177 kqueue_body() {
178 test_mount
179
180 atf_check 'mkdir dir' 0 null null
181 atf_check 'mkdir dir/a' 0 null null
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 'rmdir dir' 0 null null
187
188 test_unmount
189 }
190
191 atf_init_test_cases() {
192 . $(atf_get_srcdir)/../h_funcs.subr
193 . $(atf_get_srcdir)/h_funcs.subr
194
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
204 }
205