Home | History | Annotate | Line # | Download | only in tmpfs
t_sizes.sh revision 1.1.4.2
      1 # $NetBSD: t_sizes.sh,v 1.1.4.2 2008/01/09 01:59:22 matt Exp $
      2 #
      3 # Copyright (c) 2005, 2006, 2007 The NetBSD Foundation, Inc.
      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 # 3. All advertising materials mentioning features or use of this software
     15 #    must display the following acknowledgement:
     16 #        This product includes software developed by the NetBSD
     17 #        Foundation, Inc. and its contributors.
     18 # 4. Neither the name of The NetBSD Foundation nor the names of its
     19 #    contributors may be used to endorse or promote products derived
     20 #    from this software without specific prior written permission.
     21 #
     22 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     23 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     24 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     25 # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     26 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     27 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     28 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     29 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     30 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     31 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     32 # POSSIBILITY OF SUCH DAMAGE.
     33 #
     34 
     35 #
     36 # Verifies that the file system controls memory usage correctly.
     37 #
     38 
     39 atf_test_case small
     40 small_head() {
     41 	atf_set "descr" "Checks the status after creating a small file"
     42 	atf_set "require.user" "root"
     43 }
     44 small_body() {
     45 	test_mount -o -s10M
     46 
     47 	echo a >a || atf_fail "Could not create file"
     48 	eval $($(atf_get_srcdir)/h_tools statvfs .)
     49 	f_bused=$((${f_blocks} - ${f_bfree}))
     50 	[ ${f_bused} -gt 1 ] || atf_fail "Incorrect bused count"
     51 	atf_check 'rm a' 0 null null
     52 
     53 	test_unmount
     54 }
     55 
     56 atf_test_case big
     57 big_head() {
     58 	atf_set "descr" "Checks the status after creating a big file"
     59 	atf_set "require.user" "root"
     60 }
     61 big_body() {
     62 	test_mount -o -s10M
     63 
     64 	pagesize=$(sysctl hw.pagesize | cut -d ' ' -f 3)
     65 	eval $($(atf_get_srcdir)/h_tools statvfs . | sed -e 's|^f_|cf_|')
     66 	cf_bused=$((${cf_blocks} - ${cf_bfree}))
     67 
     68 	atf_check 'dd if=/dev/zero of=a bs=1m count=5' 0 ignore ignore
     69 	eval $($(atf_get_srcdir)/h_tools statvfs .)
     70 	f_bused=$((${f_blocks} - ${f_bfree}))
     71 	[ ${f_bused} -ne ${cf_bused} ] || atf_fail "bused did not change"
     72 	[ ${f_bused} -gt $((5 * 1024 * 1024 / ${pagesize})) ] || \
     73 	    atf_fail "bused too big"
     74 	of_bused=${f_bused}
     75 	atf_check 'rm a' 0 null null
     76 	eval $($(atf_get_srcdir)/h_tools statvfs .)
     77 	f_bused=$((${f_blocks} - ${f_bfree}))
     78 	[ ${f_bused} -lt ${of_bused} ] || \
     79 	    atf_fail "bused was not correctly restored"
     80 
     81 	test_unmount
     82 }
     83 
     84 atf_test_case overflow
     85 overflow_head() {
     86 	atf_set "descr" "Checks the status after creating a big file that" \
     87 	                "overflows the file system limits"
     88 	atf_set "require.user" "root"
     89 }
     90 overflow_body() {
     91 	test_mount -o -s10M
     92 
     93 	atf_check 'touch a' 0 null null
     94 	atf_check 'rm a' 0 null null
     95 	eval $($(atf_get_srcdir)/h_tools statvfs .)
     96 	of_bused=$((${f_blocks} - ${f_bfree}))
     97 	atf_check 'dd if=/dev/zero of=a bs=1m count=15' 1 ignore ignore
     98 	atf_check 'rm a' 0 null null
     99 	eval $($(atf_get_srcdir)/h_tools statvfs .)
    100 	f_bused=$((${f_blocks} - ${f_bfree}))
    101 	[ ${f_bused} -ge ${of_bused} -a ${f_bused} -le $((${of_bused} + 1)) ] \
    102 	    || atf_fail "Incorrect bused"
    103 
    104 	test_unmount
    105 }
    106 
    107 atf_test_case overwrite
    108 overwrite_head() {
    109 	atf_set "descr" "Checks that writing to the middle of a file" \
    110 	                "does not change its size"
    111 	atf_set "require.user" "root"
    112 }
    113 overwrite_body() {
    114 	test_mount -o -s10M
    115 
    116 	atf_check 'dd if=/dev/zero of=a bs=1024 count=10' 0 ignore ignore
    117 	sync
    118 	atf_check 'dd if=/dev/zero of=a bs=1024 conv=notrunc seek=1 count=1' \
    119 	     0 ignore ignore
    120 	sync
    121 	eval $(stat -s a)
    122 	[ ${st_size} -eq 10240 ] || atf_fail "Incorrect file size"
    123 
    124 	test_unmount
    125 }
    126 
    127 atf_init_test_cases() {
    128 	. $(atf_get_srcdir)/../h_funcs.subr
    129 	. $(atf_get_srcdir)/h_funcs.subr
    130 
    131 	atf_add_test_case small
    132 	atf_add_test_case big
    133 	atf_add_test_case overflow
    134 	atf_add_test_case overwrite
    135 }
    136