1 # $NetBSD: t_link.sh,v 1.2 2008/04/30 13:11:00 martin Exp $
3 # Copyright (c) 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
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 the link operation works.
34 atf_set
"descr" "Verifies that the link operation works on files" \
35 "at the top directory"
36 atf_set
"require.user" "root"
41 atf_check
-s eq
:0 -o empty
-e empty
touch a
42 atf_check
-s eq
:0 -o empty
-e empty
touch z
43 eval $
(stat
-s a |
sed -e 's|st_|sta_|g')
44 eval $
(stat
-s z |
sed -e 's|st_|stz_|g')
45 test ${sta_ino} != ${stz_ino} || \
46 atf_fail
"Node numbers are not different"
47 test ${sta_nlink} -eq 1 || atf_fail
"Number of links is incorrect"
48 atf_check
-s eq
:0 -o empty
-e empty
ln a b
50 echo "Checking if link count is correct after links are created"
51 eval $
(stat
-s a |
sed -e 's|st_|sta_|g')
52 eval $
(stat
-s b |
sed -e 's|st_|stb_|g')
53 test ${sta_ino} = ${stb_ino} || atf_fail
"Node number changed"
54 test ${sta_nlink} -eq 2 || atf_fail
"Link count is incorrect"
55 test ${stb_nlink} -eq 2 || atf_fail
"Link count is incorrect"
57 echo "Checking if link count is correct after links are deleted"
58 atf_check
-s eq
:0 -o empty
-e empty
rm a
59 eval $
(stat
-s b |
sed -e 's|st_|stb_|g')
60 test ${stb_nlink} -eq 1 || atf_fail
"Link count is incorrect"
61 atf_check
-s eq
:0 -o empty
-e empty
rm b
68 atf_set
"descr" "Verifies that the link operation works if used" \
70 atf_set
"require.user" "root"
75 atf_check
-s eq
:0 -o empty
-e empty
touch a
76 atf_check
-s eq
:0 -o empty
-e empty mkdir c
77 atf_check
-s eq
:0 -o empty
-e empty
ln a c
/b
79 echo "Checking if link count is correct after links are created"
80 eval $
(stat
-s a |
sed -e 's|st_|sta_|g')
81 eval $
(stat
-s c
/b |
sed -e 's|st_|stb_|g')
82 test ${sta_ino} = ${stb_ino} || atf_fail
"Node number changed"
83 test ${sta_nlink} -eq 2 || atf_fail
"Link count is incorrect"
84 test ${stb_nlink} -eq 2 || atf_fail
"Link count is incorrect"
86 echo "Checking if link count is correct after links are deleted"
87 atf_check
-s eq
:0 -o empty
-e empty
rm a
88 eval $
(stat
-s c
/b |
sed -e 's|st_|stb_|g')
89 test ${stb_nlink} -eq 1 || atf_fail
"Link count is incorrect"
90 atf_check
-s eq
:0 -o empty
-e empty
rm c
/b
91 atf_check
-s eq
:0 -o empty
-e empty
rmdir c
98 atf_set
"descr" "Verifies that creating a link raises the correct" \
100 atf_set
"require.user" "root"
105 atf_check
-s eq
:0 -o empty
-e empty mkdir dir
106 atf_check
-s eq
:0 -o empty
-e empty
touch dir
/a
107 echo 'ln dir/a dir/b' | kqueue_monitor
2 dir dir
/a
108 kqueue_check dir
/a NOTE_LINK
109 kqueue_check dir NOTE_WRITE
111 echo 'rm dir/a' | kqueue_monitor
2 dir dir
/b
112 # XXX According to the (short) kqueue(2) documentation, the following
113 # should raise a NOTE_LINK but FFS raises a NOTE_DELETE...
114 kqueue_check dir
/b NOTE_LINK
115 kqueue_check dir NOTE_WRITE
116 atf_check
-s eq
:0 -o empty
-e empty
rm dir
/b
117 atf_check
-s eq
:0 -o empty
-e empty
rmdir dir
122 atf_init_test_cases
() {
123 . $
(atf_get_srcdir
)/..
/h_funcs.subr
124 . $
(atf_get_srcdir
)/h_funcs.subr
126 atf_add_test_case basic
127 atf_add_test_case subdirs
128 atf_add_test_case kqueue