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