Home | History | Annotate | Line # | Download | only in tmpfs
t_symlink.sh revision 1.1.8.1
      1 # $NetBSD: t_symlink.sh,v 1.1.8.1 2008/05/18 12:36:01 yamt 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 #
     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 symlink and readlink operations work.
     30 #
     31 
     32 atf_test_case file
     33 file_head() {
     34 	atf_set "descr" "Tests that symlinks to files work"
     35 	atf_set "require.user" "root"
     36 }
     37 file_body() {
     38 	test_mount
     39 
     40 	atf_check 'touch a' 0 null null
     41 	atf_check 'ln -s a b' 0 null null
     42 	[ $(md5 b | cut -d ' ' -f 4) = d41d8cd98f00b204e9800998ecf8427e ] || \
     43 	    atf_fail "Symlink points to an incorrect file"
     44 
     45 	atf_check 'echo foo >a' 0 null null
     46 	[ $(md5 b | cut -d ' ' -f 4) = d3b07384d113edec49eaa6238ad5ff00 ] || \
     47 	    atf_fail "Symlink points to an incorrect file"
     48 
     49 	test_unmount
     50 }
     51 
     52 atf_test_case exec
     53 exec_head() {
     54 	atf_set "descr" "Tests symlinking to a known system binary and" \
     55 	                "executing it through the symlink"
     56 	atf_set "require.user" "root"
     57 }
     58 exec_body() {
     59 	test_mount
     60 
     61 	atf_check 'touch b' 0 null null
     62 	atf_check 'ln -s /bin/cp cp' 0 null null
     63 	atf_check './cp b c' 0 null null
     64 	atf_check 'test -f c' 0 null null
     65 
     66 	test_unmount
     67 }
     68 
     69 atf_test_case dir
     70 dir_head() {
     71 	atf_set "descr" "Tests that symlinks to directories work"
     72 	atf_set "require.user" "root"
     73 }
     74 dir_body() {
     75 	test_mount
     76 
     77 	atf_check 'mkdir d' 0 null null
     78 	atf_check 'test -f d/foo' 1 null null
     79 	atf_check 'test -f e/foo' 1 null null
     80 	atf_check 'ln -s d e' 0 null null
     81 	atf_check 'touch d/foo' 0 null null
     82 	atf_check 'test -f d/foo' 0 null null
     83 	atf_check 'test -f e/foo' 0 null null
     84 
     85 	test_unmount
     86 }
     87 
     88 atf_test_case kqueue
     89 kqueue_head() {
     90 	atf_set "descr" "Tests that creating a symlink raises the" \
     91 	                "appropriate kqueue events"
     92 	atf_set "require.user" "root"
     93 }
     94 kqueue_body() {
     95 	test_mount
     96 
     97 	atf_check 'mkdir dir' 0 null null
     98 	echo 'ln -s non-existent dir/a' | kqueue_monitor 1 dir
     99 	kqueue_check dir NOTE_WRITE
    100 	atf_check 'rm dir/a' 0 null null
    101 	atf_check 'rmdir dir' 0 null null
    102 
    103 	test_unmount
    104 }
    105 
    106 atf_init_test_cases() {
    107 	. $(atf_get_srcdir)/../h_funcs.subr
    108 	. $(atf_get_srcdir)/h_funcs.subr
    109 
    110 	atf_add_test_case file
    111 	atf_add_test_case exec
    112 	atf_add_test_case dir
    113 	atf_add_test_case kqueue
    114 }
    115