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