1 # Copyright (c) 2012 Edward Tomasz NapieraĆa <trasz@FreeBSD.org>
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions
7 # 1. Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 # 2. Redistributions in binary form must reproduce the above copyright
10 # notice, this list of conditions and the following disclaimer in the
11 # documentation and/or other materials provided with the distribution.
13 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 local mediasize_in_bytes=$2
32 local mediasize_in_sectors=$3
33 local sectorsize=${4:-512}
34 local stripesize=${5:-0}
35 local stripeoffset=${6:-0}
38 -o match:"/dev/$md *$sectorsize *$mediasize_in_bytes *$mediasize_in_sectors *$stripesize *$stripeoffset" \
39 -x "diskinfo /dev/$md | expand"
44 if [ -f mdconfig.out ]; then
45 mdconfig -d -u $(sed -e 's/md//' mdconfig.out)
49 atf_test_case attach_vnode_non_explicit_type cleanup
50 attach_vnode_non_explicit_type_head()
52 atf_set "descr" "Tests out -a / -f without -t"
54 attach_vnode_non_explicit_type_body()
59 atf_check -s exit:0 -x "truncate -s ${size_in_mb}m xxx"
60 atf_check -s exit:0 -o save:mdconfig.out -x 'mdconfig -af xxx'
61 md=$(cat mdconfig.out)
62 atf_check -s exit:0 -o match:'^md[0-9]+$' -x "echo $md"
63 check_diskinfo "$md" "1073741824" "2097152"
64 # This awk strips the file path.
65 atf_check -s exit:0 -o match:"^$md vnode ${size_in_mb}M$" \
66 -x "mdconfig -lv | awk '\$1 == \"$md\" { print \$1, \$2, \$3 }'"
68 attach_vnode_non_explicit_type_cleanup()
73 atf_test_case attach_vnode_implicit_a_f cleanup
74 attach_vnode_implicit_a_f_head()
76 atf_set "descr" "Tests out implied -a / -f without -t"
78 attach_vnode_implicit_a_f_body()
83 atf_check -s exit:0 -x "truncate -s ${size_in_mb}m xxx"
84 atf_check -s exit:0 -o save:mdconfig.out -x 'mdconfig xxx'
85 md=$(cat mdconfig.out)
86 atf_check -s exit:0 -o match:'^md[0-9]+$' -x "echo $md"
87 check_diskinfo "$md" "1073741824" "2097152"
88 # This awk strips the file path.
89 atf_check -s exit:0 -o match:"^$md vnode ${size_in_mb}M$" \
90 -x "mdconfig -lv | awk '\$1 == \"$md\" { print \$1, \$2, \$3 }'"
92 attach_vnode_implicit_a_f_cleanup()
97 atf_test_case attach_vnode_explicit_type cleanup
98 attach_vnode_explicit_type_head()
100 atf_set "descr" "Tests out implied -a / -f with -t vnode"
102 attach_vnode_explicit_type_body()
105 local size_in_mb=1024
107 atf_check -s exit:0 -x "truncate -s ${size_in_mb}m xxx"
108 atf_check -s exit:0 -o save:mdconfig.out -x 'mdconfig -af xxx -t vnode'
109 md=$(cat mdconfig.out)
110 atf_check -s exit:0 -o match:'^md[0-9]+$' -x "echo $md"
111 check_diskinfo "$md" "1073741824" "2097152"
112 # This awk strips the file path.
113 atf_check -s exit:0 -o match:"^$md vnode ${size_in_mb}M$" \
114 -x "mdconfig -lv | awk '\$1 == \"$md\" { print \$1, \$2, \$3 }'"
116 attach_vnode_explicit_type_cleanup()
118 [ -f mdconfig.out ] && mdconfig -d -u $(sed -e 's/md//' mdconfig.out)
119 rm -f mdconfig.out xxx
122 atf_test_case attach_vnode_smaller_than_file cleanup
123 attach_vnode_smaller_than_file_head()
125 atf_set "descr" "Tests mdconfig -s with size less than the file size"
127 attach_vnode_smaller_than_file_body()
132 atf_check -s exit:0 -x "truncate -s 1024m xxx"
133 atf_check -s exit:0 -o save:mdconfig.out \
134 -x "mdconfig -af xxx -s ${size_in_mb}m"
135 md=$(cat mdconfig.out)
136 atf_check -s exit:0 -o match:'^md[0-9]+$' -x "echo $md"
137 check_diskinfo "$md" "134217728" "262144"
138 # This awk strips the file path.
139 atf_check -s exit:0 -o match:"^$md vnode ${size_in_mb}M$" \
140 -x "mdconfig -lv | awk '\$1 == \"$md\" { print \$1, \$2, \$3 }'"
142 attach_vnode_smaller_than_file_cleanup()
147 atf_test_case attach_vnode_larger_than_file cleanup
148 attach_vnode_larger_than_file_head()
150 atf_set "descr" "Tests mdconfig -s with size greater than the file size"
152 attach_vnode_larger_than_file_body()
157 atf_check -s exit:0 -x "truncate -s 1024m xxx"
158 atf_check -s exit:0 -o save:mdconfig.out \
159 -x "mdconfig -af xxx -s ${size_in_gb}g"
160 md=$(cat mdconfig.out)
161 atf_check -s exit:0 -o match:'^md[0-9]+$' -x "echo $md"
162 check_diskinfo "$md" "137438953472" "268435456"
163 # This awk strips the file path.
164 atf_check -s exit:0 -o match:"^$md vnode ${size_in_gb}G$" \
165 -x "mdconfig -lv | awk '\$1 == \"$md\" { print \$1, \$2, \$3 }'"
167 attach_vnode_larger_than_file_cleanup()
172 atf_test_case attach_vnode_sector_size cleanup
173 attach_vnode_sector_size_head()
175 atf_set "descr" "Tests mdconfig -s with size greater than the file size"
177 attach_vnode_sector_size_body()
180 local size_in_mb=1024
182 atf_check -s exit:0 -x "truncate -s ${size_in_mb}m xxx"
183 atf_check -s exit:0 -o save:mdconfig.out \
184 -x "mdconfig -af xxx -S 2048"
185 md=$(cat mdconfig.out)
186 atf_check -s exit:0 -o match:'^md[0-9]+$' -x "echo $md"
187 check_diskinfo "$md" "1073741824" "524288" "2048"
188 # This awk strips the file path.
189 atf_check -s exit:0 -o match:"^$md vnode ${size_in_mb}M$" \
190 -x "mdconfig -lv | awk '\$1 == \"$md\" { print \$1, \$2, \$3 }'"
192 attach_vnode_sector_size_cleanup()
197 atf_test_case attach_malloc cleanup
200 atf_set "descr" "Tests mdconfig with -t malloc"
205 local size_in_mb=1024
207 atf_check -s exit:0 -o save:mdconfig.out \
208 -x 'mdconfig -a -t malloc -s 1g'
209 md=$(cat mdconfig.out)
210 atf_check -s exit:0 -o match:'^md[0-9]+$' -x "echo $md"
211 check_diskinfo "$md" "1073741824" "2097152"
212 # This awk strips the file path.
213 atf_check -s exit:0 -o match:"^$md malloc ${size_in_mb}M$" \
214 -x "mdconfig -lv | awk '\$1 == \"$md\" { print \$1, \$2, \$3 }'"
216 attach_malloc_cleanup()
221 atf_test_case attach_swap cleanup
224 atf_set "descr" "Tests mdconfig with -t swap"
229 local size_in_mb=1024
231 atf_check -s exit:0 -o save:mdconfig.out \
232 -x 'mdconfig -a -t swap -s 1g'
233 md=$(cat mdconfig.out)
234 atf_check -s exit:0 -o match:'^md[0-9]+$' -x "echo $md"
235 check_diskinfo "$md" "1073741824" "2097152"
236 # This awk strips the file path.
237 atf_check -s exit:0 -o match:"^$md swap ${size_in_mb}M$" \
238 -x "mdconfig -lv | awk '\$1 == \"$md\" { print \$1, \$2, \$3 }'"
240 attach_swap_cleanup()
245 atf_test_case attach_with_specific_unit_number cleanup
246 attach_with_specific_unit_number_head()
248 atf_set "descr" "Tests mdconfig with a unit specified by -u"
250 attach_with_specific_unit_number_body()
255 local md="md${md_unit}"
257 echo "$md" > mdconfig.out
259 atf_check -s exit:0 -o empty \
260 -x "mdconfig -a -t malloc -s ${size_in_mb}m -u $md_unit"
261 check_diskinfo "$md" "10485760" "20480"
262 # This awk strips the file path.
263 atf_check -s exit:0 -o match:"^$md malloc "$size_in_mb"M$" \
264 -x "mdconfig -lv | awk '\$1 == \"$md\" { print \$1, \$2, \$3 }'"
266 attach_with_specific_unit_number_cleanup()
271 atf_init_test_cases()
273 atf_add_test_case attach_vnode_non_explicit_type
274 atf_add_test_case attach_vnode_explicit_type
275 atf_add_test_case attach_vnode_smaller_than_file
276 atf_add_test_case attach_vnode_larger_than_file
277 atf_add_test_case attach_vnode_sector_size
278 atf_add_test_case attach_malloc
279 atf_add_test_case attach_swap
280 atf_add_test_case attach_with_specific_unit_number