Home | History | Annotate | Line # | Download | only in ffs
t_setquota.sh revision 1.1.2.3
      1 # $NetBSD: t_setquota.sh,v 1.1.2.3 2011/01/30 19:49:48 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   7days       1      20   51200   7days" \
     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        -        -" \
     97 		    $(atf_get_srcdir)/rump_repquota -${q} /mnt
     98 	done
     99 	atf_check -s exit:0 rump.halt
    100 # check that the quota inode creation didn't corrupt the filesystem
    101 	atf_check -s exit:0 -o "match:already clean" \
    102 		-o "match:Phase 6 - Check Quotas" \
    103 		fsck_ffs -nf -F ${IMG}
    104 }
    105 
    106 set_quota_new()
    107 {
    108 	create_with_quotas $*
    109 	local q=$3
    110 	local expect
    111 	local fail
    112 
    113 	case ${q} in
    114 	user)
    115 		expect=u
    116 		fail=g
    117 		;;
    118 	group)
    119 		expect=g
    120 		fail=u
    121 		;;
    122 	both)
    123 		expect="u g"
    124 		fail=""
    125 		;;
    126 	*)
    127 		atf_fail "wrong quota type"
    128 		;;
    129 	esac
    130 
    131 #check that we can set the expected quota
    132 	for q in ${expect} ; do
    133 		local id=1
    134 		atf_check -s exit:0 \
    135 		   $(atf_get_srcdir)/rump_edquota -$q -s10k/20 -h40M/50k ${id}
    136 		atf_check -s exit:0 \
    137 -o "match:/mnt        0       10    40960   7days       0      20   51200   7days" \
    138 -o "match:Disk quotas for .*: $" \
    139 		    $(atf_get_srcdir)/rump_quota -${q} -v ${id}
    140 	done
    141 
    142 #check that we do not get positive reply for non-expected quota
    143 	for q in ${fail} ; do
    144 		local id=$(id -${q})
    145 		atf_check -s exit:0 \
    146 		   $(atf_get_srcdir)/rump_edquota -$q -s10k/20 -h40M/50k ${id}
    147 		atf_check -s exit:0 -o "not-match:/mnt" \
    148 		    -o "not-match:Disk quotas for .*: $" \
    149 		    -o "match:Disk quotas for .*: none$" \
    150 		    $(atf_get_srcdir)/rump_quota -${q} -v ${id}
    151 	done
    152 	atf_check -s exit:0 rump.halt
    153 # check that the quota inode creation didn't corrupt the filesystem
    154 	atf_check -s exit:0 -o "match:already clean" \
    155 		-o "match:Phase 6 - Check Quotas" \
    156 		fsck_ffs -nf -F ${IMG}
    157 }
    158 
    159 set_quota_default()
    160 {
    161 	create_with_quotas $*
    162 	local q=$3
    163 	local expect
    164 	local fail
    165 
    166 	case ${q} in
    167 	user)
    168 		expect=u
    169 		fail=g
    170 		;;
    171 	group)
    172 		expect=g
    173 		fail=u
    174 		;;
    175 	both)
    176 		expect="u g"
    177 		fail=""
    178 		;;
    179 	*)
    180 		atf_fail "wrong quota type"
    181 		;;
    182 	esac
    183 
    184 #check that we can set the expected quota
    185 	for q in ${expect} ; do
    186 		local id="-d"
    187 		atf_check -s exit:0 \
    188 		   $(atf_get_srcdir)/rump_edquota -$q -s10k/20 -h40M/50k ${id}
    189 		atf_check -s exit:0 \
    190 -o "match:/mnt        0       10    40960   7days       0      20   51200   7days" \
    191 -o "match:Default (user|group) disk quotas: $" \
    192 		    $(atf_get_srcdir)/rump_quota -${q} -v ${id}
    193 	done
    194 
    195 #check that we do not get positive reply for non-expected quota
    196 	for q in ${fail} ; do
    197 		local id="-d"
    198 		atf_check -s exit:0 \
    199 		   $(atf_get_srcdir)/rump_edquota -$q -s10k/20 -h40M/50k ${id}
    200 		atf_check -s exit:0 -o "not-match:/mnt" \
    201 		    -o "not-match:Default (user|group) disk quotas: $" \
    202 		    -o "match:Default (user|group) disk quotas: none$" \
    203 		    $(atf_get_srcdir)/rump_quota -${q} -v ${id}
    204 	done
    205 	atf_check -s exit:0 rump.halt
    206 # check that the quota inode creation didn't corrupt the filesystem
    207 	atf_check -s exit:0 -o "match:already clean" \
    208 		-o "match:Phase 6 - Check Quotas" \
    209 		fsck_ffs -nf -F ${IMG}
    210 }
    211