1 1.7 rillig # $NetBSD: t_sizes.sh,v 1.7 2024/04/28 07:27:41 rillig Exp $ 2 1.1 jmmv # 3 1.3 jmmv # Copyright (c) 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc. 4 1.1 jmmv # All rights reserved. 5 1.1 jmmv # 6 1.1 jmmv # Redistribution and use in source and binary forms, with or without 7 1.1 jmmv # modification, are permitted provided that the following conditions 8 1.1 jmmv # are met: 9 1.1 jmmv # 1. Redistributions of source code must retain the above copyright 10 1.1 jmmv # notice, this list of conditions and the following disclaimer. 11 1.1 jmmv # 2. Redistributions in binary form must reproduce the above copyright 12 1.1 jmmv # notice, this list of conditions and the following disclaimer in the 13 1.1 jmmv # documentation and/or other materials provided with the distribution. 14 1.1 jmmv # 15 1.1 jmmv # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16 1.1 jmmv # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 1.1 jmmv # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 1.1 jmmv # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 1.1 jmmv # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 1.1 jmmv # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 1.1 jmmv # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 1.1 jmmv # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 1.1 jmmv # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 1.1 jmmv # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 1.1 jmmv # POSSIBILITY OF SUCH DAMAGE. 26 1.1 jmmv # 27 1.1 jmmv 28 1.1 jmmv # 29 1.1 jmmv # Verifies that the file system controls memory usage correctly. 30 1.1 jmmv # 31 1.1 jmmv 32 1.1 jmmv atf_test_case small 33 1.1 jmmv small_head() { 34 1.1 jmmv atf_set "descr" "Checks the status after creating a small file" 35 1.1 jmmv atf_set "require.user" "root" 36 1.1 jmmv } 37 1.1 jmmv small_body() { 38 1.1 jmmv test_mount -o -s10M 39 1.1 jmmv 40 1.1 jmmv echo a >a || atf_fail "Could not create file" 41 1.1 jmmv eval $($(atf_get_srcdir)/h_tools statvfs .) 42 1.1 jmmv f_bused=$((${f_blocks} - ${f_bfree})) 43 1.1 jmmv [ ${f_bused} -gt 1 ] || atf_fail "Incorrect bused count" 44 1.7 rillig atf_check -s exit:0 -o empty -e empty rm a 45 1.1 jmmv 46 1.1 jmmv test_unmount 47 1.1 jmmv } 48 1.1 jmmv 49 1.1 jmmv atf_test_case big 50 1.1 jmmv big_head() { 51 1.1 jmmv atf_set "descr" "Checks the status after creating a big file" 52 1.1 jmmv atf_set "require.user" "root" 53 1.1 jmmv } 54 1.1 jmmv big_body() { 55 1.1 jmmv test_mount -o -s10M 56 1.1 jmmv 57 1.6 maya pagesize=$(sysctl -n hw.pagesize) 58 1.1 jmmv eval $($(atf_get_srcdir)/h_tools statvfs . | sed -e 's|^f_|cf_|') 59 1.1 jmmv cf_bused=$((${cf_blocks} - ${cf_bfree})) 60 1.1 jmmv 61 1.7 rillig atf_check -s exit:0 -o ignore -e ignore \ 62 1.3 jmmv dd if=/dev/zero of=a bs=1m count=5 63 1.1 jmmv eval $($(atf_get_srcdir)/h_tools statvfs .) 64 1.1 jmmv f_bused=$((${f_blocks} - ${f_bfree})) 65 1.1 jmmv [ ${f_bused} -ne ${cf_bused} ] || atf_fail "bused did not change" 66 1.1 jmmv [ ${f_bused} -gt $((5 * 1024 * 1024 / ${pagesize})) ] || \ 67 1.1 jmmv atf_fail "bused too big" 68 1.1 jmmv of_bused=${f_bused} 69 1.7 rillig atf_check -s exit:0 -o empty -e empty rm a 70 1.1 jmmv eval $($(atf_get_srcdir)/h_tools statvfs .) 71 1.1 jmmv f_bused=$((${f_blocks} - ${f_bfree})) 72 1.1 jmmv [ ${f_bused} -lt ${of_bused} ] || \ 73 1.1 jmmv atf_fail "bused was not correctly restored" 74 1.1 jmmv 75 1.1 jmmv test_unmount 76 1.1 jmmv } 77 1.1 jmmv 78 1.1 jmmv atf_test_case overflow 79 1.1 jmmv overflow_head() { 80 1.1 jmmv atf_set "descr" "Checks the status after creating a big file that" \ 81 1.1 jmmv "overflows the file system limits" 82 1.1 jmmv atf_set "require.user" "root" 83 1.1 jmmv } 84 1.1 jmmv overflow_body() { 85 1.1 jmmv test_mount -o -s10M 86 1.1 jmmv 87 1.7 rillig atf_check -s exit:0 -o empty -e empty touch a 88 1.7 rillig atf_check -s exit:0 -o empty -e empty rm a 89 1.1 jmmv eval $($(atf_get_srcdir)/h_tools statvfs .) 90 1.1 jmmv of_bused=$((${f_blocks} - ${f_bfree})) 91 1.7 rillig atf_check -s exit:1 -o ignore -e ignore \ 92 1.3 jmmv dd if=/dev/zero of=a bs=1m count=15 93 1.7 rillig atf_check -s exit:0 -o empty -e empty rm a 94 1.1 jmmv eval $($(atf_get_srcdir)/h_tools statvfs .) 95 1.1 jmmv f_bused=$((${f_blocks} - ${f_bfree})) 96 1.1 jmmv [ ${f_bused} -ge ${of_bused} -a ${f_bused} -le $((${of_bused} + 1)) ] \ 97 1.1 jmmv || atf_fail "Incorrect bused" 98 1.1 jmmv 99 1.1 jmmv test_unmount 100 1.1 jmmv } 101 1.1 jmmv 102 1.1 jmmv atf_test_case overwrite 103 1.1 jmmv overwrite_head() { 104 1.1 jmmv atf_set "descr" "Checks that writing to the middle of a file" \ 105 1.1 jmmv "does not change its size" 106 1.1 jmmv atf_set "require.user" "root" 107 1.1 jmmv } 108 1.1 jmmv overwrite_body() { 109 1.1 jmmv test_mount -o -s10M 110 1.1 jmmv 111 1.7 rillig atf_check -s exit:0 -o ignore -e ignore \ 112 1.3 jmmv dd if=/dev/zero of=a bs=1024 count=10 113 1.1 jmmv sync 114 1.7 rillig atf_check -s exit:0 -o ignore -e ignore \ 115 1.3 jmmv dd if=/dev/zero of=a bs=1024 conv=notrunc seek=1 count=1 116 1.1 jmmv sync 117 1.1 jmmv eval $(stat -s a) 118 1.1 jmmv [ ${st_size} -eq 10240 ] || atf_fail "Incorrect file size" 119 1.1 jmmv 120 1.1 jmmv test_unmount 121 1.1 jmmv } 122 1.1 jmmv 123 1.1 jmmv atf_init_test_cases() { 124 1.1 jmmv . $(atf_get_srcdir)/../h_funcs.subr 125 1.1 jmmv . $(atf_get_srcdir)/h_funcs.subr 126 1.1 jmmv 127 1.1 jmmv atf_add_test_case small 128 1.1 jmmv atf_add_test_case big 129 1.1 jmmv atf_add_test_case overflow 130 1.1 jmmv atf_add_test_case overwrite 131 1.1 jmmv } 132