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