Home | History | Annotate | Line # | Download | only in tmpfs
      1 # $NetBSD: t_symlink.sh,v 1.6 2024/04/28 07:27:41 rillig 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 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 -s exit:0 -o empty -e empty touch a
     41 	atf_check -s exit:0 -o empty -e empty ln -s a b
     42 	[ $(md5 b | cut -d ' ' -f 4) = d41d8cd98f00b204e9800998ecf8427e ] || \
     43 	    atf_fail "Symlink points to an incorrect file"
     44 
     45 	atf_check -s exit:0 -o empty -e empty -x 'echo foo >a'
     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 -s exit:0 -o empty -e empty touch b
     62 	atf_check -s exit:0 -o empty -e empty ln -s /bin/cp cp
     63 	atf_check -s exit:0 -o empty -e empty ./cp b c
     64 	atf_check -s exit:0 -o empty -e empty test -f c
     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 -s exit:0 -o empty -e empty mkdir d
     78 	atf_check -s exit:1 -o empty -e empty test -f d/foo
     79 	atf_check -s exit:1 -o empty -e empty test -f e/foo
     80 	atf_check -s exit:0 -o empty -e empty ln -s d e
     81 	atf_check -s exit:0 -o empty -e empty touch d/foo
     82 	atf_check -s exit:0 -o empty -e empty test -f d/foo
     83 	atf_check -s exit:0 -o empty -e empty test -f e/foo
     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 -s exit:0 -o empty -e empty mkdir dir
     98 	echo 'ln -s non-existent dir/a' | kqueue_monitor 1 dir
     99 	kqueue_check dir NOTE_WRITE
    100 	atf_check -s exit:0 -o empty -e empty rm dir/a
    101 	atf_check -s exit:0 -o empty -e empty rmdir dir
    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