1# $NetBSD: t_link.sh,v 1.4 2010/06/04 08:39:40 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 atf_set "use.fs" "true" 38} 39basic_body() { 40 test_mount 41 42 atf_check -s eq:0 -o empty -e empty touch a 43 atf_check -s eq:0 -o empty -e empty touch z 44 eval $(stat -s a | sed -e 's|st_|sta_|g') 45 eval $(stat -s z | sed -e 's|st_|stz_|g') 46 test ${sta_ino} != ${stz_ino} || \ 47 atf_fail "Node numbers are not different" 48 test ${sta_nlink} -eq 1 || atf_fail "Number of links is incorrect" 49 atf_check -s eq:0 -o empty -e empty ln a b 50 51 echo "Checking if link count is correct after links are created" 52 eval $(stat -s a | sed -e 's|st_|sta_|g') 53 eval $(stat -s b | sed -e 's|st_|stb_|g') 54 test ${sta_ino} = ${stb_ino} || atf_fail "Node number changed" 55 test ${sta_nlink} -eq 2 || atf_fail "Link count is incorrect" 56 test ${stb_nlink} -eq 2 || atf_fail "Link count is incorrect" 57 58 echo "Checking if link count is correct after links are deleted" 59 atf_check -s eq:0 -o empty -e empty rm a 60 eval $(stat -s b | sed -e 's|st_|stb_|g') 61 test ${stb_nlink} -eq 1 || atf_fail "Link count is incorrect" 62 atf_check -s eq:0 -o empty -e empty rm b 63 64 test_unmount 65} 66 67atf_test_case subdirs 68subdirs_head() { 69 atf_set "descr" "Verifies that the link operation works if used" \ 70 "in subdirectories" 71 atf_set "require.user" "root" 72 atf_set "use.fs" "true" 73} 74subdirs_body() { 75 test_mount 76 77 atf_check -s eq:0 -o empty -e empty touch a 78 atf_check -s eq:0 -o empty -e empty mkdir c 79 atf_check -s eq:0 -o empty -e empty ln a c/b 80 81 echo "Checking if link count is correct after links are created" 82 eval $(stat -s a | sed -e 's|st_|sta_|g') 83 eval $(stat -s c/b | sed -e 's|st_|stb_|g') 84 test ${sta_ino} = ${stb_ino} || atf_fail "Node number changed" 85 test ${sta_nlink} -eq 2 || atf_fail "Link count is incorrect" 86 test ${stb_nlink} -eq 2 || atf_fail "Link count is incorrect" 87 88 echo "Checking if link count is correct after links are deleted" 89 atf_check -s eq:0 -o empty -e empty rm a 90 eval $(stat -s c/b | sed -e 's|st_|stb_|g') 91 test ${stb_nlink} -eq 1 || atf_fail "Link count is incorrect" 92 atf_check -s eq:0 -o empty -e empty rm c/b 93 atf_check -s eq:0 -o empty -e empty rmdir c 94 95 test_unmount 96} 97 98atf_test_case kqueue 99kqueue_head() { 100 atf_set "descr" "Verifies that creating a link raises the correct" \ 101 "kqueue events" 102 atf_set "require.user" "root" 103 atf_set "use.fs" "true" 104} 105kqueue_body() { 106 test_mount 107 108 atf_check -s eq:0 -o empty -e empty mkdir dir 109 atf_check -s eq:0 -o empty -e empty touch dir/a 110 echo 'ln dir/a dir/b' | kqueue_monitor 2 dir dir/a 111 kqueue_check dir/a NOTE_LINK 112 kqueue_check dir NOTE_WRITE 113 114 echo 'rm dir/a' | kqueue_monitor 2 dir dir/b 115 # XXX According to the (short) kqueue(2) documentation, the following 116 # should raise a NOTE_LINK but FFS raises a NOTE_DELETE... 117 kqueue_check dir/b NOTE_LINK 118 kqueue_check dir NOTE_WRITE 119 atf_check -s eq:0 -o empty -e empty rm dir/b 120 atf_check -s eq:0 -o empty -e empty rmdir dir 121 122 test_unmount 123} 124 125atf_init_test_cases() { 126 . $(atf_get_srcdir)/../h_funcs.subr 127 . $(atf_get_srcdir)/h_funcs.subr 128 129 atf_add_test_case basic 130 atf_add_test_case subdirs 131 atf_add_test_case kqueue 132} 133