Home | History | Annotate | Line # | Download | only in tmpfs
t_mkdir.sh revision 1.1
      1 # $NetBSD: t_mkdir.sh,v 1.1 2007/11/12 15:18:23 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 mkdir works by creating some nested directories.  It also
     37 # checks, in part, the lookup operation.
     38 #
     39 
     40 atf_test_case single
     41 single_head() {
     42 	atf_set "descr" "Creates a single directory and checks the" \
     43 	                "mount point's hard link count"
     44 	atf_set "require.user" "root"
     45 }
     46 single_body() {
     47 	test_mount
     48 
     49 	atf_check 'test -d a' 1 null null
     50 	atf_check 'mkdir a' 0 null null
     51 	atf_check 'test -d a' 0 null null
     52 	test -d a
     53 	eval $(stat -s ${Mount_Point})
     54 	[ ${st_nlink} = 3 ] || atf_fail "Link count is not 3"
     55 
     56 	test_unmount
     57 }
     58 
     59 atf_test_case many
     60 many_head() {
     61 	atf_set "descr" "Creates multiple directories and checks the" \
     62 	                "mount point's hard link count"
     63 	atf_set "require.user" "root"
     64 }
     65 many_body() {
     66 	test_mount
     67 
     68 	for d in $(jot 100); do
     69 		atf_check "test -d ${d}" 1 null null
     70 		atf_check "mkdir ${d}" 0 null null
     71 		atf_check "test -d ${d}" 0 null null
     72 	done
     73 	eval $(stat -s ${Mount_Point})
     74 	[ ${st_nlink} = 102 ] || atf_fail "Link count is not 102"
     75 
     76 	test_unmount
     77 }
     78 
     79 atf_test_case nested
     80 nested_head() {
     81 	atf_set "descr" "Checks if nested directories can be created"
     82 	atf_set "require.user" "root"
     83 }
     84 nested_body() {
     85 	test_mount
     86 
     87 	atf_check 'test -d a/b/c/d/e' 1 null null
     88 	atf_check 'mkdir -p a/b/c/d/e' 0 null null
     89 	atf_check 'test -d a/b/c/d/e' 0 null null
     90 
     91 	test_unmount
     92 }
     93 
     94 atf_test_case attrs
     95 attrs_head() {
     96 	atf_set "descr" "Checks that new directories get the proper" \
     97 	                "attributes (owner and group)"
     98 	atf_set "require.config" "unprivileged-user"
     99 	atf_set "require.user" "root"
    100 }
    101 attrs_body() {
    102 	# Allow the unprivileged user to access the work directory.
    103 	chmod 711 .
    104 
    105 	test_mount
    106 
    107 	user=$(atf_config_get unprivileged-user)
    108 
    109 	atf_check 'mkdir b c' 0 null null
    110 
    111 	atf_check "chown ${user}:0 b" 0 null null
    112 	eval $(stat -s b)
    113 	[ ${st_uid} -eq $(id -u ${user}) ] || atf_fail "Incorrect owner"
    114 	[ ${st_gid} -eq 0 ] || atf_fail "Incorrect group"
    115 
    116 	atf_check "chown ${user}:100 c" 0 null null
    117 	eval $(stat -s c)
    118 	[ ${st_uid} -eq $(id -u ${user}) ] || atf_fail "Incorrect owner"
    119 	[ ${st_gid} -eq 100 ] || atf_fail "Incorrect group"
    120 
    121 	su ${user} -c 'mkdir b/a'
    122 	eval $(stat -s b/a)
    123 	[ ${st_uid} -eq $(id -u ${user}) ] || atf_fail "Incorrect owner"
    124 	[ ${st_gid} -eq 0 ] || atf_fail "Incorrect group"
    125 
    126 	su ${user} -c 'mkdir c/a'
    127 	eval $(stat -s c/a)
    128 	[ ${st_uid} -eq $(id -u ${user}) ] || atf_fail "Incorrect owner"
    129 	[ ${st_gid} -eq 100 ] || atf_fail "Incorrect group"
    130 
    131 	test_unmount
    132 }
    133 
    134 atf_test_case kqueue
    135 kqueue_head() {
    136 	atf_set "descr" "Creates a directory and checks the kqueue events" \
    137 	                "raised"
    138 	atf_set "require.user" "root"
    139 }
    140 kqueue_body() {
    141 	test_mount
    142 
    143 	atf_check 'mkdir dir' 0 null null
    144 	echo 'mkdir dir/a' | kqueue_monitor 2 dir
    145 
    146 	# Creating a directory raises NOTE_LINK on the parent directory
    147 	kqueue_check dir NOTE_LINK
    148 
    149 	# Creating a directory raises NOTE_WRITE on the parent directory
    150 	kqueue_check dir NOTE_WRITE
    151 
    152 	atf_check 'rmdir dir/a' 0 null null
    153 	atf_check 'rmdir dir' 0 null null
    154 
    155 	test_unmount
    156 }
    157 
    158 atf_init_test_cases() {
    159 	. $(atf_get_srcdir)/../h_funcs.subr
    160 	. $(atf_get_srcdir)/h_funcs.subr
    161 
    162 	atf_add_test_case single
    163 	atf_add_test_case many
    164 	atf_add_test_case nested
    165 	atf_add_test_case attrs
    166 	atf_add_test_case kqueue
    167 }
    168