xref: /netbsd-src/tests/fs/tmpfs/t_symlink.sh (revision 8b0f9554ff8762542c4defc4f70e1eb76fb508fa)
1# $NetBSD: t_symlink.sh,v 1.1 2007/11/12 15:18:27 jmmv 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# 3. All advertising materials mentioning features or use of this software
15#    must display the following acknowledgement:
16#        This product includes software developed by the NetBSD
17#        Foundation, Inc. and its contributors.
18# 4. Neither the name of The NetBSD Foundation nor the names of its
19#    contributors may be used to endorse or promote products derived
20#    from this software without specific prior written permission.
21#
22# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32# POSSIBILITY OF SUCH DAMAGE.
33#
34
35#
36# Verifies that the symlink and readlink operations work.
37#
38
39atf_test_case file
40file_head() {
41	atf_set "descr" "Tests that symlinks to files work"
42	atf_set "require.user" "root"
43}
44file_body() {
45	test_mount
46
47	atf_check 'touch a' 0 null null
48	atf_check 'ln -s a b' 0 null null
49	[ $(md5 b | cut -d ' ' -f 4) = d41d8cd98f00b204e9800998ecf8427e ] || \
50	    atf_fail "Symlink points to an incorrect file"
51
52	atf_check 'echo foo >a' 0 null null
53	[ $(md5 b | cut -d ' ' -f 4) = d3b07384d113edec49eaa6238ad5ff00 ] || \
54	    atf_fail "Symlink points to an incorrect file"
55
56	test_unmount
57}
58
59atf_test_case exec
60exec_head() {
61	atf_set "descr" "Tests symlinking to a known system binary and" \
62	                "executing it through the symlink"
63	atf_set "require.user" "root"
64}
65exec_body() {
66	test_mount
67
68	atf_check 'touch b' 0 null null
69	atf_check 'ln -s /bin/cp cp' 0 null null
70	atf_check './cp b c' 0 null null
71	atf_check 'test -f c' 0 null null
72
73	test_unmount
74}
75
76atf_test_case dir
77dir_head() {
78	atf_set "descr" "Tests that symlinks to directories work"
79	atf_set "require.user" "root"
80}
81dir_body() {
82	test_mount
83
84	atf_check 'mkdir d' 0 null null
85	atf_check 'test -f d/foo' 1 null null
86	atf_check 'test -f e/foo' 1 null null
87	atf_check 'ln -s d e' 0 null null
88	atf_check 'touch d/foo' 0 null null
89	atf_check 'test -f d/foo' 0 null null
90	atf_check 'test -f e/foo' 0 null null
91
92	test_unmount
93}
94
95atf_test_case kqueue
96kqueue_head() {
97	atf_set "descr" "Tests that creating a symlink raises the" \
98	                "appropriate kqueue events"
99	atf_set "require.user" "root"
100}
101kqueue_body() {
102	test_mount
103
104	atf_check 'mkdir dir' 0 null null
105	echo 'ln -s non-existent dir/a' | kqueue_monitor 1 dir
106	kqueue_check dir NOTE_WRITE
107	atf_check 'rm dir/a' 0 null null
108	atf_check 'rmdir dir' 0 null null
109
110	test_unmount
111}
112
113atf_init_test_cases() {
114	. $(atf_get_srcdir)/../h_funcs.subr
115	. $(atf_get_srcdir)/h_funcs.subr
116
117	atf_add_test_case file
118	atf_add_test_case exec
119	atf_add_test_case dir
120	atf_add_test_case kqueue
121}
122