t_rmdir.sh revision 1.1 1 1.1 jmmv # $NetBSD: t_rmdir.sh,v 1.1 2007/11/12 15:18:26 jmmv Exp $
2 1.1 jmmv #
3 1.1 jmmv # Copyright (c) 2005, 2006, 2007 The NetBSD Foundation, Inc.
4 1.1 jmmv # All rights reserved.
5 1.1 jmmv #
6 1.1 jmmv # Redistribution and use in source and binary forms, with or without
7 1.1 jmmv # modification, are permitted provided that the following conditions
8 1.1 jmmv # are met:
9 1.1 jmmv # 1. Redistributions of source code must retain the above copyright
10 1.1 jmmv # notice, this list of conditions and the following disclaimer.
11 1.1 jmmv # 2. Redistributions in binary form must reproduce the above copyright
12 1.1 jmmv # notice, this list of conditions and the following disclaimer in the
13 1.1 jmmv # documentation and/or other materials provided with the distribution.
14 1.1 jmmv # 3. All advertising materials mentioning features or use of this software
15 1.1 jmmv # must display the following acknowledgement:
16 1.1 jmmv # This product includes software developed by the NetBSD
17 1.1 jmmv # Foundation, Inc. and its contributors.
18 1.1 jmmv # 4. Neither the name of The NetBSD Foundation nor the names of its
19 1.1 jmmv # contributors may be used to endorse or promote products derived
20 1.1 jmmv # from this software without specific prior written permission.
21 1.1 jmmv #
22 1.1 jmmv # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23 1.1 jmmv # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 1.1 jmmv # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 1.1 jmmv # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26 1.1 jmmv # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 1.1 jmmv # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 1.1 jmmv # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 1.1 jmmv # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 1.1 jmmv # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 1.1 jmmv # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 1.1 jmmv # POSSIBILITY OF SUCH DAMAGE.
33 1.1 jmmv #
34 1.1 jmmv
35 1.1 jmmv #
36 1.1 jmmv # Verifies that rmdir works by creating and removing directories. Also
37 1.1 jmmv # checks multiple error conditions.
38 1.1 jmmv #
39 1.1 jmmv
40 1.1 jmmv atf_test_case mntpt
41 1.1 jmmv mntpt_head() {
42 1.1 jmmv atf_set "descr" "Checks that the mount point cannot be removed"
43 1.1 jmmv atf_set "require.user" "root"
44 1.1 jmmv }
45 1.1 jmmv mntpt_body() {
46 1.1 jmmv test_mount
47 1.1 jmmv
48 1.1 jmmv atf_check "rmdir ${Mount_Point}" 1 null ignore
49 1.1 jmmv
50 1.1 jmmv test_unmount
51 1.1 jmmv }
52 1.1 jmmv
53 1.1 jmmv atf_test_case non_existent
54 1.1 jmmv non_existent_head() {
55 1.1 jmmv atf_set "descr" "Checks that non-existent directories cannot" \
56 1.1 jmmv "be removed"
57 1.1 jmmv atf_set "require.user" "root"
58 1.1 jmmv }
59 1.1 jmmv non_existent_body() {
60 1.1 jmmv test_mount
61 1.1 jmmv
62 1.1 jmmv atf_check 'rmdir non-existent' 1 null ignore
63 1.1 jmmv
64 1.1 jmmv test_unmount
65 1.1 jmmv }
66 1.1 jmmv
67 1.1 jmmv atf_test_case single
68 1.1 jmmv single_head() {
69 1.1 jmmv atf_set "descr" "Checks that removing a single directory works"
70 1.1 jmmv atf_set "require.user" "root"
71 1.1 jmmv }
72 1.1 jmmv single_body() {
73 1.1 jmmv test_mount
74 1.1 jmmv
75 1.1 jmmv atf_check 'mkdir a' 0 null null
76 1.1 jmmv eval $(stat -s ${Mount_Point})
77 1.1 jmmv [ ${st_nlink} = 3 ] || \
78 1.1 jmmv atf_fail "Incorrect number of links after creation"
79 1.1 jmmv atf_check 'rmdir a' 0 null null
80 1.1 jmmv eval $(stat -s ${Mount_Point})
81 1.1 jmmv [ ${st_nlink} = 2 ] || \
82 1.1 jmmv atf_fail "Incorrect number of links after removal"
83 1.1 jmmv
84 1.1 jmmv test_unmount
85 1.1 jmmv }
86 1.1 jmmv
87 1.1 jmmv atf_test_case nested
88 1.1 jmmv nested_head() {
89 1.1 jmmv atf_set "descr" "Checks that removing nested directories works"
90 1.1 jmmv atf_set "require.user" "root"
91 1.1 jmmv }
92 1.1 jmmv nested_body() {
93 1.1 jmmv test_mount
94 1.1 jmmv
95 1.1 jmmv atf_check 'mkdir -p a/b/c' 0 null null
96 1.1 jmmv atf_check 'rmdir a/b/c' 0 null null
97 1.1 jmmv atf_check 'rmdir a/b' 0 null null
98 1.1 jmmv atf_check 'rmdir a' 0 null null
99 1.1 jmmv
100 1.1 jmmv test_unmount
101 1.1 jmmv }
102 1.1 jmmv
103 1.1 jmmv atf_test_case dots
104 1.1 jmmv dots_head() {
105 1.1 jmmv atf_set "descr" "Checks that '.' and '..' cannot be removed"
106 1.1 jmmv atf_set "require.user" "root"
107 1.1 jmmv }
108 1.1 jmmv dots_body() {
109 1.1 jmmv test_mount
110 1.1 jmmv
111 1.1 jmmv atf_check 'mkdir a' 0 null null
112 1.1 jmmv atf_check 'rmdir a/.' 1 null ignore
113 1.1 jmmv atf_check 'rmdir a/..' 1 null ignore
114 1.1 jmmv atf_check 'rmdir a' 0 null null
115 1.1 jmmv
116 1.1 jmmv test_unmount
117 1.1 jmmv }
118 1.1 jmmv
119 1.1 jmmv atf_test_case non_empty
120 1.1 jmmv non_empty_head() {
121 1.1 jmmv atf_set "descr" "Checks that non-empty directories cannot be removed"
122 1.1 jmmv atf_set "require.user" "root"
123 1.1 jmmv }
124 1.1 jmmv non_empty_body() {
125 1.1 jmmv test_mount
126 1.1 jmmv
127 1.1 jmmv atf_check 'mkdir a' 0 null null
128 1.1 jmmv atf_check 'mkdir a/b' 0 null null
129 1.1 jmmv atf_check 'mkdir a/c' 0 null null
130 1.1 jmmv atf_check 'rmdir a' 1 null ignore
131 1.1 jmmv atf_check 'rmdir a/b' 0 null null
132 1.1 jmmv atf_check 'rmdir a/c' 0 null null
133 1.1 jmmv atf_check 'rmdir a' 0 null null
134 1.1 jmmv
135 1.1 jmmv test_unmount
136 1.1 jmmv }
137 1.1 jmmv
138 1.1 jmmv atf_test_case links
139 1.1 jmmv links_head() {
140 1.1 jmmv atf_set "descr" "Checks the root directory's links after removals"
141 1.1 jmmv atf_set "require.user" "root"
142 1.1 jmmv }
143 1.1 jmmv links_body() {
144 1.1 jmmv test_mount
145 1.1 jmmv
146 1.1 jmmv atf_check 'mkdir a' 0 null null
147 1.1 jmmv atf_check 'mkdir a/b' 0 null null
148 1.1 jmmv atf_check 'mkdir c' 0 null null
149 1.1 jmmv
150 1.1 jmmv atf_check 'rmdir c' 0 null null
151 1.1 jmmv atf_check 'rmdir a/b' 0 null null
152 1.1 jmmv atf_check 'rmdir a' 0 null null
153 1.1 jmmv
154 1.1 jmmv eval $(stat -s ${Mount_Point})
155 1.1 jmmv [ ${st_nlink} = 2 ] || atf_fail "Incorrect number of links"
156 1.1 jmmv
157 1.1 jmmv test_unmount
158 1.1 jmmv }
159 1.1 jmmv
160 1.1 jmmv atf_test_case curdir
161 1.1 jmmv curdir_head() {
162 1.1 jmmv atf_set "descr" "Checks that the current directory cannot be removed"
163 1.1 jmmv atf_set "require.user" "root"
164 1.1 jmmv }
165 1.1 jmmv curdir_body() {
166 1.1 jmmv test_mount
167 1.1 jmmv
168 1.1 jmmv atf_check 'mkdir a' 0 null null
169 1.1 jmmv # Catch a bug that would panic the system when accessing the
170 1.1 jmmv # current directory after being deleted: vop_open cannot assume
171 1.1 jmmv # that open files are still linked to a directory.
172 1.1 jmmv atf_check '( cd a && rmdir ../a && ls )' 1 null ignore
173 1.1 jmmv atf_check 'test -e a' 1 null null
174 1.1 jmmv
175 1.1 jmmv test_unmount
176 1.1 jmmv }
177 1.1 jmmv
178 1.1 jmmv atf_test_case kqueue
179 1.1 jmmv kqueue_head() {
180 1.1 jmmv atf_set "descr" "Checks that removing a directory raises the" \
181 1.1 jmmv "correct kqueue events"
182 1.1 jmmv atf_set "require.user" "root"
183 1.1 jmmv }
184 1.1 jmmv kqueue_body() {
185 1.1 jmmv test_mount
186 1.1 jmmv
187 1.1 jmmv atf_check 'mkdir dir' 0 null null
188 1.1 jmmv atf_check 'mkdir dir/a' 0 null null
189 1.1 jmmv echo 'rmdir dir/a' | kqueue_monitor 3 dir dir/a
190 1.1 jmmv kqueue_check dir/a NOTE_DELETE
191 1.1 jmmv kqueue_check dir NOTE_LINK
192 1.1 jmmv kqueue_check dir NOTE_WRITE
193 1.1 jmmv atf_check 'rmdir dir' 0 null null
194 1.1 jmmv
195 1.1 jmmv test_unmount
196 1.1 jmmv }
197 1.1 jmmv
198 1.1 jmmv atf_init_test_cases() {
199 1.1 jmmv . $(atf_get_srcdir)/../h_funcs.subr
200 1.1 jmmv . $(atf_get_srcdir)/h_funcs.subr
201 1.1 jmmv
202 1.1 jmmv atf_add_test_case mntpt
203 1.1 jmmv atf_add_test_case non_existent
204 1.1 jmmv atf_add_test_case single
205 1.1 jmmv atf_add_test_case nested
206 1.1 jmmv atf_add_test_case dots
207 1.1 jmmv atf_add_test_case non_empty
208 1.1 jmmv atf_add_test_case links
209 1.1 jmmv atf_add_test_case curdir
210 1.1 jmmv atf_add_test_case kqueue
211 1.1 jmmv }
212