Home | History | Annotate | Line # | Download | only in librumphijack
t_vfs.sh revision 1.2.2.2
      1 #       $NetBSD: t_vfs.sh,v 1.2.2.2 2011/03/05 15:10:56 bouyer 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 -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 
     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 #
    100 paxcopy()
    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 
    110 cpcopy()
    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
    125 statstr='%d %i %Sp %l %Su %Sg %r %z \"%Sa\" \"%Sm\" \"%SB\" %k %b %#Xf'
    126 mv_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 
    138 simpletest mv_x
    139 
    140 #
    141 # do a cross-kernel mv
    142 #
    143 mv_x()
    144 {
    145 	thedir=$(basename $(atf_get_srcdir))
    146 	atf_check -s exit:0 cp -Rp $(atf_get_srcdir) .
    147 	atf_check -s exit:0 cp -Rp ${thedir} ${thedir}.2
    148 	atf_check -s exit:0 mv ${thedir} /rump
    149 	atf_check -s exit:0 diff -ru ${thedir}.2 /rump/${thedir}
    150 }
    151 
    152 atf_init_test_cases()
    153 {
    154 
    155 	atf_add_test_case paxcopy
    156 	atf_add_test_case cpcopy
    157 	atf_add_test_case mv_x
    158 	atf_add_test_case mv_nox
    159 }
    160