1272343Sngie# $NetBSD: t_symlink.sh,v 1.5 2010/11/07 17:51:18 jmmv Exp $
2272343Sngie#
3272343Sngie# Copyright (c) 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc.
4272343Sngie# All rights reserved.
5272343Sngie#
6272343Sngie# Redistribution and use in source and binary forms, with or without
7272343Sngie# modification, are permitted provided that the following conditions
8272343Sngie# are met:
9272343Sngie# 1. Redistributions of source code must retain the above copyright
10272343Sngie#    notice, this list of conditions and the following disclaimer.
11272343Sngie# 2. Redistributions in binary form must reproduce the above copyright
12272343Sngie#    notice, this list of conditions and the following disclaimer in the
13272343Sngie#    documentation and/or other materials provided with the distribution.
14272343Sngie#
15272343Sngie# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16272343Sngie# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17272343Sngie# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18272343Sngie# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19272343Sngie# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20272343Sngie# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21272343Sngie# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22272343Sngie# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23272343Sngie# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24272343Sngie# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25272343Sngie# POSSIBILITY OF SUCH DAMAGE.
26272343Sngie#
27272343Sngie
28272343Sngie#
29272343Sngie# Verifies that the symlink and readlink operations work.
30272343Sngie#
31272343Sngie
32272343Sngieatf_test_case file
33272343Sngiefile_head() {
34272343Sngie	atf_set "descr" "Tests that symlinks to files work"
35272343Sngie	atf_set "require.user" "root"
36272343Sngie}
37272343Sngiefile_body() {
38272343Sngie	test_mount
39272343Sngie
40272343Sngie	atf_check -s eq:0 -o empty -e empty touch a
41272343Sngie	atf_check -s eq:0 -o empty -e empty ln -s a b
42272343Sngie	[ $(md5 b | cut -d ' ' -f 4) = d41d8cd98f00b204e9800998ecf8427e ] || \
43272343Sngie	    atf_fail "Symlink points to an incorrect file"
44272343Sngie
45272343Sngie	atf_check -s eq:0 -o empty -e empty -x 'echo foo >a'
46272343Sngie	[ $(md5 b | cut -d ' ' -f 4) = d3b07384d113edec49eaa6238ad5ff00 ] || \
47272343Sngie	    atf_fail "Symlink points to an incorrect file"
48272343Sngie
49272343Sngie	test_unmount
50272343Sngie}
51272343Sngie
52272343Sngieatf_test_case exec
53272343Sngieexec_head() {
54272343Sngie	atf_set "descr" "Tests symlinking to a known system binary and" \
55272343Sngie	                "executing it through the symlink"
56272343Sngie	atf_set "require.user" "root"
57272343Sngie}
58272343Sngieexec_body() {
59272343Sngie	test_mount
60272343Sngie
61272343Sngie	atf_check -s eq:0 -o empty -e empty touch b
62272343Sngie	atf_check -s eq:0 -o empty -e empty ln -s /bin/cp cp
63272343Sngie	atf_check -s eq:0 -o empty -e empty ./cp b c
64272343Sngie	atf_check -s eq:0 -o empty -e empty test -f c
65272343Sngie
66272343Sngie	test_unmount
67272343Sngie}
68272343Sngie
69272343Sngieatf_test_case dir
70272343Sngiedir_head() {
71272343Sngie	atf_set "descr" "Tests that symlinks to directories work"
72272343Sngie	atf_set "require.user" "root"
73272343Sngie}
74272343Sngiedir_body() {
75272343Sngie	test_mount
76272343Sngie
77272343Sngie	atf_check -s eq:0 -o empty -e empty mkdir d
78272343Sngie	atf_check -s eq:1 -o empty -e empty test -f d/foo
79272343Sngie	atf_check -s eq:1 -o empty -e empty test -f e/foo
80272343Sngie	atf_check -s eq:0 -o empty -e empty ln -s d e
81272343Sngie	atf_check -s eq:0 -o empty -e empty touch d/foo
82272343Sngie	atf_check -s eq:0 -o empty -e empty test -f d/foo
83272343Sngie	atf_check -s eq:0 -o empty -e empty test -f e/foo
84272343Sngie
85272343Sngie	test_unmount
86272343Sngie}
87272343Sngie
88272343Sngieatf_test_case kqueue
89272343Sngiekqueue_head() {
90272343Sngie	atf_set "descr" "Tests that creating a symlink raises the" \
91272343Sngie	                "appropriate kqueue events"
92272343Sngie	atf_set "require.user" "root"
93272343Sngie}
94272343Sngiekqueue_body() {
95272343Sngie	test_mount
96272343Sngie
97272343Sngie	atf_check -s eq:0 -o empty -e empty mkdir dir
98272343Sngie	echo 'ln -s non-existent dir/a' | kqueue_monitor 1 dir
99272343Sngie	kqueue_check dir NOTE_WRITE
100272343Sngie	atf_check -s eq:0 -o empty -e empty rm dir/a
101272343Sngie	atf_check -s eq:0 -o empty -e empty rmdir dir
102272343Sngie
103272343Sngie	test_unmount
104272343Sngie}
105272343Sngie
106272343Sngieatf_init_test_cases() {
107272343Sngie	. $(atf_get_srcdir)/../h_funcs.subr
108272343Sngie	. $(atf_get_srcdir)/h_funcs.subr
109272343Sngie
110272343Sngie	atf_add_test_case file
111272343Sngie	atf_add_test_case exec
112272343Sngie	atf_add_test_case dir
113272343Sngie	atf_add_test_case kqueue
114272343Sngie}
115