xref: /freebsd/contrib/netbsd-tests/fs/tmpfs/t_remove.sh (revision 2e3507c25e42292b45a5482e116d278f5515d04d)
1# $NetBSD: t_remove.sh,v 1.5 2010/11/07 17:51:18 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 remove operation works.
30#
31
32atf_test_case single
33single_head() {
34	atf_set "descr" "Checks that file removal works"
35	atf_set "require.user" "root"
36}
37single_body() {
38	test_mount
39
40	atf_check -s eq:1 -o empty -e empty test -f a
41	atf_check -s eq:0 -o empty -e empty touch a
42	atf_check -s eq:0 -o empty -e empty test -f a
43	atf_check -s eq:0 -o empty -e empty rm a
44	atf_check -s eq:1 -o empty -e empty test -f a
45
46	test_unmount
47}
48
49# Begin FreeBSD
50if true; then
51atf_test_case uchg cleanup
52uchg_cleanup() {
53	Mount_Point=$(pwd)/mntpt _test_unmount
54}
55else
56# End FreeBSD
57atf_test_case uchg
58# Begin FreeBSD
59fi
60# End FreeBSD
61uchg_head() {
62	atf_set "descr" "Checks that files with the uchg flag set cannot" \
63	                "be removed"
64	atf_set "require.user" "root"
65}
66uchg_body() {
67	# Begin FreeBSD
68	atf_expect_fail "this fails on FreeBSD with root - bug 212861"
69	# End FreeBSD
70
71	test_mount
72
73	atf_check -s eq:0 -o empty -e empty touch a
74	atf_check -s eq:0 -o empty -e empty chflags uchg a
75	atf_check -s eq:1 -o empty -e ignore rm -f a
76	atf_check -s eq:0 -o empty -e empty chflags nouchg a
77	atf_check -s eq:0 -o empty -e empty rm a
78	atf_check -s eq:1 -o empty -e empty test -f a
79
80	test_unmount
81}
82
83atf_test_case dot
84dot_head() {
85	atf_set "descr" "Checks that '.' cannot be removed"
86	atf_set "require.user" "root"
87}
88dot_body() {
89	test_mount
90
91	atf_check -s eq:0 -o empty -e empty mkdir a
92	atf_check -s eq:1 -o empty -e ignore unlink a/.
93	atf_check -s eq:0 -o empty -e empty rmdir a
94
95	test_unmount
96}
97
98atf_test_case kqueue
99kqueue_head() {
100	atf_set "descr" "Removes a file and checks the kqueue events" \
101	                "raised"
102	atf_set "require.user" "root"
103}
104kqueue_body() {
105	test_mount
106
107	atf_check -s eq:0 -o empty -e empty mkdir dir
108	atf_check -s eq:0 -o empty -e empty touch dir/a
109	echo 'rm dir/a' | kqueue_monitor 2 dir dir/a
110	kqueue_check dir/a NOTE_DELETE
111	kqueue_check dir NOTE_WRITE
112	atf_check -s eq:0 -o empty -e empty rmdir dir
113
114	test_unmount
115}
116
117atf_init_test_cases() {
118	. $(atf_get_srcdir)/../h_funcs.subr
119	. $(atf_get_srcdir)/h_funcs.subr
120
121	atf_add_test_case single
122	atf_add_test_case uchg
123	atf_add_test_case dot
124	atf_add_test_case kqueue
125}
126