Expand PMF_FN_* macros.
[netbsd-mini2440.git] / tests / fs / tmpfs / t_mkdir.sh
blobec43bd888de3e34f6539f5eacdac18477e01b10a
1 # $NetBSD: t_mkdir.sh,v 1.2 2008/04/30 13:11:00 martin Exp $
3 # Copyright (c) 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc.
4 # All rights reserved.
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.
15 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 # POSSIBILITY OF SUCH DAMAGE.
29 # Verifies that mkdir works by creating some nested directories. It also
30 # checks, in part, the lookup operation.
33 atf_test_case single
34 single_head() {
35 atf_set "descr" "Creates a single directory and checks the" \
36 "mount point's hard link count"
37 atf_set "require.user" "root"
39 single_body() {
40 test_mount
42 atf_check -s eq:1 -o empty -e empty test -d a
43 atf_check -s eq:0 -o empty -e empty mkdir a
44 atf_check -s eq:0 -o empty -e empty test -d a
45 test -d a
46 eval $(stat -s ${Mount_Point})
47 [ ${st_nlink} = 3 ] || atf_fail "Link count is not 3"
49 test_unmount
52 atf_test_case many
53 many_head() {
54 atf_set "descr" "Creates multiple directories and checks the" \
55 "mount point's hard link count"
56 atf_set "require.user" "root"
58 many_body() {
59 test_mount
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"
69 test_unmount
72 atf_test_case nested
73 nested_head() {
74 atf_set "descr" "Checks if nested directories can be created"
75 atf_set "require.user" "root"
77 nested_body() {
78 test_mount
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
84 test_unmount
87 atf_test_case attrs
88 attrs_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"
94 attrs_body() {
95 # Allow the unprivileged user to access the work directory.
96 chmod 711 .
98 test_mount
100 user=$(atf_config_get unprivileged-user)
102 atf_check -s eq:0 -o empty -e empty mkdir b c
104 atf_check -s eq:0 -o empty -e empty chown ${user}:0 b
105 eval $(stat -s b)
106 [ ${st_uid} -eq $(id -u ${user}) ] || atf_fail "Incorrect owner"
107 [ ${st_gid} -eq 0 ] || atf_fail "Incorrect group"
109 atf_check -s eq:0 -o empty -e empty chown ${user}:100 c
110 eval $(stat -s c)
111 [ ${st_uid} -eq $(id -u ${user}) ] || atf_fail "Incorrect owner"
112 [ ${st_gid} -eq 100 ] || atf_fail "Incorrect group"
114 su ${user} -c 'mkdir b/a'
115 eval $(stat -s b/a)
116 [ ${st_uid} -eq $(id -u ${user}) ] || atf_fail "Incorrect owner"
117 [ ${st_gid} -eq 0 ] || atf_fail "Incorrect group"
119 su ${user} -c 'mkdir c/a'
120 eval $(stat -s c/a)
121 [ ${st_uid} -eq $(id -u ${user}) ] || atf_fail "Incorrect owner"
122 [ ${st_gid} -eq 100 ] || atf_fail "Incorrect group"
124 test_unmount
127 atf_test_case kqueue
128 kqueue_head() {
129 atf_set "descr" "Creates a directory and checks the kqueue events" \
130 "raised"
131 atf_set "require.user" "root"
133 kqueue_body() {
134 test_mount
136 atf_check -s eq:0 -o empty -e empty mkdir dir
137 echo 'mkdir dir/a' | kqueue_monitor 2 dir
139 # Creating a directory raises NOTE_LINK on the parent directory
140 kqueue_check dir NOTE_LINK
142 # Creating a directory raises NOTE_WRITE on the parent directory
143 kqueue_check dir NOTE_WRITE
145 atf_check -s eq:0 -o empty -e empty rmdir dir/a
146 atf_check -s eq:0 -o empty -e empty rmdir dir
148 test_unmount
151 atf_init_test_cases() {
152 . $(atf_get_srcdir)/../h_funcs.subr
153 . $(atf_get_srcdir)/h_funcs.subr
155 atf_add_test_case single
156 atf_add_test_case many
157 atf_add_test_case nested
158 atf_add_test_case attrs
159 atf_add_test_case kqueue