1# $NetBSD: t_vfs.sh,v 1.4 2011/03/08 22:21:52 pooka 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 -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 mount_ffs /img ${mntdir} 39} 40 41dounmount() 42{ 43 44 atf_check -s exit:0 umount -R ${mntdir} 45} 46 47remount() 48{ 49 50 dounmount 51 domount /rump/mnt2 52} 53 54simpletest() 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 70test_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 90test_case paxcopy 91test_case cpcopy 92test_case mv_nox 93 94# 95# use rumphijack to cp/pax stuff onto an image, unmount it, remount it 96# at a different location, and check that we have an identical copy 97# (we make a local copy to avoid the minor possibility that someone 98# modifies the source dir data while the test is running) 99# 100paxcopy() 101{ 102 parent=$(dirname $(atf_get_srcdir)) 103 thedir=$(basename $(atf_get_srcdir)) 104 atf_check -s exit:0 pax -rw -s,${parent},, $(atf_get_srcdir) . 105 atf_check -s exit:0 pax -rw ${thedir} /rump/mnt 106 remount 107 atf_check -s exit:0 diff -ru ${thedir} /rump/mnt2/${thedir} 108} 109 110cpcopy() 111{ 112 thedir=$(basename $(atf_get_srcdir)) 113 atf_check -s exit:0 cp -Rp $(atf_get_srcdir) . 114 atf_check -s exit:0 cp -Rp ${thedir} /rump/mnt 115 remount 116 atf_check -s exit:0 diff -ru ${thedir} /rump/mnt2/${thedir} 117} 118 119# 120# non-crosskernel mv (non-simple test since this uses rename(2) 121# which is not supported by rumpfs) 122# 123 124# stat default format sans changetime and filename 125statstr='%d %i %Sp %l %Su %Sg %r %z \"%Sa\" \"%Sm\" \"%SB\" %k %b %#Xf' 126mv_nox() 127{ 128 129 atf_check -s exit:0 touch /rump/mnt/filename 130 atf_check -s exit:0 -o save:stat.out \ 131 stat -f "${statstr}" /rump/mnt/filename 132 atf_check -s exit:0 mkdir /rump/mnt/dir 133 atf_check -s exit:0 mv /rump/mnt/filename /rump/mnt/dir/same 134 atf_check -s exit:0 -o file:stat.out \ 135 stat -f "${statstr}" /rump/mnt/dir/same 136} 137 138simpletest mv_x 139simpletest runonprefix 140simpletest blanket 141simpletest doubleblanket 142 143# 144# do a cross-kernel mv 145# 146mv_x() 147{ 148 thedir=$(basename $(atf_get_srcdir)) 149 atf_check -s exit:0 cp -Rp $(atf_get_srcdir) . 150 atf_check -s exit:0 cp -Rp ${thedir} ${thedir}.2 151 atf_check -s exit:0 mv ${thedir} /rump 152 atf_check -s exit:0 diff -ru ${thedir}.2 /rump/${thedir} 153} 154 155runonprefix() 156{ 157 atf_check -s exit:0 -o ignore stat /rump/dev 158 atf_check -s exit:1 -e ignore stat /rumpdev 159} 160 161blanket() 162{ 163 export RUMPHIJACK='blanket=/dev,path=/rump' 164 atf_check -s exit:0 -o save:stat.out \ 165 stat -f "${statstr}" /rump/dev/null 166 atf_check -s exit:0 -o file:stat.out \ 167 stat -f "${statstr}" /dev/null 168} 169 170doubleblanket() 171{ 172 atf_check -s exit:0 mkdir /rump/dir 173 atf_check -s exit:0 ln -s dir /rump/dirtoo 174 175 export RUMPHIJACK='blanket=/dirtoo:/dir' 176 atf_check -s exit:0 touch /dir/file 177 178 atf_check -s exit:0 -o save:stat.out \ 179 stat -f "${statstr}" /dir/file 180 atf_check -s exit:0 -o file:stat.out \ 181 stat -f "${statstr}" /dirtoo/file 182} 183 184atf_init_test_cases() 185{ 186 187 atf_add_test_case paxcopy 188 atf_add_test_case cpcopy 189 atf_add_test_case mv_x 190 atf_add_test_case mv_nox 191 atf_add_test_case runonprefix 192 atf_add_test_case blanket 193 atf_add_test_case doubleblanket 194} 195