]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/netbsd-tests/lib/librumphijack/t_vfs.sh
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / netbsd-tests / lib / librumphijack / t_vfs.sh
1 #       $NetBSD: t_vfs.sh,v 1.6 2012/08/04 03:56:47 riastradh Exp $
2 #
3 # Copyright (c) 2011 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 img=ffs.img
29 rumpsrv_ffs=\
30 "rump_server -lrumpvfs -lrumpfs_ffs -lrumpdev_disk -d key=/img,hostpath=${img},size=host"
31 export RUMP_SERVER=unix://csock
32
33 domount()
34 {
35
36         mntdir=$1
37         [ $# -eq 0 ] && mntdir=/rump/mnt
38         atf_check -s exit:0 -e ignore mount_ffs /img ${mntdir}
39 }
40
41 dounmount()
42 {
43
44         atf_check -s exit:0 umount -R ${mntdir}
45 }
46
47 remount()
48 {
49
50         dounmount
51         domount /rump/mnt2
52 }
53
54 simpletest()
55 {
56         local name="${1}"; shift
57
58         atf_test_case "${name}" cleanup
59         eval "${name}_head() {  }"
60         eval "${name}_body() { \
61                 atf_check -s exit:0 rump_server -lrumpvfs ${RUMP_SERVER} ; \
62                 export LD_PRELOAD=/usr/lib/librumphijack.so ; \
63                 ${name} " "${@}" "; \
64         }"
65         eval "${name}_cleanup() { \
66                 rump.halt
67         }"
68 }
69
70 test_case()
71 {
72         local name="${1}"; shift
73
74         atf_test_case "${name}" cleanup
75         eval "${name}_head() {  }"
76         eval "${name}_body() { \
77                 atf_check -s exit:0 -o ignore newfs -F -s 20000 ${img} ; \
78                 atf_check -s exit:0 ${rumpsrv_ffs} ${RUMP_SERVER} ; \
79                 export LD_PRELOAD=/usr/lib/librumphijack.so ; \
80                 mkdir /rump/mnt /rump/mnt2 ; \
81                 domount ; \
82                 ${name} " "${@}" "; \
83                 dounmount ${mntdir}
84         }"
85         eval "${name}_cleanup() { \
86                 rump.halt
87         }"
88 }
89
90 test_case paxcopy
91 test_case cpcopy
92 test_case mv_nox
93 test_case ln_nox
94
95 #
96 # use rumphijack to cp/pax stuff onto an image, unmount it, remount it
97 # at a different location, and check that we have an identical copy
98 # (we make a local copy to avoid the minor possibility that someone
99 # modifies the source dir data while the test is running)
100 #
101 paxcopy()
102 {
103         parent=$(dirname $(atf_get_srcdir))
104         thedir=$(basename $(atf_get_srcdir))
105         atf_check -s exit:0 pax -rw -s,${parent},, $(atf_get_srcdir) .
106         atf_check -s exit:0 pax -rw ${thedir} /rump/mnt
107         remount
108         atf_check -s exit:0 diff -ru ${thedir} /rump/mnt2/${thedir}
109 }
110
111 cpcopy()
112 {
113         thedir=$(basename $(atf_get_srcdir))
114         atf_check -s exit:0 cp -Rp $(atf_get_srcdir) .
115         atf_check -s exit:0 cp -Rp ${thedir} /rump/mnt
116         remount
117         atf_check -s exit:0 diff -ru ${thedir} /rump/mnt2/${thedir}
118 }
119
120 #
121 # non-crosskernel mv (non-simple test since this uses rename(2)
122 # which is not supported by rumpfs)
123 #
124
125 mv_nox()
126 {
127         # stat default format sans changetime and filename
128         statstr='%d %i %Sp %l %Su %Sg %r %z \"%Sa\" \"%Sm\" \"%SB\" %k %b %#Xf'
129
130         atf_check -s exit:0 touch /rump/mnt/filename
131         atf_check -s exit:0 -o save:stat.out \
132             stat -f "${statstr}" /rump/mnt/filename
133         atf_check -s exit:0 mkdir /rump/mnt/dir
134         atf_check -s exit:0 mv /rump/mnt/filename /rump/mnt/dir/same
135         atf_check -s exit:0 -o file:stat.out \
136             stat -f "${statstr}" /rump/mnt/dir/same
137 }
138
139 ln_nox()
140 {
141         # Omit st_nlink too, since it will increase.
142         statstr='%d %i %Sp %Su %Sg %r %z \"%Sa\" \"%Sm\" \"%SB\" %k %b %#Xf'
143
144         atf_check -s exit:0 touch /rump/mnt/filename
145         atf_check -s exit:0 -o save:stat.out \
146             stat -f "${statstr}" /rump/mnt/filename
147         atf_check -s exit:0 mkdir /rump/mnt/dir
148         atf_check -s exit:0 ln /rump/mnt/filename /rump/mnt/dir/same
149         atf_check -s exit:0 -o file:stat.out \
150             stat -f "${statstr}" /rump/mnt/filename
151         atf_check -s exit:0 -o file:stat.out \
152             stat -f "${statstr}" /rump/mnt/dir/same
153 }
154
155 simpletest mv_x
156 simpletest ln_x
157 simpletest runonprefix
158 simpletest blanket
159 simpletest doubleblanket
160
161 #
162 # do a cross-kernel mv
163 #
164 mv_x()
165 {
166         thedir=$(basename $(atf_get_srcdir))
167         atf_check -s exit:0 cp -Rp $(atf_get_srcdir) .
168         atf_check -s exit:0 cp -Rp ${thedir} ${thedir}.2
169         atf_check -s exit:0 mv ${thedir} /rump
170         atf_check -s exit:0 diff -ru ${thedir}.2 /rump/${thedir}
171 }
172
173 #
174 # Fail to make a cross-kernel hard link.
175 #
176 ln_x()
177 {
178         atf_check -s exit:0 touch ./loser
179         atf_check -s not-exit:0 -e ignore ln ./loser /rump/.
180 }
181
182 runonprefix()
183 {
184         atf_check -s exit:0 -o ignore stat /rump/dev
185         atf_check -s exit:1 -e ignore stat /rumpdev
186 }
187
188 blanket()
189 {
190         export RUMPHIJACK='blanket=/dev,path=/rump'
191         atf_check -s exit:0 -o save:stat.out \
192             stat -f "${statstr}" /rump/dev/null
193         atf_check -s exit:0 -o file:stat.out \
194             stat -f "${statstr}" /dev/null
195 }
196
197 doubleblanket()
198 {
199         atf_check -s exit:0 mkdir /rump/dir
200         atf_check -s exit:0 ln -s dir /rump/dirtoo
201
202         export RUMPHIJACK='blanket=/dirtoo:/dir'
203         atf_check -s exit:0 touch /dir/file
204
205         atf_check -s exit:0 -o save:stat.out \
206             stat -f "${statstr}" /dir/file
207         atf_check -s exit:0 -o file:stat.out \
208             stat -f "${statstr}" /dirtoo/file
209 }
210
211 atf_init_test_cases()
212 {
213
214         atf_add_test_case paxcopy
215         atf_add_test_case cpcopy
216         atf_add_test_case mv_x
217         atf_add_test_case ln_x
218         atf_add_test_case mv_nox
219         atf_add_test_case ln_nox
220         atf_add_test_case runonprefix
221         atf_add_test_case blanket
222         atf_add_test_case doubleblanket
223 }