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