t_symlink.sh revision 285830
175584Sru# $NetBSD: t_symlink.sh,v 1.5 2010/11/07 17:51:18 jmmv Exp $
275584Sru#
375584Sru# Copyright (c) 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc.
475584Sru# All rights reserved.
575584Sru#
675584Sru# Redistribution and use in source and binary forms, with or without
775584Sru# modification, are permitted provided that the following conditions
875584Sru# are met:
975584Sru# 1. Redistributions of source code must retain the above copyright
1075584Sru#    notice, this list of conditions and the following disclaimer.
1175584Sru# 2. Redistributions in binary form must reproduce the above copyright
1275584Sru#    notice, this list of conditions and the following disclaimer in the
1375584Sru#    documentation and/or other materials provided with the distribution.
1475584Sru#
1575584Sru# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1675584Sru# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1775584Sru# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1875584Sru# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
1975584Sru# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2075584Sru# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2175584Sru# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2275584Sru# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2375584Sru# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2475584Sru# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2575584Sru# POSSIBILITY OF SUCH DAMAGE.
2675584Sru#
2775584Sru
2875584Sru#
2975584Sru# Verifies that the symlink and readlink operations work.
3075584Sru#
3175584Sru
3275584Sruatf_test_case file
3375584Srufile_head() {
3475584Sru	atf_set "descr" "Tests that symlinks to files work"
3575584Sru	atf_set "require.user" "root"
3675584Sru}
3775584Srufile_body() {
3875584Sru	test_mount
3975584Sru
4075584Sru	atf_check -s eq:0 -o empty -e empty touch a
4175584Sru	atf_check -s eq:0 -o empty -e empty ln -s a b
4275584Sru	[ $(md5 b | cut -d ' ' -f 4) = d41d8cd98f00b204e9800998ecf8427e ] || \
4375584Sru	    atf_fail "Symlink points to an incorrect file"
4475584Sru
4575584Sru	atf_check -s eq:0 -o empty -e empty -x 'echo foo >a'
4675584Sru	[ $(md5 b | cut -d ' ' -f 4) = d3b07384d113edec49eaa6238ad5ff00 ] || \
4775584Sru	    atf_fail "Symlink points to an incorrect file"
4875584Sru
4975584Sru	test_unmount
5075584Sru}
5175584Sru
5275584Sruatf_test_case exec
5375584Sruexec_head() {
5475584Sru	atf_set "descr" "Tests symlinking to a known system binary and" \
5575584Sru	                "executing it through the symlink"
5675584Sru	atf_set "require.user" "root"
5775584Sru}
5875584Sruexec_body() {
5975584Sru	test_mount
6075584Sru
6175584Sru	atf_check -s eq:0 -o empty -e empty touch b
6275584Sru	atf_check -s eq:0 -o empty -e empty ln -s /bin/cp cp
6375584Sru	atf_check -s eq:0 -o empty -e empty ./cp b c
6475584Sru	atf_check -s eq:0 -o empty -e empty test -f c
6575584Sru
6675584Sru	test_unmount
6775584Sru}
6875584Sru
6975584Sruatf_test_case dir
7075584Srudir_head() {
7175584Sru	atf_set "descr" "Tests that symlinks to directories work"
7275584Sru	atf_set "require.user" "root"
7375584Sru}
7475584Srudir_body() {
7575584Sru	test_mount
7675584Sru
7775584Sru	atf_check -s eq:0 -o empty -e empty mkdir d
7875584Sru	atf_check -s eq:1 -o empty -e empty test -f d/foo
7975584Sru	atf_check -s eq:1 -o empty -e empty test -f e/foo
8075584Sru	atf_check -s eq:0 -o empty -e empty ln -s d e
8175584Sru	atf_check -s eq:0 -o empty -e empty touch d/foo
8275584Sru	atf_check -s eq:0 -o empty -e empty test -f d/foo
8375584Sru	atf_check -s eq:0 -o empty -e empty test -f e/foo
8475584Sru
8575584Sru	test_unmount
8675584Sru}
8775584Sru
8875584Sruatf_test_case kqueue
8975584Srukqueue_head() {
9075584Sru	atf_set "descr" "Tests that creating a symlink raises the" \
9175584Sru	                "appropriate kqueue events"
9275584Sru	atf_set "require.user" "root"
9375584Sru}
9475584Srukqueue_body() {
9575584Sru	test_mount
9675584Sru
9775584Sru	atf_check -s eq:0 -o empty -e empty mkdir dir
9875584Sru	echo 'ln -s non-existent dir/a' | kqueue_monitor 1 dir
9975584Sru	kqueue_check dir NOTE_WRITE
10075584Sru	atf_check -s eq:0 -o empty -e empty rm dir/a
10175584Sru	atf_check -s eq:0 -o empty -e empty rmdir dir
10275584Sru
10375584Sru	test_unmount
10475584Sru}
10575584Sru
10675584Sruatf_init_test_cases() {
10775584Sru	. $(atf_get_srcdir)/../h_funcs.subr
10875584Sru	. $(atf_get_srcdir)/h_funcs.subr
10975584Sru
11075584Sru	atf_add_test_case file
11175584Sru	atf_add_test_case exec
11275584Sru	atf_add_test_case dir
11375584Sru	atf_add_test_case kqueue
11475584Sru}
11575584Sru