1# $NetBSD: t_link.sh,v 1.5 2010/11/07 17:51:18 jmmv Exp $ 2# 3# Copyright (c) 2005, 2006, 2007, 2008 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# 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. 26# 27 28# 29# Verifies that the link operation works. 30# 31 32atf_test_case basic 33basic_head() { 34 atf_set "descr" "Verifies that the link operation works on files" \ 35 "at the top directory" 36 atf_set "require.user" "root" 37} 38basic_body() { 39 test_mount 40 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 49 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" 56 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 62 63 test_unmount 64} 65 66atf_test_case subdirs 67subdirs_head() { 68 atf_set "descr" "Verifies that the link operation works if used" \ 69 "in subdirectories" 70 atf_set "require.user" "root" 71} 72subdirs_body() { 73 test_mount 74 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 78 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" 85 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 92 93 test_unmount 94} 95 96# Begin FreeBSD 97if true; then 98atf_test_case kqueue cleanup 99kqueue_cleanup() { 100 Mount_Point=$(pwd)/mntpt _test_unmount || : 101} 102else 103# End FreeBSD 104atf_test_case kqueue 105# Begin FreeBSD 106fi 107# End FreeBSD 108kqueue_head() { 109 atf_set "descr" "Verifies that creating a link raises the correct" \ 110 "kqueue events" 111 atf_set "require.user" "root" 112} 113kqueue_body() { 114 test_mount 115 116 # Begin FreeBSD 117 atf_expect_fail "fails with: dir/b did not receive NOTE_LINK - bug 213662" 118 # End FreeBSD 119 120 atf_check -s eq:0 -o empty -e empty mkdir dir 121 atf_check -s eq:0 -o empty -e empty touch dir/a 122 echo 'ln dir/a dir/b' | kqueue_monitor 2 dir dir/a 123 kqueue_check dir/a NOTE_LINK 124 kqueue_check dir NOTE_WRITE 125 126 echo 'rm dir/a' | kqueue_monitor 2 dir dir/b 127 # XXX According to the (short) kqueue(2) documentation, the following 128 # should raise a NOTE_LINK but FFS raises a NOTE_DELETE... 129 kqueue_check dir/b NOTE_LINK 130 kqueue_check dir NOTE_WRITE 131 atf_check -s eq:0 -o empty -e empty rm dir/b 132 atf_check -s eq:0 -o empty -e empty rmdir dir 133 134 test_unmount 135} 136 137atf_init_test_cases() { 138 . $(atf_get_srcdir)/../h_funcs.subr 139 . $(atf_get_srcdir)/h_funcs.subr 140 141 atf_add_test_case basic 142 atf_add_test_case subdirs 143 atf_add_test_case kqueue 144} 145