1272343Sngie# $NetBSD: t_vfs.sh,v 1.6 2012/08/04 03:56:47 riastradh Exp $ 2272343Sngie# 3272343Sngie# Copyright (c) 2011 The NetBSD Foundation, Inc. 4272343Sngie# All rights reserved. 5272343Sngie# 6272343Sngie# Redistribution and use in source and binary forms, with or without 7272343Sngie# modification, are permitted provided that the following conditions 8272343Sngie# are met: 9272343Sngie# 1. Redistributions of source code must retain the above copyright 10272343Sngie# notice, this list of conditions and the following disclaimer. 11272343Sngie# 2. Redistributions in binary form must reproduce the above copyright 12272343Sngie# notice, this list of conditions and the following disclaimer in the 13272343Sngie# documentation and/or other materials provided with the distribution. 14272343Sngie# 15272343Sngie# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16272343Sngie# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17272343Sngie# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18272343Sngie# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19272343Sngie# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20272343Sngie# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21272343Sngie# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22272343Sngie# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23272343Sngie# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24272343Sngie# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25272343Sngie# POSSIBILITY OF SUCH DAMAGE. 26272343Sngie# 27272343Sngie 28272343Sngieimg=ffs.img 29272343Sngierumpsrv_ffs=\ 30272343Sngie"rump_server -lrumpvfs -lrumpfs_ffs -lrumpdev_disk -d key=/img,hostpath=${img},size=host" 31272343Sngieexport RUMP_SERVER=unix://csock 32272343Sngie 33272343Sngiedomount() 34272343Sngie{ 35272343Sngie 36272343Sngie mntdir=$1 37272343Sngie [ $# -eq 0 ] && mntdir=/rump/mnt 38272343Sngie atf_check -s exit:0 -e ignore mount_ffs /img ${mntdir} 39272343Sngie} 40272343Sngie 41272343Sngiedounmount() 42272343Sngie{ 43272343Sngie 44272343Sngie atf_check -s exit:0 umount -R ${mntdir} 45272343Sngie} 46272343Sngie 47272343Sngieremount() 48272343Sngie{ 49272343Sngie 50272343Sngie dounmount 51272343Sngie domount /rump/mnt2 52272343Sngie} 53272343Sngie 54272343Sngiesimpletest() 55272343Sngie{ 56272343Sngie local name="${1}"; shift 57272343Sngie 58272343Sngie atf_test_case "${name}" cleanup 59272343Sngie eval "${name}_head() { }" 60272343Sngie eval "${name}_body() { \ 61272343Sngie atf_check -s exit:0 rump_server -lrumpvfs ${RUMP_SERVER} ; \ 62272343Sngie export LD_PRELOAD=/usr/lib/librumphijack.so ; \ 63272343Sngie ${name} " "${@}" "; \ 64272343Sngie }" 65272343Sngie eval "${name}_cleanup() { \ 66272343Sngie rump.halt 67272343Sngie }" 68272343Sngie} 69272343Sngie 70272343Sngietest_case() 71272343Sngie{ 72272343Sngie local name="${1}"; shift 73272343Sngie 74272343Sngie atf_test_case "${name}" cleanup 75272343Sngie eval "${name}_head() { }" 76272343Sngie eval "${name}_body() { \ 77272343Sngie atf_check -s exit:0 -o ignore newfs -F -s 20000 ${img} ; \ 78272343Sngie atf_check -s exit:0 ${rumpsrv_ffs} ${RUMP_SERVER} ; \ 79272343Sngie export LD_PRELOAD=/usr/lib/librumphijack.so ; \ 80272343Sngie mkdir /rump/mnt /rump/mnt2 ; \ 81272343Sngie domount ; \ 82272343Sngie ${name} " "${@}" "; \ 83272343Sngie dounmount ${mntdir} 84272343Sngie }" 85272343Sngie eval "${name}_cleanup() { \ 86272343Sngie rump.halt 87272343Sngie }" 88272343Sngie} 89272343Sngie 90272343Sngietest_case paxcopy 91272343Sngietest_case cpcopy 92272343Sngietest_case mv_nox 93272343Sngietest_case ln_nox 94272343Sngie 95272343Sngie# 96272343Sngie# use rumphijack to cp/pax stuff onto an image, unmount it, remount it 97272343Sngie# at a different location, and check that we have an identical copy 98272343Sngie# (we make a local copy to avoid the minor possibility that someone 99272343Sngie# modifies the source dir data while the test is running) 100272343Sngie# 101272343Sngiepaxcopy() 102272343Sngie{ 103272343Sngie parent=$(dirname $(atf_get_srcdir)) 104272343Sngie thedir=$(basename $(atf_get_srcdir)) 105272343Sngie atf_check -s exit:0 pax -rw -s,${parent},, $(atf_get_srcdir) . 106272343Sngie atf_check -s exit:0 pax -rw ${thedir} /rump/mnt 107272343Sngie remount 108272343Sngie atf_check -s exit:0 diff -ru ${thedir} /rump/mnt2/${thedir} 109272343Sngie} 110272343Sngie 111272343Sngiecpcopy() 112272343Sngie{ 113272343Sngie thedir=$(basename $(atf_get_srcdir)) 114272343Sngie atf_check -s exit:0 cp -Rp $(atf_get_srcdir) . 115272343Sngie atf_check -s exit:0 cp -Rp ${thedir} /rump/mnt 116272343Sngie remount 117272343Sngie atf_check -s exit:0 diff -ru ${thedir} /rump/mnt2/${thedir} 118272343Sngie} 119272343Sngie 120272343Sngie# 121272343Sngie# non-crosskernel mv (non-simple test since this uses rename(2) 122272343Sngie# which is not supported by rumpfs) 123272343Sngie# 124272343Sngie 125272343Sngiemv_nox() 126272343Sngie{ 127272343Sngie # stat default format sans changetime and filename 128272343Sngie statstr='%d %i %Sp %l %Su %Sg %r %z \"%Sa\" \"%Sm\" \"%SB\" %k %b %#Xf' 129272343Sngie 130272343Sngie atf_check -s exit:0 touch /rump/mnt/filename 131272343Sngie atf_check -s exit:0 -o save:stat.out \ 132272343Sngie stat -f "${statstr}" /rump/mnt/filename 133272343Sngie atf_check -s exit:0 mkdir /rump/mnt/dir 134272343Sngie atf_check -s exit:0 mv /rump/mnt/filename /rump/mnt/dir/same 135272343Sngie atf_check -s exit:0 -o file:stat.out \ 136272343Sngie stat -f "${statstr}" /rump/mnt/dir/same 137272343Sngie} 138272343Sngie 139272343Sngieln_nox() 140272343Sngie{ 141272343Sngie # Omit st_nlink too, since it will increase. 142272343Sngie statstr='%d %i %Sp %Su %Sg %r %z \"%Sa\" \"%Sm\" \"%SB\" %k %b %#Xf' 143272343Sngie 144272343Sngie atf_check -s exit:0 touch /rump/mnt/filename 145272343Sngie atf_check -s exit:0 -o save:stat.out \ 146272343Sngie stat -f "${statstr}" /rump/mnt/filename 147272343Sngie atf_check -s exit:0 mkdir /rump/mnt/dir 148272343Sngie atf_check -s exit:0 ln /rump/mnt/filename /rump/mnt/dir/same 149272343Sngie atf_check -s exit:0 -o file:stat.out \ 150272343Sngie stat -f "${statstr}" /rump/mnt/filename 151272343Sngie atf_check -s exit:0 -o file:stat.out \ 152272343Sngie stat -f "${statstr}" /rump/mnt/dir/same 153272343Sngie} 154272343Sngie 155272343Sngiesimpletest mv_x 156272343Sngiesimpletest ln_x 157272343Sngiesimpletest runonprefix 158272343Sngiesimpletest blanket 159272343Sngiesimpletest doubleblanket 160272343Sngie 161272343Sngie# 162272343Sngie# do a cross-kernel mv 163272343Sngie# 164272343Sngiemv_x() 165272343Sngie{ 166272343Sngie thedir=$(basename $(atf_get_srcdir)) 167272343Sngie atf_check -s exit:0 cp -Rp $(atf_get_srcdir) . 168272343Sngie atf_check -s exit:0 cp -Rp ${thedir} ${thedir}.2 169272343Sngie atf_check -s exit:0 mv ${thedir} /rump 170272343Sngie atf_check -s exit:0 diff -ru ${thedir}.2 /rump/${thedir} 171272343Sngie} 172272343Sngie 173272343Sngie# 174272343Sngie# Fail to make a cross-kernel hard link. 175272343Sngie# 176272343Sngieln_x() 177272343Sngie{ 178272343Sngie atf_check -s exit:0 touch ./loser 179272343Sngie atf_check -s not-exit:0 -e ignore ln ./loser /rump/. 180272343Sngie} 181272343Sngie 182272343Sngierunonprefix() 183272343Sngie{ 184272343Sngie atf_check -s exit:0 -o ignore stat /rump/dev 185272343Sngie atf_check -s exit:1 -e ignore stat /rumpdev 186272343Sngie} 187272343Sngie 188272343Sngieblanket() 189272343Sngie{ 190272343Sngie export RUMPHIJACK='blanket=/dev,path=/rump' 191272343Sngie atf_check -s exit:0 -o save:stat.out \ 192272343Sngie stat -f "${statstr}" /rump/dev/null 193272343Sngie atf_check -s exit:0 -o file:stat.out \ 194272343Sngie stat -f "${statstr}" /dev/null 195272343Sngie} 196272343Sngie 197272343Sngiedoubleblanket() 198272343Sngie{ 199272343Sngie atf_check -s exit:0 mkdir /rump/dir 200272343Sngie atf_check -s exit:0 ln -s dir /rump/dirtoo 201272343Sngie 202272343Sngie export RUMPHIJACK='blanket=/dirtoo:/dir' 203272343Sngie atf_check -s exit:0 touch /dir/file 204272343Sngie 205272343Sngie atf_check -s exit:0 -o save:stat.out \ 206272343Sngie stat -f "${statstr}" /dir/file 207272343Sngie atf_check -s exit:0 -o file:stat.out \ 208272343Sngie stat -f "${statstr}" /dirtoo/file 209272343Sngie} 210272343Sngie 211272343Sngieatf_init_test_cases() 212272343Sngie{ 213272343Sngie 214272343Sngie atf_add_test_case paxcopy 215272343Sngie atf_add_test_case cpcopy 216272343Sngie atf_add_test_case mv_x 217272343Sngie atf_add_test_case ln_x 218272343Sngie atf_add_test_case mv_nox 219272343Sngie atf_add_test_case ln_nox 220272343Sngie atf_add_test_case runonprefix 221272343Sngie atf_add_test_case blanket 222272343Sngie atf_add_test_case doubleblanket 223272343Sngie} 224