1# $NetBSD: t_sizes.sh,v 1.2 2008/04/30 13:11:00 martin 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# 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# 29# Verifies that the file system controls memory usage correctly. 30# 31 32atf_test_case small 33small_head() { 34 atf_set "descr" "Checks the status after creating a small file" 35 atf_set "require.user" "root" 36} 37small_body() { 38 test_mount -o -s10M 39 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 'rm a' 0 null null 45 46 test_unmount 47} 48 49atf_test_case big 50big_head() { 51 atf_set "descr" "Checks the status after creating a big file" 52 atf_set "require.user" "root" 53} 54big_body() { 55 test_mount -o -s10M 56 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})) 60 61 atf_check 'dd if=/dev/zero of=a bs=1m count=5' 0 ignore ignore 62 eval $($(atf_get_srcdir)/h_tools statvfs .) 63 f_bused=$((${f_blocks} - ${f_bfree})) 64 [ ${f_bused} -ne ${cf_bused} ] || atf_fail "bused did not change" 65 [ ${f_bused} -gt $((5 * 1024 * 1024 / ${pagesize})) ] || \ 66 atf_fail "bused too big" 67 of_bused=${f_bused} 68 atf_check 'rm a' 0 null null 69 eval $($(atf_get_srcdir)/h_tools statvfs .) 70 f_bused=$((${f_blocks} - ${f_bfree})) 71 [ ${f_bused} -lt ${of_bused} ] || \ 72 atf_fail "bused was not correctly restored" 73 74 test_unmount 75} 76 77atf_test_case overflow 78overflow_head() { 79 atf_set "descr" "Checks the status after creating a big file that" \ 80 "overflows the file system limits" 81 atf_set "require.user" "root" 82} 83overflow_body() { 84 test_mount -o -s10M 85 86 atf_check 'touch a' 0 null null 87 atf_check 'rm a' 0 null null 88 eval $($(atf_get_srcdir)/h_tools statvfs .) 89 of_bused=$((${f_blocks} - ${f_bfree})) 90 atf_check 'dd if=/dev/zero of=a bs=1m count=15' 1 ignore ignore 91 atf_check 'rm a' 0 null null 92 eval $($(atf_get_srcdir)/h_tools statvfs .) 93 f_bused=$((${f_blocks} - ${f_bfree})) 94 [ ${f_bused} -ge ${of_bused} -a ${f_bused} -le $((${of_bused} + 1)) ] \ 95 || atf_fail "Incorrect bused" 96 97 test_unmount 98} 99 100atf_test_case overwrite 101overwrite_head() { 102 atf_set "descr" "Checks that writing to the middle of a file" \ 103 "does not change its size" 104 atf_set "require.user" "root" 105} 106overwrite_body() { 107 test_mount -o -s10M 108 109 atf_check 'dd if=/dev/zero of=a bs=1024 count=10' 0 ignore ignore 110 sync 111 atf_check 'dd if=/dev/zero of=a bs=1024 conv=notrunc seek=1 count=1' \ 112 0 ignore ignore 113 sync 114 eval $(stat -s a) 115 [ ${st_size} -eq 10240 ] || atf_fail "Incorrect file size" 116 117 test_unmount 118} 119 120atf_init_test_cases() { 121 . $(atf_get_srcdir)/../h_funcs.subr 122 . $(atf_get_srcdir)/h_funcs.subr 123 124 atf_add_test_case small 125 atf_add_test_case big 126 atf_add_test_case overflow 127 atf_add_test_case overwrite 128} 129