xref: /netbsd-src/tests/fs/tmpfs/t_remove.sh (revision 9b7401e7cb4e6a8aa5a84a9facdc1d940082106f)
1# $NetBSD: t_remove.sh,v 1.1 2007/11/12 15:18:25 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 remove operation works.
37#
38
39atf_test_case single
40single_head() {
41	atf_set "descr" "Checks that file removal works"
42	atf_set "require.user" "root"
43}
44single_body() {
45	test_mount
46
47	atf_check 'test -f a' 1 null null
48	atf_check 'touch a' 0 null null
49	atf_check 'test -f a' 0 null null
50	atf_check 'rm a' 0 null null
51	atf_check 'test -f a' 1 null null
52
53	test_unmount
54}
55
56atf_test_case uchg
57uchg_head() {
58	atf_set "descr" "Checks that files with the uchg flag set cannot" \
59	                "be removed"
60	atf_set "require.user" "root"
61}
62uchg_body() {
63	test_mount
64
65	atf_check 'touch a' 0 null null
66	atf_check 'chflags uchg a' 0 null null
67	atf_check 'rm -f a' 1 null ignore
68	atf_check 'chflags nouchg a' 0 null null
69	atf_check 'rm a' 0 null null
70	atf_check 'test -f a' 1 null null
71
72	test_unmount
73}
74
75atf_test_case dot
76dot_head() {
77	atf_set "descr" "Checks that '.' cannot be removed"
78	atf_set "require.user" "root"
79}
80dot_body() {
81	test_mount
82
83	atf_check 'mkdir a' 0 null null
84	atf_check 'unlink a/.' 1 null ignore
85	atf_check 'rmdir a' 0 null null
86
87	test_unmount
88}
89
90atf_test_case kqueue
91kqueue_head() {
92	atf_set "descr" "Removes a file and checks the kqueue events" \
93	                "raised"
94	atf_set "require.user" "root"
95}
96kqueue_body() {
97	test_mount
98
99	atf_check 'mkdir dir' 0 null null
100	atf_check 'touch dir/a' 0 null null
101	echo 'rm dir/a' | kqueue_monitor 2 dir dir/a
102	kqueue_check dir/a NOTE_DELETE
103	kqueue_check dir NOTE_WRITE
104	atf_check 'rmdir dir' 0 null null
105
106	test_unmount
107}
108
109atf_init_test_cases() {
110	. $(atf_get_srcdir)/../h_funcs.subr
111	. $(atf_get_srcdir)/h_funcs.subr
112
113	atf_add_test_case single
114	atf_add_test_case uchg
115	atf_add_test_case dot
116	atf_add_test_case kqueue
117}
118