t_symlink.sh revision 1.4 1 # $NetBSD: t_symlink.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 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 atf_set "use.fs" "true"
37 }
38 file_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 ln -s a b
43 [ $(md5 b | cut -d ' ' -f 4) = d41d8cd98f00b204e9800998ecf8427e ] || \
44 atf_fail "Symlink points to an incorrect file"
45
46 atf_check -s eq:0 -o empty -e empty -x 'echo foo >a'
47 [ $(md5 b | cut -d ' ' -f 4) = d3b07384d113edec49eaa6238ad5ff00 ] || \
48 atf_fail "Symlink points to an incorrect file"
49
50 test_unmount
51 }
52
53 atf_test_case exec
54 exec_head() {
55 atf_set "descr" "Tests symlinking to a known system binary and" \
56 "executing it through the symlink"
57 atf_set "require.user" "root"
58 atf_set "use.fs" "true"
59 }
60 exec_body() {
61 test_mount
62
63 atf_check -s eq:0 -o empty -e empty touch b
64 atf_check -s eq:0 -o empty -e empty ln -s /bin/cp cp
65 atf_check -s eq:0 -o empty -e empty ./cp b c
66 atf_check -s eq:0 -o empty -e empty test -f c
67
68 test_unmount
69 }
70
71 atf_test_case dir
72 dir_head() {
73 atf_set "descr" "Tests that symlinks to directories work"
74 atf_set "require.user" "root"
75 atf_set "use.fs" "true"
76 }
77 dir_body() {
78 test_mount
79
80 atf_check -s eq:0 -o empty -e empty mkdir d
81 atf_check -s eq:1 -o empty -e empty test -f d/foo
82 atf_check -s eq:1 -o empty -e empty test -f e/foo
83 atf_check -s eq:0 -o empty -e empty ln -s d e
84 atf_check -s eq:0 -o empty -e empty touch d/foo
85 atf_check -s eq:0 -o empty -e empty test -f d/foo
86 atf_check -s eq:0 -o empty -e empty test -f e/foo
87
88 test_unmount
89 }
90
91 atf_test_case kqueue
92 kqueue_head() {
93 atf_set "descr" "Tests that creating a symlink raises the" \
94 "appropriate kqueue events"
95 atf_set "require.user" "root"
96 atf_set "use.fs" "true"
97 }
98 kqueue_body() {
99 test_mount
100
101 atf_check -s eq:0 -o empty -e empty mkdir dir
102 echo 'ln -s non-existent dir/a' | kqueue_monitor 1 dir
103 kqueue_check dir NOTE_WRITE
104 atf_check -s eq:0 -o empty -e empty rm dir/a
105 atf_check -s eq:0 -o empty -e empty rmdir dir
106
107 test_unmount
108 }
109
110 atf_init_test_cases() {
111 . $(atf_get_srcdir)/../h_funcs.subr
112 . $(atf_get_srcdir)/h_funcs.subr
113
114 atf_add_test_case file
115 atf_add_test_case exec
116 atf_add_test_case dir
117 atf_add_test_case kqueue
118 }
119