1 # Copyright (c) 2012 Edward Tomasz NapieraĆa <trasz@FreeBSD.org>
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions
6 # 1. Redistributions of source code must retain the above copyright
7 # notice, this list of conditions and the following disclaimer.
8 # 2. Redistributions in binary form must reproduce the above copyright
9 # notice, this list of conditions and the following disclaimer in the
10 # documentation and/or other materials provided with the distribution.
12 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 local mediasize_in_bytes=$2
31 local mediasize_in_sectors=$3
32 local sectorsize=${4:-512}
33 local stripesize=${5:-0}
34 local stripeoffset=${6:-0}
37 -o match:"/dev/$md *$sectorsize *$mediasize_in_bytes *$mediasize_in_sectors *$stripesize *$stripeoffset" \
38 -x "diskinfo /dev/$md | expand"
43 if [ -f mdconfig.out ]; then
44 mdconfig -d -u $(sed -e 's/md//' mdconfig.out)
48 atf_test_case attach_vnode_non_explicit_type cleanup
49 attach_vnode_non_explicit_type_head()
51 atf_set "descr" "Tests out -a / -f without -t"
53 attach_vnode_non_explicit_type_body()
58 atf_check -s exit:0 -x "truncate -s ${size_in_mb}m xxx"
59 atf_check -s exit:0 -o save:mdconfig.out -x 'mdconfig -af xxx'
60 md=$(cat mdconfig.out)
61 atf_check -s exit:0 -o match:'^md[0-9]+$' -x "echo $md"
62 check_diskinfo "$md" "1073741824" "2097152"
63 # This awk strips the file path.
64 atf_check -s exit:0 -o match:"^$md vnode ${size_in_mb}M$" \
65 -x "mdconfig -lv | awk '\$1 == \"$md\" { print \$1, \$2, \$3 }'"
67 attach_vnode_non_explicit_type_cleanup()
72 atf_test_case attach_vnode_implicit_a_f cleanup
73 attach_vnode_implicit_a_f_head()
75 atf_set "descr" "Tests out implied -a / -f without -t"
77 attach_vnode_implicit_a_f_body()
82 atf_check -s exit:0 -x "truncate -s ${size_in_mb}m xxx"
83 atf_check -s exit:0 -o save:mdconfig.out -x 'mdconfig xxx'
84 md=$(cat mdconfig.out)
85 atf_check -s exit:0 -o match:'^md[0-9]+$' -x "echo $md"
86 check_diskinfo "$md" "1073741824" "2097152"
87 # This awk strips the file path.
88 atf_check -s exit:0 -o match:"^$md vnode ${size_in_mb}M$" \
89 -x "mdconfig -lv | awk '\$1 == \"$md\" { print \$1, \$2, \$3 }'"
91 attach_vnode_implicit_a_f_cleanup()
96 atf_test_case attach_vnode_explicit_type cleanup
97 attach_vnode_explicit_type_head()
99 atf_set "descr" "Tests out implied -a / -f with -t vnode"
101 attach_vnode_explicit_type_body()
104 local size_in_mb=1024
106 atf_check -s exit:0 -x "truncate -s ${size_in_mb}m xxx"
107 atf_check -s exit:0 -o save:mdconfig.out -x 'mdconfig -af xxx -t vnode'
108 md=$(cat mdconfig.out)
109 atf_check -s exit:0 -o match:'^md[0-9]+$' -x "echo $md"
110 check_diskinfo "$md" "1073741824" "2097152"
111 # This awk strips the file path.
112 atf_check -s exit:0 -o match:"^$md vnode ${size_in_mb}M$" \
113 -x "mdconfig -lv | awk '\$1 == \"$md\" { print \$1, \$2, \$3 }'"
115 attach_vnode_explicit_type_cleanup()
117 [ -f mdconfig.out ] && mdconfig -d -u $(sed -e 's/md//' mdconfig.out)
118 rm -f mdconfig.out xxx
121 atf_test_case attach_vnode_smaller_than_file cleanup
122 attach_vnode_smaller_than_file_head()
124 atf_set "descr" "Tests mdconfig -s with size less than the file size"
126 attach_vnode_smaller_than_file_body()
131 atf_check -s exit:0 -x "truncate -s 1024m xxx"
132 atf_check -s exit:0 -o save:mdconfig.out \
133 -x "mdconfig -af xxx -s ${size_in_mb}m"
134 md=$(cat mdconfig.out)
135 atf_check -s exit:0 -o match:'^md[0-9]+$' -x "echo $md"
136 check_diskinfo "$md" "134217728" "262144"
137 # This awk strips the file path.
138 atf_check -s exit:0 -o match:"^$md vnode ${size_in_mb}M$" \
139 -x "mdconfig -lv | awk '\$1 == \"$md\" { print \$1, \$2, \$3 }'"
141 attach_vnode_smaller_than_file_cleanup()
146 atf_test_case attach_vnode_larger_than_file cleanup
147 attach_vnode_larger_than_file_head()
149 atf_set "descr" "Tests mdconfig -s with size greater than the file size"
151 attach_vnode_larger_than_file_body()
156 atf_check -s exit:0 -x "truncate -s 1024m xxx"
157 atf_check -s exit:0 -o save:mdconfig.out \
158 -x "mdconfig -af xxx -s ${size_in_gb}g"
159 md=$(cat mdconfig.out)
160 atf_check -s exit:0 -o match:'^md[0-9]+$' -x "echo $md"
161 check_diskinfo "$md" "137438953472" "268435456"
162 # This awk strips the file path.
163 atf_check -s exit:0 -o match:"^$md vnode ${size_in_gb}G$" \
164 -x "mdconfig -lv | awk '\$1 == \"$md\" { print \$1, \$2, \$3 }'"
166 attach_vnode_larger_than_file_cleanup()
171 atf_test_case attach_vnode_sector_size cleanup
172 attach_vnode_sector_size_head()
174 atf_set "descr" "Tests mdconfig -s with size greater than the file size"
176 attach_vnode_sector_size_body()
179 local size_in_mb=1024
181 atf_check -s exit:0 -x "truncate -s ${size_in_mb}m xxx"
182 atf_check -s exit:0 -o save:mdconfig.out \
183 -x "mdconfig -af xxx -S 2048"
184 md=$(cat mdconfig.out)
185 atf_check -s exit:0 -o match:'^md[0-9]+$' -x "echo $md"
186 check_diskinfo "$md" "1073741824" "524288" "2048"
187 # This awk strips the file path.
188 atf_check -s exit:0 -o match:"^$md vnode ${size_in_mb}M$" \
189 -x "mdconfig -lv | awk '\$1 == \"$md\" { print \$1, \$2, \$3 }'"
191 attach_vnode_sector_size_cleanup()
196 atf_test_case attach_malloc cleanup
199 atf_set "descr" "Tests mdconfig with -t malloc"
204 local size_in_mb=1024
206 atf_check -s exit:0 -o save:mdconfig.out \
207 -x 'mdconfig -a -t malloc -s 1g'
208 md=$(cat mdconfig.out)
209 atf_check -s exit:0 -o match:'^md[0-9]+$' -x "echo $md"
210 check_diskinfo "$md" "1073741824" "2097152"
211 # This awk strips the file path.
212 atf_check -s exit:0 -o match:"^$md malloc ${size_in_mb}M$" \
213 -x "mdconfig -lv | awk '\$1 == \"$md\" { print \$1, \$2, \$3 }'"
215 attach_malloc_cleanup()
220 atf_test_case attach_swap cleanup
223 atf_set "descr" "Tests mdconfig with -t swap"
228 local size_in_mb=1024
230 atf_check -s exit:0 -o save:mdconfig.out \
231 -x 'mdconfig -a -t swap -s 1g'
232 md=$(cat mdconfig.out)
233 atf_check -s exit:0 -o match:'^md[0-9]+$' -x "echo $md"
234 check_diskinfo "$md" "1073741824" "2097152"
235 # This awk strips the file path.
236 atf_check -s exit:0 -o match:"^$md swap ${size_in_mb}M$" \
237 -x "mdconfig -lv | awk '\$1 == \"$md\" { print \$1, \$2, \$3 }'"
239 attach_swap_cleanup()
244 atf_test_case attach_with_specific_unit_number cleanup
245 attach_with_specific_unit_number_head()
247 atf_set "descr" "Tests mdconfig with a unit specified by -u"
249 attach_with_specific_unit_number_body()
254 local md="md${md_unit}"
256 echo "$md" > mdconfig.out
258 atf_check -s exit:0 -o empty \
259 -x "mdconfig -a -t malloc -s ${size_in_mb}m -u $md_unit"
260 check_diskinfo "$md" "10485760" "20480"
261 # This awk strips the file path.
262 atf_check -s exit:0 -o match:"^$md malloc "$size_in_mb"M$" \
263 -x "mdconfig -lv | awk '\$1 == \"$md\" { print \$1, \$2, \$3 }'"
265 attach_with_specific_unit_number_cleanup()
270 atf_init_test_cases()
272 atf_add_test_case attach_vnode_non_explicit_type
273 atf_add_test_case attach_vnode_explicit_type
274 atf_add_test_case attach_vnode_smaller_than_file
275 atf_add_test_case attach_vnode_larger_than_file
276 atf_add_test_case attach_vnode_sector_size
277 atf_add_test_case attach_malloc
278 atf_add_test_case attach_swap
279 atf_add_test_case attach_with_specific_unit_number