1*11be35a1SLionel Sambuc# $NetBSD: t_vfs.sh,v 1.6 2012/08/04 03:56:47 riastradh Exp $ 2*11be35a1SLionel Sambuc# 3*11be35a1SLionel Sambuc# Copyright (c) 2011 The NetBSD Foundation, Inc. 4*11be35a1SLionel Sambuc# All rights reserved. 5*11be35a1SLionel Sambuc# 6*11be35a1SLionel Sambuc# Redistribution and use in source and binary forms, with or without 7*11be35a1SLionel Sambuc# modification, are permitted provided that the following conditions 8*11be35a1SLionel Sambuc# are met: 9*11be35a1SLionel Sambuc# 1. Redistributions of source code must retain the above copyright 10*11be35a1SLionel Sambuc# notice, this list of conditions and the following disclaimer. 11*11be35a1SLionel Sambuc# 2. Redistributions in binary form must reproduce the above copyright 12*11be35a1SLionel Sambuc# notice, this list of conditions and the following disclaimer in the 13*11be35a1SLionel Sambuc# documentation and/or other materials provided with the distribution. 14*11be35a1SLionel Sambuc# 15*11be35a1SLionel Sambuc# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16*11be35a1SLionel Sambuc# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17*11be35a1SLionel Sambuc# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18*11be35a1SLionel Sambuc# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19*11be35a1SLionel Sambuc# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20*11be35a1SLionel Sambuc# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21*11be35a1SLionel Sambuc# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22*11be35a1SLionel Sambuc# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23*11be35a1SLionel Sambuc# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24*11be35a1SLionel Sambuc# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25*11be35a1SLionel Sambuc# POSSIBILITY OF SUCH DAMAGE. 26*11be35a1SLionel Sambuc# 27*11be35a1SLionel Sambuc 28*11be35a1SLionel Sambucimg=ffs.img 29*11be35a1SLionel Sambucrumpsrv_ffs=\ 30*11be35a1SLionel Sambuc"rump_server -lrumpvfs -lrumpfs_ffs -lrumpdev_disk -d key=/img,hostpath=${img},size=host" 31*11be35a1SLionel Sambucexport RUMP_SERVER=unix://csock 32*11be35a1SLionel Sambuc 33*11be35a1SLionel Sambucdomount() 34*11be35a1SLionel Sambuc{ 35*11be35a1SLionel Sambuc 36*11be35a1SLionel Sambuc mntdir=$1 37*11be35a1SLionel Sambuc [ $# -eq 0 ] && mntdir=/rump/mnt 38*11be35a1SLionel Sambuc atf_check -s exit:0 -e ignore mount_ffs /img ${mntdir} 39*11be35a1SLionel Sambuc} 40*11be35a1SLionel Sambuc 41*11be35a1SLionel Sambucdounmount() 42*11be35a1SLionel Sambuc{ 43*11be35a1SLionel Sambuc 44*11be35a1SLionel Sambuc atf_check -s exit:0 umount -R ${mntdir} 45*11be35a1SLionel Sambuc} 46*11be35a1SLionel Sambuc 47*11be35a1SLionel Sambucremount() 48*11be35a1SLionel Sambuc{ 49*11be35a1SLionel Sambuc 50*11be35a1SLionel Sambuc dounmount 51*11be35a1SLionel Sambuc domount /rump/mnt2 52*11be35a1SLionel Sambuc} 53*11be35a1SLionel Sambuc 54*11be35a1SLionel Sambucsimpletest() 55*11be35a1SLionel Sambuc{ 56*11be35a1SLionel Sambuc local name="${1}"; shift 57*11be35a1SLionel Sambuc 58*11be35a1SLionel Sambuc atf_test_case "${name}" cleanup 59*11be35a1SLionel Sambuc eval "${name}_head() { }" 60*11be35a1SLionel Sambuc eval "${name}_body() { \ 61*11be35a1SLionel Sambuc atf_check -s exit:0 rump_server -lrumpvfs ${RUMP_SERVER} ; \ 62*11be35a1SLionel Sambuc export LD_PRELOAD=/usr/lib/librumphijack.so ; \ 63*11be35a1SLionel Sambuc ${name} " "${@}" "; \ 64*11be35a1SLionel Sambuc }" 65*11be35a1SLionel Sambuc eval "${name}_cleanup() { \ 66*11be35a1SLionel Sambuc rump.halt 67*11be35a1SLionel Sambuc }" 68*11be35a1SLionel Sambuc} 69*11be35a1SLionel Sambuc 70*11be35a1SLionel Sambuctest_case() 71*11be35a1SLionel Sambuc{ 72*11be35a1SLionel Sambuc local name="${1}"; shift 73*11be35a1SLionel Sambuc 74*11be35a1SLionel Sambuc atf_test_case "${name}" cleanup 75*11be35a1SLionel Sambuc eval "${name}_head() { }" 76*11be35a1SLionel Sambuc eval "${name}_body() { \ 77*11be35a1SLionel Sambuc atf_check -s exit:0 -o ignore newfs -F -s 20000 ${img} ; \ 78*11be35a1SLionel Sambuc atf_check -s exit:0 ${rumpsrv_ffs} ${RUMP_SERVER} ; \ 79*11be35a1SLionel Sambuc export LD_PRELOAD=/usr/lib/librumphijack.so ; \ 80*11be35a1SLionel Sambuc mkdir /rump/mnt /rump/mnt2 ; \ 81*11be35a1SLionel Sambuc domount ; \ 82*11be35a1SLionel Sambuc ${name} " "${@}" "; \ 83*11be35a1SLionel Sambuc dounmount ${mntdir} 84*11be35a1SLionel Sambuc }" 85*11be35a1SLionel Sambuc eval "${name}_cleanup() { \ 86*11be35a1SLionel Sambuc rump.halt 87*11be35a1SLionel Sambuc }" 88*11be35a1SLionel Sambuc} 89*11be35a1SLionel Sambuc 90*11be35a1SLionel Sambuctest_case paxcopy 91*11be35a1SLionel Sambuctest_case cpcopy 92*11be35a1SLionel Sambuctest_case mv_nox 93*11be35a1SLionel Sambuctest_case ln_nox 94*11be35a1SLionel Sambuc 95*11be35a1SLionel Sambuc# 96*11be35a1SLionel Sambuc# use rumphijack to cp/pax stuff onto an image, unmount it, remount it 97*11be35a1SLionel Sambuc# at a different location, and check that we have an identical copy 98*11be35a1SLionel Sambuc# (we make a local copy to avoid the minor possibility that someone 99*11be35a1SLionel Sambuc# modifies the source dir data while the test is running) 100*11be35a1SLionel Sambuc# 101*11be35a1SLionel Sambucpaxcopy() 102*11be35a1SLionel Sambuc{ 103*11be35a1SLionel Sambuc parent=$(dirname $(atf_get_srcdir)) 104*11be35a1SLionel Sambuc thedir=$(basename $(atf_get_srcdir)) 105*11be35a1SLionel Sambuc atf_check -s exit:0 pax -rw -s,${parent},, $(atf_get_srcdir) . 106*11be35a1SLionel Sambuc atf_check -s exit:0 pax -rw ${thedir} /rump/mnt 107*11be35a1SLionel Sambuc remount 108*11be35a1SLionel Sambuc atf_check -s exit:0 diff -ru ${thedir} /rump/mnt2/${thedir} 109*11be35a1SLionel Sambuc} 110*11be35a1SLionel Sambuc 111*11be35a1SLionel Sambuccpcopy() 112*11be35a1SLionel Sambuc{ 113*11be35a1SLionel Sambuc thedir=$(basename $(atf_get_srcdir)) 114*11be35a1SLionel Sambuc atf_check -s exit:0 cp -Rp $(atf_get_srcdir) . 115*11be35a1SLionel Sambuc atf_check -s exit:0 cp -Rp ${thedir} /rump/mnt 116*11be35a1SLionel Sambuc remount 117*11be35a1SLionel Sambuc atf_check -s exit:0 diff -ru ${thedir} /rump/mnt2/${thedir} 118*11be35a1SLionel Sambuc} 119*11be35a1SLionel Sambuc 120*11be35a1SLionel Sambuc# 121*11be35a1SLionel Sambuc# non-crosskernel mv (non-simple test since this uses rename(2) 122*11be35a1SLionel Sambuc# which is not supported by rumpfs) 123*11be35a1SLionel Sambuc# 124*11be35a1SLionel Sambuc 125*11be35a1SLionel Sambucmv_nox() 126*11be35a1SLionel Sambuc{ 127*11be35a1SLionel Sambuc # stat default format sans changetime and filename 128*11be35a1SLionel Sambuc statstr='%d %i %Sp %l %Su %Sg %r %z \"%Sa\" \"%Sm\" \"%SB\" %k %b %#Xf' 129*11be35a1SLionel Sambuc 130*11be35a1SLionel Sambuc atf_check -s exit:0 touch /rump/mnt/filename 131*11be35a1SLionel Sambuc atf_check -s exit:0 -o save:stat.out \ 132*11be35a1SLionel Sambuc stat -f "${statstr}" /rump/mnt/filename 133*11be35a1SLionel Sambuc atf_check -s exit:0 mkdir /rump/mnt/dir 134*11be35a1SLionel Sambuc atf_check -s exit:0 mv /rump/mnt/filename /rump/mnt/dir/same 135*11be35a1SLionel Sambuc atf_check -s exit:0 -o file:stat.out \ 136*11be35a1SLionel Sambuc stat -f "${statstr}" /rump/mnt/dir/same 137*11be35a1SLionel Sambuc} 138*11be35a1SLionel Sambuc 139*11be35a1SLionel Sambucln_nox() 140*11be35a1SLionel Sambuc{ 141*11be35a1SLionel Sambuc # Omit st_nlink too, since it will increase. 142*11be35a1SLionel Sambuc statstr='%d %i %Sp %Su %Sg %r %z \"%Sa\" \"%Sm\" \"%SB\" %k %b %#Xf' 143*11be35a1SLionel Sambuc 144*11be35a1SLionel Sambuc atf_check -s exit:0 touch /rump/mnt/filename 145*11be35a1SLionel Sambuc atf_check -s exit:0 -o save:stat.out \ 146*11be35a1SLionel Sambuc stat -f "${statstr}" /rump/mnt/filename 147*11be35a1SLionel Sambuc atf_check -s exit:0 mkdir /rump/mnt/dir 148*11be35a1SLionel Sambuc atf_check -s exit:0 ln /rump/mnt/filename /rump/mnt/dir/same 149*11be35a1SLionel Sambuc atf_check -s exit:0 -o file:stat.out \ 150*11be35a1SLionel Sambuc stat -f "${statstr}" /rump/mnt/filename 151*11be35a1SLionel Sambuc atf_check -s exit:0 -o file:stat.out \ 152*11be35a1SLionel Sambuc stat -f "${statstr}" /rump/mnt/dir/same 153*11be35a1SLionel Sambuc} 154*11be35a1SLionel Sambuc 155*11be35a1SLionel Sambucsimpletest mv_x 156*11be35a1SLionel Sambucsimpletest ln_x 157*11be35a1SLionel Sambucsimpletest runonprefix 158*11be35a1SLionel Sambucsimpletest blanket 159*11be35a1SLionel Sambucsimpletest doubleblanket 160*11be35a1SLionel Sambuc 161*11be35a1SLionel Sambuc# 162*11be35a1SLionel Sambuc# do a cross-kernel mv 163*11be35a1SLionel Sambuc# 164*11be35a1SLionel Sambucmv_x() 165*11be35a1SLionel Sambuc{ 166*11be35a1SLionel Sambuc thedir=$(basename $(atf_get_srcdir)) 167*11be35a1SLionel Sambuc atf_check -s exit:0 cp -Rp $(atf_get_srcdir) . 168*11be35a1SLionel Sambuc atf_check -s exit:0 cp -Rp ${thedir} ${thedir}.2 169*11be35a1SLionel Sambuc atf_check -s exit:0 mv ${thedir} /rump 170*11be35a1SLionel Sambuc atf_check -s exit:0 diff -ru ${thedir}.2 /rump/${thedir} 171*11be35a1SLionel Sambuc} 172*11be35a1SLionel Sambuc 173*11be35a1SLionel Sambuc# 174*11be35a1SLionel Sambuc# Fail to make a cross-kernel hard link. 175*11be35a1SLionel Sambuc# 176*11be35a1SLionel Sambucln_x() 177*11be35a1SLionel Sambuc{ 178*11be35a1SLionel Sambuc atf_check -s exit:0 touch ./loser 179*11be35a1SLionel Sambuc atf_check -s not-exit:0 -e ignore ln ./loser /rump/. 180*11be35a1SLionel Sambuc} 181*11be35a1SLionel Sambuc 182*11be35a1SLionel Sambucrunonprefix() 183*11be35a1SLionel Sambuc{ 184*11be35a1SLionel Sambuc atf_check -s exit:0 -o ignore stat /rump/dev 185*11be35a1SLionel Sambuc atf_check -s exit:1 -e ignore stat /rumpdev 186*11be35a1SLionel Sambuc} 187*11be35a1SLionel Sambuc 188*11be35a1SLionel Sambucblanket() 189*11be35a1SLionel Sambuc{ 190*11be35a1SLionel Sambuc export RUMPHIJACK='blanket=/dev,path=/rump' 191*11be35a1SLionel Sambuc atf_check -s exit:0 -o save:stat.out \ 192*11be35a1SLionel Sambuc stat -f "${statstr}" /rump/dev/null 193*11be35a1SLionel Sambuc atf_check -s exit:0 -o file:stat.out \ 194*11be35a1SLionel Sambuc stat -f "${statstr}" /dev/null 195*11be35a1SLionel Sambuc} 196*11be35a1SLionel Sambuc 197*11be35a1SLionel Sambucdoubleblanket() 198*11be35a1SLionel Sambuc{ 199*11be35a1SLionel Sambuc atf_check -s exit:0 mkdir /rump/dir 200*11be35a1SLionel Sambuc atf_check -s exit:0 ln -s dir /rump/dirtoo 201*11be35a1SLionel Sambuc 202*11be35a1SLionel Sambuc export RUMPHIJACK='blanket=/dirtoo:/dir' 203*11be35a1SLionel Sambuc atf_check -s exit:0 touch /dir/file 204*11be35a1SLionel Sambuc 205*11be35a1SLionel Sambuc atf_check -s exit:0 -o save:stat.out \ 206*11be35a1SLionel Sambuc stat -f "${statstr}" /dir/file 207*11be35a1SLionel Sambuc atf_check -s exit:0 -o file:stat.out \ 208*11be35a1SLionel Sambuc stat -f "${statstr}" /dirtoo/file 209*11be35a1SLionel Sambuc} 210*11be35a1SLionel Sambuc 211*11be35a1SLionel Sambucatf_init_test_cases() 212*11be35a1SLionel Sambuc{ 213*11be35a1SLionel Sambuc 214*11be35a1SLionel Sambuc atf_add_test_case paxcopy 215*11be35a1SLionel Sambuc atf_add_test_case cpcopy 216*11be35a1SLionel Sambuc atf_add_test_case mv_x 217*11be35a1SLionel Sambuc atf_add_test_case ln_x 218*11be35a1SLionel Sambuc atf_add_test_case mv_nox 219*11be35a1SLionel Sambuc atf_add_test_case ln_nox 220*11be35a1SLionel Sambuc atf_add_test_case runonprefix 221*11be35a1SLionel Sambuc atf_add_test_case blanket 222*11be35a1SLionel Sambuc atf_add_test_case doubleblanket 223*11be35a1SLionel Sambuc} 224