1272343Sngie# $NetBSD: t_sizes.sh,v 1.5 2010/11/07 17:51:18 jmmv Exp $ 2272343Sngie# 3272343Sngie# Copyright (c) 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc. 4272343Sngie# All rights reserved. 5272343Sngie# 6272343Sngie# Redistribution and use in source and binary forms, with or without 7272343Sngie# modification, are permitted provided that the following conditions 8272343Sngie# are met: 9272343Sngie# 1. Redistributions of source code must retain the above copyright 10272343Sngie# notice, this list of conditions and the following disclaimer. 11272343Sngie# 2. Redistributions in binary form must reproduce the above copyright 12272343Sngie# notice, this list of conditions and the following disclaimer in the 13272343Sngie# documentation and/or other materials provided with the distribution. 14272343Sngie# 15272343Sngie# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16272343Sngie# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17272343Sngie# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18272343Sngie# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19272343Sngie# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20272343Sngie# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21272343Sngie# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22272343Sngie# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23272343Sngie# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24272343Sngie# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25272343Sngie# POSSIBILITY OF SUCH DAMAGE. 26272343Sngie# 27272343Sngie 28272343Sngie# 29272343Sngie# Verifies that the file system controls memory usage correctly. 30272343Sngie# 31272343Sngie 32272343Sngieatf_test_case small 33272343Sngiesmall_head() { 34272343Sngie atf_set "descr" "Checks the status after creating a small file" 35272343Sngie atf_set "require.user" "root" 36272343Sngie} 37272343Sngiesmall_body() { 38272343Sngie test_mount -o -s10M 39272343Sngie 40272343Sngie echo a >a || atf_fail "Could not create file" 41272343Sngie eval $($(atf_get_srcdir)/h_tools statvfs .) 42272343Sngie f_bused=$((${f_blocks} - ${f_bfree})) 43272343Sngie [ ${f_bused} -gt 1 ] || atf_fail "Incorrect bused count" 44272343Sngie atf_check -s eq:0 -o empty -e empty rm a 45272343Sngie 46272343Sngie test_unmount 47272343Sngie} 48272343Sngie 49272343Sngieatf_test_case big 50272343Sngiebig_head() { 51272343Sngie atf_set "descr" "Checks the status after creating a big file" 52272343Sngie atf_set "require.user" "root" 53272343Sngie} 54272343Sngiebig_body() { 55272343Sngie test_mount -o -s10M 56272343Sngie 57272343Sngie pagesize=$(sysctl hw.pagesize | cut -d ' ' -f 3) 58272343Sngie eval $($(atf_get_srcdir)/h_tools statvfs . | sed -e 's|^f_|cf_|') 59272343Sngie cf_bused=$((${cf_blocks} - ${cf_bfree})) 60272343Sngie 61272343Sngie atf_check -s eq:0 -o ignore -e ignore \ 62272343Sngie dd if=/dev/zero of=a bs=1m count=5 63272343Sngie eval $($(atf_get_srcdir)/h_tools statvfs .) 64272343Sngie f_bused=$((${f_blocks} - ${f_bfree})) 65272343Sngie [ ${f_bused} -ne ${cf_bused} ] || atf_fail "bused did not change" 66272343Sngie [ ${f_bused} -gt $((5 * 1024 * 1024 / ${pagesize})) ] || \ 67272343Sngie atf_fail "bused too big" 68272343Sngie of_bused=${f_bused} 69272343Sngie atf_check -s eq:0 -o empty -e empty rm a 70272343Sngie eval $($(atf_get_srcdir)/h_tools statvfs .) 71272343Sngie f_bused=$((${f_blocks} - ${f_bfree})) 72272343Sngie [ ${f_bused} -lt ${of_bused} ] || \ 73272343Sngie atf_fail "bused was not correctly restored" 74272343Sngie 75272343Sngie test_unmount 76272343Sngie} 77272343Sngie 78272343Sngieatf_test_case overflow 79272343Sngieoverflow_head() { 80272343Sngie atf_set "descr" "Checks the status after creating a big file that" \ 81272343Sngie "overflows the file system limits" 82272343Sngie atf_set "require.user" "root" 83272343Sngie} 84272343Sngieoverflow_body() { 85272343Sngie test_mount -o -s10M 86272343Sngie 87272343Sngie atf_check -s eq:0 -o empty -e empty touch a 88272343Sngie atf_check -s eq:0 -o empty -e empty rm a 89272343Sngie eval $($(atf_get_srcdir)/h_tools statvfs .) 90272343Sngie of_bused=$((${f_blocks} - ${f_bfree})) 91272343Sngie atf_check -s eq:1 -o ignore -e ignore \ 92272343Sngie dd if=/dev/zero of=a bs=1m count=15 93272343Sngie atf_check -s eq:0 -o empty -e empty rm a 94272343Sngie eval $($(atf_get_srcdir)/h_tools statvfs .) 95272343Sngie f_bused=$((${f_blocks} - ${f_bfree})) 96272343Sngie [ ${f_bused} -ge ${of_bused} -a ${f_bused} -le $((${of_bused} + 1)) ] \ 97272343Sngie || atf_fail "Incorrect bused" 98272343Sngie 99272343Sngie test_unmount 100272343Sngie} 101272343Sngie 102272343Sngieatf_test_case overwrite 103272343Sngieoverwrite_head() { 104272343Sngie atf_set "descr" "Checks that writing to the middle of a file" \ 105272343Sngie "does not change its size" 106272343Sngie atf_set "require.user" "root" 107272343Sngie} 108272343Sngieoverwrite_body() { 109272343Sngie test_mount -o -s10M 110272343Sngie 111272343Sngie atf_check -s eq:0 -o ignore -e ignore \ 112272343Sngie dd if=/dev/zero of=a bs=1024 count=10 113272343Sngie sync 114272343Sngie atf_check -s eq:0 -o ignore -e ignore \ 115272343Sngie dd if=/dev/zero of=a bs=1024 conv=notrunc seek=1 count=1 116272343Sngie sync 117272343Sngie eval $(stat -s a) 118272343Sngie [ ${st_size} -eq 10240 ] || atf_fail "Incorrect file size" 119272343Sngie 120272343Sngie test_unmount 121272343Sngie} 122272343Sngie 123272343Sngieatf_init_test_cases() { 124272343Sngie . $(atf_get_srcdir)/../h_funcs.subr 125272343Sngie . $(atf_get_srcdir)/h_funcs.subr 126272343Sngie 127272343Sngie atf_add_test_case small 128272343Sngie atf_add_test_case big 129272343Sngie atf_add_test_case overflow 130272343Sngie atf_add_test_case overwrite 131272343Sngie} 132