1 # $NetBSD: t_sizes.sh,v 1.7 2024/04/28 07:27:41 rillig Exp $ 2 # 3 # Copyright (c) 2005, 2006, 2007, 2008 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 32 atf_test_case small 33 small_head() { 34 atf_set "descr" "Checks the status after creating a small file" 35 atf_set "require.user" "root" 36 } 37 small_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 -s exit:0 -o empty -e empty rm a 45 46 test_unmount 47 } 48 49 atf_test_case big 50 big_head() { 51 atf_set "descr" "Checks the status after creating a big file" 52 atf_set "require.user" "root" 53 } 54 big_body() { 55 test_mount -o -s10M 56 57 pagesize=$(sysctl -n hw.pagesize) 58 eval $($(atf_get_srcdir)/h_tools statvfs . | sed -e 's|^f_|cf_|') 59 cf_bused=$((${cf_blocks} - ${cf_bfree})) 60 61 atf_check -s exit: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" 68 of_bused=${f_bused} 69 atf_check -s exit: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" 74 75 test_unmount 76 } 77 78 atf_test_case overflow 79 overflow_head() { 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" 83 } 84 overflow_body() { 85 test_mount -o -s10M 86 87 atf_check -s exit:0 -o empty -e empty touch a 88 atf_check -s exit: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 exit:1 -o ignore -e ignore \ 92 dd if=/dev/zero of=a bs=1m count=15 93 atf_check -s exit: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" 98 99 test_unmount 100 } 101 102 atf_test_case overwrite 103 overwrite_head() { 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" 107 } 108 overwrite_body() { 109 test_mount -o -s10M 110 111 atf_check -s exit:0 -o ignore -e ignore \ 112 dd if=/dev/zero of=a bs=1024 count=10 113 sync 114 atf_check -s exit:0 -o ignore -e ignore \ 115 dd if=/dev/zero of=a bs=1024 conv=notrunc seek=1 count=1 116 sync 117 eval $(stat -s a) 118 [ ${st_size} -eq 10240 ] || atf_fail "Incorrect file size" 119 120 test_unmount 121 } 122 123 atf_init_test_cases() { 124 . $(atf_get_srcdir)/../h_funcs.subr 125 . $(atf_get_srcdir)/h_funcs.subr 126 127 atf_add_test_case small 128 atf_add_test_case big 129 atf_add_test_case overflow 130 atf_add_test_case overwrite 131 } 132