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