Home | History | Annotate | Line # | Download | only in ffs
t_setquota.sh revision 1.1.2.2
      1 # $NetBSD: t_setquota.sh,v 1.1.2.2 2011/01/30 13:23:26 bouyer Exp $ 
      2 #
      3 #  Copyright (c) 2011 Manuel Bouyer
      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 for e in le be; do
     29   for v in 1 2; do
     30     for q in "user" "group"; do
     31       test_case_root set_${e}_${v}_${q} set_quota \
     32 	 "set quota with ${q} enabled" ${e} ${v} ${q}
     33       test_case_root set_new_${e}_${v}_${q} set_quota_new \
     34 	 "set quota for new id with ${q} enabled" ${e} ${v} ${q}
     35       test_case_root set_default_${e}_${v}_${q} set_quota_default \
     36 	 "set default quota with ${q} enabled" ${e} ${v} ${q}
     37     done
     38     test_case_root set_${e}_${v}_"both" set_quota \
     39 	 "set quota with both enabled" ${e} ${v} "both"
     40     test_case_root set_new_${e}_${v}_"both" set_quota_new \
     41 	 "set quota for new id with both enabled" ${e} ${v} "both"
     42     test_case_root set_default_${e}_${v}_"both" set_quota_default \
     43 	 "set default quota with both enabled" ${e} ${v} "both"
     44   done
     45 done
     46 
     47 set_quota()
     48 {
     49 	create_with_quotas $*
     50 	local q=$3
     51 	local expect
     52 	local fail
     53 
     54 	case ${q} in
     55 	user)
     56 		expect=u
     57 		fail=g
     58 		;;
     59 	group)
     60 		expect=g
     61 		fail=u
     62 		;;
     63 	both)
     64 		expect="u g"
     65 		fail=""
     66 		;;
     67 	*)
     68 		atf_fail "wrong quota type"
     69 		;;
     70 	esac
     71 
     72 #check that we can set the expected quota
     73 	for q in ${expect} ; do
     74 		local id=$(id -${q})
     75 		atf_check -s exit:0 \
     76 		   $(atf_get_srcdir)/rump_edquota -$q -s10k/20 -h40M/50k ${id}
     77 		atf_check -s exit:0 \
     78 -o "match:/mnt        0       10    40960               1      20   51200" \
     79 -o "match:Disk quotas for .*: $" \
     80 		    $(atf_get_srcdir)/rump_quota -${q} -v
     81 		atf_check -s exit:0 \
     82 -o "match:--        0       10    40960                1      20   51200" \
     83 		    $(atf_get_srcdir)/rump_repquota -${q} /mnt
     84 	done
     85 
     86 #check that we do not get positive reply for non-expected quota
     87 	for q in ${fail} ; do
     88 		local id=$(id -${q})
     89 		atf_check -s exit:0 \
     90 		   $(atf_get_srcdir)/rump_edquota -$q -s10k/20 -h40M/50k ${id}
     91 		atf_check -s exit:0 -o "not-match:/mnt" \
     92 		    -o "not-match:Disk quotas for .*: $" \
     93 		    -o "match:Disk quotas for .*: none$" \
     94 		    $(atf_get_srcdir)/rump_quota -${q} -v
     95 		atf_check -s exit:0 \
     96 -o "not-match:--        0        -        -                1       -       -" \
     97 		    $(atf_get_srcdir)/rump_repquota -${q} /mnt
     98 	done
     99 	atf_check -s exit:0 rump.halt
    100 #wait for rump server to be gone
    101 	while [ -e ${RUMP_SOCKET} ] ; do done
    102 	sleep 1
    103 # check that the quota inode creation didn't corrupt the filesystem
    104 	atf_check -s exit:0 -o "match:already clean" \
    105 		-o "match:Phase 6 - Check Quotas" \
    106 		fsck_ffs -nf -F ${IMG}
    107 }
    108 
    109 set_quota_new()
    110 {
    111 	create_with_quotas $*
    112 	local q=$3
    113 	local expect
    114 	local fail
    115 
    116 	case ${q} in
    117 	user)
    118 		expect=u
    119 		fail=g
    120 		;;
    121 	group)
    122 		expect=g
    123 		fail=u
    124 		;;
    125 	both)
    126 		expect="u g"
    127 		fail=""
    128 		;;
    129 	*)
    130 		atf_fail "wrong quota type"
    131 		;;
    132 	esac
    133 
    134 #check that we can set the expected quota
    135 	for q in ${expect} ; do
    136 		local id=1
    137 		atf_check -s exit:0 \
    138 		   $(atf_get_srcdir)/rump_edquota -$q -s10k/20 -h40M/50k ${id}
    139 		atf_check -s exit:0 \
    140 -o "match:/mnt        0       10    40960               0      20   51200" \
    141 -o "match:Disk quotas for .*: $" \
    142 		    $(atf_get_srcdir)/rump_quota -${q} -v ${id}
    143 	done
    144 
    145 #check that we do not get positive reply for non-expected quota
    146 	for q in ${fail} ; do
    147 		local id=$(id -${q})
    148 		atf_check -s exit:0 \
    149 		   $(atf_get_srcdir)/rump_edquota -$q -s10k/20 -h40M/50k ${id}
    150 		atf_check -s exit:0 -o "not-match:/mnt" \
    151 		    -o "not-match:Disk quotas for .*: $" \
    152 		    -o "match:Disk quotas for .*: none$" \
    153 		    $(atf_get_srcdir)/rump_quota -${q} -v ${id}
    154 	done
    155 	atf_check -s exit:0 rump.halt
    156 #wait for rump server to be gone
    157 	while [ -e ${RUMP_SOCKET} ] ; do done
    158 	sleep 1
    159 # check that the quota inode creation didn't corrupt the filesystem
    160 	atf_check -s exit:0 -o "match:already clean" \
    161 		-o "match:Phase 6 - Check Quotas" \
    162 		fsck_ffs -nf -F ${IMG}
    163 }
    164 
    165 set_quota_default()
    166 {
    167 	create_with_quotas $*
    168 	local q=$3
    169 	local expect
    170 	local fail
    171 
    172 	case ${q} in
    173 	user)
    174 		expect=u
    175 		fail=g
    176 		;;
    177 	group)
    178 		expect=g
    179 		fail=u
    180 		;;
    181 	both)
    182 		expect="u g"
    183 		fail=""
    184 		;;
    185 	*)
    186 		atf_fail "wrong quota type"
    187 		;;
    188 	esac
    189 
    190 #check that we can set the expected quota
    191 	for q in ${expect} ; do
    192 		local id="-d"
    193 		atf_check -s exit:0 \
    194 		   $(atf_get_srcdir)/rump_edquota -$q -s10k/20 -h40M/50k ${id}
    195 		atf_check -s exit:0 \
    196 -o "match:/mnt        0       10    40960               0      20   51200" \
    197 -o "match:Default (user|group) disk quotas: $" \
    198 		    $(atf_get_srcdir)/rump_quota -${q} -v ${id}
    199 	done
    200 
    201 #check that we do not get positive reply for non-expected quota
    202 	for q in ${fail} ; do
    203 		local id="-d"
    204 		atf_check -s exit:0 \
    205 		   $(atf_get_srcdir)/rump_edquota -$q -s10k/20 -h40M/50k ${id}
    206 		atf_check -s exit:0 -o "not-match:/mnt" \
    207 		    -o "not-match:Default (user|group) disk quotas: $" \
    208 		    -o "match:Default (user|group) disk quotas: none$" \
    209 		    $(atf_get_srcdir)/rump_quota -${q} -v ${id}
    210 	done
    211 	atf_check -s exit:0 rump.halt
    212 #wait for rump server to be gone
    213 	while [ -e ${RUMP_SOCKET} ] ; do done
    214 	sleep 1
    215 # check that the quota inode creation didn't corrupt the filesystem
    216 	atf_check -s exit:0 -o "match:already clean" \
    217 		-o "match:Phase 6 - Check Quotas" \
    218 		fsck_ffs -nf -F ${IMG}
    219 }
    220