1 # $NetBSD: t_sizes.sh,v 1.5 2010/11/07 17:51:18 jmmv Exp $
3 # Copyright (c) 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
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.
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.
29 # Verifies that the file system controls memory usage correctly.
34 atf_set
"descr" "Checks the status after creating a small file"
35 atf_set
"require.user" "root"
40 echo a
>a || atf_fail
"Could not create file"
41 eval $
($
(atf_get_srcdir
)/h_tools statvfs .
)
42 f_bused
=$
((${f_blocks} - ${f_bfree}))
43 [ ${f_bused} -gt 1 ] || atf_fail
"Incorrect bused count"
44 atf_check
-s eq
:0 -o empty
-e empty
rm a
51 atf_set
"descr" "Checks the status after creating a big file"
52 atf_set
"require.user" "root"
57 pagesize
=$
(sysctl hw.pagesize | cut
-d ' ' -f 3)
58 eval $
($
(atf_get_srcdir
)/h_tools statvfs . |
sed -e 's|^f_|cf_|')
59 cf_bused
=$
((${cf_blocks} - ${cf_bfree}))
61 atf_check
-s eq
:0 -o ignore
-e ignore \
62 dd if=/dev
/zero of
=a bs
=1m count
=5
63 eval $
($
(atf_get_srcdir
)/h_tools statvfs .
)
64 f_bused
=$
((${f_blocks} - ${f_bfree}))
65 [ ${f_bused} -ne ${cf_bused} ] || atf_fail
"bused did not change"
66 [ ${f_bused} -gt $
((5 * 1024 * 1024 / ${pagesize})) ] || \
67 atf_fail
"bused too big"
69 atf_check
-s eq
:0 -o empty
-e empty
rm a
70 eval $
($
(atf_get_srcdir
)/h_tools statvfs .
)
71 f_bused
=$
((${f_blocks} - ${f_bfree}))
72 [ ${f_bused} -lt ${of_bused} ] || \
73 atf_fail
"bused was not correctly restored"
78 atf_test_case overflow
80 atf_set
"descr" "Checks the status after creating a big file that" \
81 "overflows the file system limits"
82 atf_set
"require.user" "root"
87 atf_check
-s eq
:0 -o empty
-e empty
touch a
88 atf_check
-s eq
:0 -o empty
-e empty
rm a
89 eval $
($
(atf_get_srcdir
)/h_tools statvfs .
)
90 of_bused
=$
((${f_blocks} - ${f_bfree}))
91 atf_check
-s eq
:1 -o ignore
-e ignore \
92 dd if=/dev
/zero of
=a bs
=1m count
=15
93 atf_check
-s eq
:0 -o empty
-e empty
rm a
94 eval $
($
(atf_get_srcdir
)/h_tools statvfs .
)
95 f_bused
=$
((${f_blocks} - ${f_bfree}))
96 [ ${f_bused} -ge ${of_bused} -a ${f_bused} -le $((${of_bused} + 1)) ] \
97 || atf_fail
"Incorrect bused"
102 atf_test_case overwrite
104 atf_set
"descr" "Checks that writing to the middle of a file" \
105 "does not change its size"
106 atf_set
"require.user" "root"
111 atf_check
-s eq
:0 -o ignore
-e ignore \
112 dd if=/dev
/zero of
=a bs
=1024 count
=10
114 atf_check
-s eq
:0 -o ignore
-e ignore \
115 dd if=/dev
/zero of
=a bs
=1024 conv
=notrunc seek
=1 count
=1
118 [ ${st_size} -eq 10240 ] || atf_fail
"Incorrect file size"
123 atf_init_test_cases
() {
124 . $
(atf_get_srcdir
)/..
/h_funcs.subr
125 . $
(atf_get_srcdir
)/h_funcs.subr
127 atf_add_test_case small
128 atf_add_test_case big
129 atf_add_test_case overflow
130 atf_add_test_case overwrite