]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - tools/regression/tmpfs/t_rename
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / tools / regression / tmpfs / t_rename
1 #!/bin/sh
2 #
3 # $NetBSD: t_rename,v 1.7 2007/07/23 15:05:43 jmmv Exp $
4 #
5 # Copyright (c) 2005, 2006 The NetBSD Foundation, Inc.
6 # All rights reserved.
7 #
8 # This code is derived from software contributed to The NetBSD Foundation
9 # by Julio M. Merino Vidal, developed as part of Google's Summer of Code
10 # 2005 program.
11 #
12 # Redistribution and use in source and binary forms, with or without
13 # modification, are permitted provided that the following conditions
14 # are met:
15 # 1. Redistributions of source code must retain the above copyright
16 #    notice, this list of conditions and the following disclaimer.
17 # 2. Redistributions in binary form must reproduce the above copyright
18 #    notice, this list of conditions and the following disclaimer in the
19 #    documentation and/or other materials provided with the distribution.
20 # 3. All advertising materials mentioning features or use of this software
21 #    must display the following acknowledgement:
22 #        This product includes software developed by the NetBSD
23 #        Foundation, Inc. and its contributors.
24 # 4. Neither the name of The NetBSD Foundation nor the names of its
25 #    contributors may be used to endorse or promote products derived
26 #    from this software without specific prior written permission.
27 #
28 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
29 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
30 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31 # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
32 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 # POSSIBILITY OF SUCH DAMAGE.
39 #
40 # $FreeBSD$
41 #
42
43 #
44 # Verifies that the rename operation works (either by renaming entries or
45 # by moving them).
46 #
47
48 test_run() {
49         test_mount
50
51         test_name "'.' and '..' entries cannot be renamed"
52         mkdir a || die
53         mv a/. c 2>/dev/null && die
54         mv a/.. c 2>/dev/null && die
55         rmdir a || die
56
57         test_name "Cross device renames do not work"
58         mkdir a || die
59         ${Src_Dir}/h_tools rename a /var/tmp/a >/dev/null 2>&1 && die
60         rmdir a || die
61
62         test_name "Directories can be renamed"
63         mkdir a || die
64         mv a c || die
65         test -d a && die
66         test -d c || die
67         rmdir c || die
68
69         test_name "The '..' entry is updated after moves"
70         mkdir a || die
71         mkdir b || die
72         mv b a || die
73         test -d a/b/../b || die
74         test -d a/b/../../a || die
75         eval $(stat -s a/b)
76         [ ${st_nlink} = 2 ] || die
77         eval $(stat -s a)
78         [ ${st_nlink} = 3 ] || die
79         rmdir a/b || die
80         rmdir a || die
81
82         test_name "The '..' entry is correct after renames"
83         mkdir a || die
84         mkdir b || die
85         mv b a || die
86         mv a c || die
87         test -d c/b/../b || die
88         test -d c/b/../../c || die
89         rmdir c/b || die
90         rmdir c || die
91
92         test_name "The '..' entry is correct after multiple moves"
93         mkdir a || die
94         mkdir b || die
95         mv b a || die
96         mv a c || die
97         mv c/b d || die
98         test -d d/../c || die
99         rmdir d || die
100         rmdir c || die
101
102         test_name "Rename works if the target file exists"
103         touch a || die
104         touch b || die
105         mv a b || die
106         test -f a && die
107         test -f b || die
108         rm b
109
110         test_name "Rename a directory to a override an empty directory works"
111         mkdir a || die
112         touch a/c || die
113         mkdir b || die
114         ${Src_Dir}/h_tools rename a b >/dev/null 2>&1 || die
115         test -e a && die
116         test -d b || die
117         test -f b/c || die
118         rm b/c
119         rmdir b
120
121         test_name "Rename a directory to a override a non-empty directory fails"
122         mkdir a || die
123         touch a/c || die
124         mkdir b || die
125         touch b/d || die
126         err=$(${Src_Dir}/h_tools rename a b 2>&1) && die
127         echo ${err} | grep 'Directory not empty' >/dev/null || die
128         test -d a || die
129         test -f a/c || die
130         test -d b || die
131         test -f b/d || die
132         rm a/c
133         rm b/d
134         rmdir a
135         rmdir b
136
137         test_name "Rename a directory to a override a file fails"
138         mkdir a || die
139         touch b || die
140         err=$(${Src_Dir}/h_tools rename a b 2>&1) && die
141         echo ${err} | grep 'Not a directory' >/dev/null || die
142         test -d a || die
143         test -f b || die
144         rmdir a
145         rm b
146
147         test_name "Rename a file to a override a directory fails"
148         touch a || die
149         mkdir b || die
150         err=$(${Src_Dir}/h_tools rename a b 2>&1) && die
151         echo ${err} | grep 'Is a directory' >/dev/null || die
152         test -f a || die
153         test -d b || die
154         rm a
155         rmdir b
156
157         mkdir dir || die
158         touch dir/a
159         echo 'mv dir/a dir/b' | kqueue_monitor 2 dir dir/a || die
160         test_name "Renaming a file raises NOTE_RENAME on the old file"
161         kqueue_check dir/a NOTE_RENAME || die
162         test_name "Renaming a file raises NOTE_WRITE on the parent directory"
163         kqueue_check dir NOTE_WRITE || die
164         rm dir/b || die
165         rmdir dir || die
166
167         mkdir dir || die
168         touch dir/a
169         touch dir/b
170         echo 'mv dir/a dir/b' | kqueue_monitor 3 dir dir/a dir/b || die
171         test_name "Renaming a file raises NOTE_RENAME on the old file"
172         kqueue_check dir/a NOTE_RENAME || die
173         test_name "Renaming a file raises NOTE_WRITE on the parent directory"
174         kqueue_check dir NOTE_WRITE || die
175         test_name "Renaming a file raises NOTE_DELETE on the target file"
176         kqueue_check dir/b NOTE_DELETE || die
177         rm dir/b || die
178         rmdir dir || die
179
180         mkdir dir1 || die
181         mkdir dir2 || die
182         touch dir1/a
183         echo 'mv dir1/a dir2/a' | kqueue_monitor 3 dir1 dir1/a dir2 || die
184         test_name "Moving a file raises NOTE_RENAME on the old file"
185         kqueue_check dir1/a NOTE_RENAME || die
186         test_name "Moving a file raises NOTE_WRITE on the source directory"
187         kqueue_check dir1 NOTE_WRITE || die
188         test_name "Moving a file raises NOTE_WRITE on the target directory"
189         kqueue_check dir2 NOTE_WRITE || die
190         rm dir2/a || die
191         rmdir dir1 || die
192         rmdir dir2 || die
193
194         test_unmount
195 }
196
197 . ${SUBRDIR}/h_funcs.subr