t_mkdir.sh revision 272345
111394Sswallace# $NetBSD: t_mkdir.sh,v 1.8 2011/03/05 07:41:11 pooka Exp $ 2139799Simp# 311394Sswallace# Copyright (c) 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc. 4139799Simp# All rights reserved. 511394Sswallace# 611394Sswallace# Redistribution and use in source and binary forms, with or without 711394Sswallace# modification, are permitted provided that the following conditions 811394Sswallace# are met: 911394Sswallace# 1. Redistributions of source code must retain the above copyright 1011394Sswallace# notice, this list of conditions and the following disclaimer. 1111394Sswallace# 2. Redistributions in binary form must reproduce the above copyright 1211394Sswallace# notice, this list of conditions and the following disclaimer in the 1311394Sswallace# documentation and/or other materials provided with the distribution. 1411394Sswallace# 1511394Sswallace# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 1611394Sswallace# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 1711394Sswallace# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 1811394Sswallace# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 1911394Sswallace# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2011394Sswallace# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2111394Sswallace# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2211394Sswallace# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2311394Sswallace# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2411394Sswallace# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2511394Sswallace# POSSIBILITY OF SUCH DAMAGE. 2611394Sswallace# 2711394Sswallace 2811394Sswallace# 2911394Sswallace# Verifies that mkdir works by creating some nested directories. It also 3011394Sswallace# checks, in part, the lookup operation. 3111394Sswallace# 3211394Sswallace 3311394Sswallaceatf_test_case single 3411394Sswallacesingle_head() { 3511394Sswallace atf_set "descr" "Creates a single directory and checks the" \ 3611394Sswallace "mount point's hard link count" 3711394Sswallace atf_set "require.user" "root" 3811394Sswallace} 3911394Sswallacesingle_body() { 4011394Sswallace test_mount 4111394Sswallace 4211394Sswallace atf_check -s eq:1 -o empty -e empty test -d a 4311394Sswallace atf_check -s eq:0 -o empty -e empty mkdir a 4411394Sswallace atf_check -s eq:0 -o empty -e empty test -d a 4511394Sswallace test -d a 4611394Sswallace eval $(stat -s ${Mount_Point}) 4711394Sswallace [ ${st_nlink} = 3 ] || atf_fail "Link count is not 3" 4811394Sswallace 4911394Sswallace test_unmount 50} 51 52atf_test_case many 53many_head() { 54 atf_set "descr" "Creates multiple directories and checks the" \ 55 "mount point's hard link count" 56 atf_set "require.user" "root" 57} 58many_body() { 59 test_mount 60 61 for d in $(jot 100); do 62 atf_check -s eq:1 -o empty -e empty test -d ${d} 63 atf_check -s eq:0 -o empty -e empty mkdir ${d} 64 atf_check -s eq:0 -o empty -e empty test -d ${d} 65 done 66 eval $(stat -s ${Mount_Point}) 67 [ ${st_nlink} = 102 ] || atf_fail "Link count is not 102" 68 69 test_unmount 70} 71 72atf_test_case nested 73nested_head() { 74 atf_set "descr" "Checks if nested directories can be created" 75 atf_set "require.user" "root" 76} 77nested_body() { 78 test_mount 79 80 atf_check -s eq:1 -o empty -e empty test -d a/b/c/d/e 81 atf_check -s eq:0 -o empty -e empty mkdir -p a/b/c/d/e 82 atf_check -s eq:0 -o empty -e empty test -d a/b/c/d/e 83 84 test_unmount 85} 86 87atf_test_case attrs 88attrs_head() { 89 atf_set "descr" "Checks that new directories get the proper" \ 90 "attributes (owner and group)" 91 atf_set "require.config" "unprivileged-user" 92 atf_set "require.user" "root" 93} 94attrs_body() { 95 user=$(atf_config_get unprivileged-user) 96 # Allow the unprivileged user to access the work directory. 97 chown ${user} . 98 99 test_mount 100 101 atf_check -s eq:0 -o empty -e empty mkdir b c 102 103 atf_check -s eq:0 -o empty -e empty chown ${user}:0 b 104 eval $(stat -s b) 105 [ ${st_uid} -eq $(id -u ${user}) ] || atf_fail "Incorrect owner" 106 [ ${st_gid} -eq 0 ] || atf_fail "Incorrect group" 107 108 atf_check -s eq:0 -o empty -e empty chown ${user}:100 c 109 eval $(stat -s c) 110 [ ${st_uid} -eq $(id -u ${user}) ] || atf_fail "Incorrect owner" 111 [ ${st_gid} -eq 100 ] || atf_fail "Incorrect group" 112 113 atf_check -s eq:0 -o empty -e empty su -m ${user} -c 'mkdir b/a' 114 eval $(stat -s b/a) 115 [ ${st_uid} -eq $(id -u ${user}) ] || atf_fail "Incorrect owner" 116 [ ${st_gid} -eq 0 ] || atf_fail "Incorrect group" 117 118 atf_check -s eq:0 -o empty -e empty su -m ${user} -c 'mkdir c/a' 119 eval $(stat -s c/a) 120 [ ${st_uid} -eq $(id -u ${user}) ] || atf_fail "Incorrect owner" 121 [ ${st_gid} -eq 100 ] || atf_fail "Incorrect group" 122 123 test_unmount 124} 125 126atf_test_case kqueue 127kqueue_head() { 128 atf_set "descr" "Creates a directory and checks the kqueue events" \ 129 "raised" 130 atf_set "require.user" "root" 131} 132kqueue_body() { 133 test_mount 134 135 atf_check -s eq:0 -o empty -e empty mkdir dir 136 echo 'mkdir dir/a' | kqueue_monitor 2 dir 137 138 # Creating a directory raises NOTE_LINK on the parent directory 139 kqueue_check dir NOTE_LINK 140 141 # Creating a directory raises NOTE_WRITE on the parent directory 142 kqueue_check dir NOTE_WRITE 143 144 atf_check -s eq:0 -o empty -e empty rmdir dir/a 145 atf_check -s eq:0 -o empty -e empty rmdir dir 146 147 test_unmount 148} 149 150atf_init_test_cases() { 151 . $(atf_get_srcdir)/../h_funcs.subr 152 . $(atf_get_srcdir)/h_funcs.subr 153 154 atf_add_test_case single 155 atf_add_test_case many 156 atf_add_test_case nested 157 atf_add_test_case attrs 158 atf_add_test_case kqueue 159} 160