xref: /freebsd/contrib/netbsd-tests/fs/tmpfs/t_sizes.sh (revision 8c4282b370bd66908b45b6a223226a9fc2b69d57)
157718be8SEnji Cooper# $NetBSD: t_sizes.sh,v 1.5 2010/11/07 17:51:18 jmmv Exp $
257718be8SEnji Cooper#
357718be8SEnji Cooper# Copyright (c) 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc.
457718be8SEnji Cooper# All rights reserved.
557718be8SEnji Cooper#
657718be8SEnji Cooper# Redistribution and use in source and binary forms, with or without
757718be8SEnji Cooper# modification, are permitted provided that the following conditions
857718be8SEnji Cooper# are met:
957718be8SEnji Cooper# 1. Redistributions of source code must retain the above copyright
1057718be8SEnji Cooper#    notice, this list of conditions and the following disclaimer.
1157718be8SEnji Cooper# 2. Redistributions in binary form must reproduce the above copyright
1257718be8SEnji Cooper#    notice, this list of conditions and the following disclaimer in the
1357718be8SEnji Cooper#    documentation and/or other materials provided with the distribution.
1457718be8SEnji Cooper#
1557718be8SEnji Cooper# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1657718be8SEnji Cooper# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1757718be8SEnji Cooper# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1857718be8SEnji Cooper# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
1957718be8SEnji Cooper# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2057718be8SEnji Cooper# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2157718be8SEnji Cooper# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2257718be8SEnji Cooper# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2357718be8SEnji Cooper# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2457718be8SEnji Cooper# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2557718be8SEnji Cooper# POSSIBILITY OF SUCH DAMAGE.
2657718be8SEnji Cooper#
2757718be8SEnji Cooper
2857718be8SEnji Cooper#
2957718be8SEnji Cooper# Verifies that the file system controls memory usage correctly.
3057718be8SEnji Cooper#
3157718be8SEnji Cooper
3257718be8SEnji Cooperatf_test_case small
3357718be8SEnji Coopersmall_head() {
3457718be8SEnji Cooper	atf_set "descr" "Checks the status after creating a small file"
3557718be8SEnji Cooper	atf_set "require.user" "root"
3657718be8SEnji Cooper}
3757718be8SEnji Coopersmall_body() {
3857718be8SEnji Cooper	test_mount -o -s10M
3957718be8SEnji Cooper
4057718be8SEnji Cooper	echo a >a || atf_fail "Could not create file"
4157718be8SEnji Cooper	eval $($(atf_get_srcdir)/h_tools statvfs .)
4257718be8SEnji Cooper	f_bused=$((${f_blocks} - ${f_bfree}))
4357718be8SEnji Cooper	[ ${f_bused} -gt 1 ] || atf_fail "Incorrect bused count"
4457718be8SEnji Cooper	atf_check -s eq:0 -o empty -e empty rm a
4557718be8SEnji Cooper
4657718be8SEnji Cooper	test_unmount
4757718be8SEnji Cooper}
4857718be8SEnji Cooper
4957718be8SEnji Cooperatf_test_case big
5057718be8SEnji Cooperbig_head() {
5157718be8SEnji Cooper	atf_set "descr" "Checks the status after creating a big file"
5257718be8SEnji Cooper	atf_set "require.user" "root"
5357718be8SEnji Cooper}
5457718be8SEnji Cooperbig_body() {
5557718be8SEnji Cooper	test_mount -o -s10M
5657718be8SEnji Cooper
57*548f948aSEnji Cooper	# Begin FreeBSD
58*548f948aSEnji Cooper	if true; then
59*548f948aSEnji Cooper		pagesize=$(sysctl -n hw.pagesize)
60*548f948aSEnji Cooper	else
61*548f948aSEnji Cooper	# End FreeBSD
6257718be8SEnji Cooper	pagesize=$(sysctl hw.pagesize | cut -d ' ' -f 3)
63*548f948aSEnji Cooper	# Begin FreeBSD
64*548f948aSEnji Cooper	fi
65*548f948aSEnji Cooper	# End FreeBSD
6657718be8SEnji Cooper	eval $($(atf_get_srcdir)/h_tools statvfs . | sed -e 's|^f_|cf_|')
6757718be8SEnji Cooper	cf_bused=$((${cf_blocks} - ${cf_bfree}))
6857718be8SEnji Cooper
6957718be8SEnji Cooper	atf_check -s eq:0 -o ignore -e ignore \
7057718be8SEnji Cooper	    dd if=/dev/zero of=a bs=1m count=5
7157718be8SEnji Cooper	eval $($(atf_get_srcdir)/h_tools statvfs .)
7257718be8SEnji Cooper	f_bused=$((${f_blocks} - ${f_bfree}))
7357718be8SEnji Cooper	[ ${f_bused} -ne ${cf_bused} ] || atf_fail "bused did not change"
7457718be8SEnji Cooper	[ ${f_bused} -gt $((5 * 1024 * 1024 / ${pagesize})) ] || \
7557718be8SEnji Cooper	    atf_fail "bused too big"
7657718be8SEnji Cooper	of_bused=${f_bused}
7757718be8SEnji Cooper	atf_check -s eq:0 -o empty -e empty rm a
7857718be8SEnji Cooper	eval $($(atf_get_srcdir)/h_tools statvfs .)
7957718be8SEnji Cooper	f_bused=$((${f_blocks} - ${f_bfree}))
8057718be8SEnji Cooper	[ ${f_bused} -lt ${of_bused} ] || \
8157718be8SEnji Cooper	    atf_fail "bused was not correctly restored"
8257718be8SEnji Cooper
8357718be8SEnji Cooper	test_unmount
8457718be8SEnji Cooper}
8557718be8SEnji Cooper
8657718be8SEnji Cooperatf_test_case overflow
8757718be8SEnji Cooperoverflow_head() {
8857718be8SEnji Cooper	atf_set "descr" "Checks the status after creating a big file that" \
8957718be8SEnji Cooper	                "overflows the file system limits"
9057718be8SEnji Cooper	atf_set "require.user" "root"
9157718be8SEnji Cooper}
9257718be8SEnji Cooperoverflow_body() {
9357718be8SEnji Cooper	test_mount -o -s10M
9457718be8SEnji Cooper
9557718be8SEnji Cooper	atf_check -s eq:0 -o empty -e empty touch a
9657718be8SEnji Cooper	atf_check -s eq:0 -o empty -e empty rm a
9757718be8SEnji Cooper	eval $($(atf_get_srcdir)/h_tools statvfs .)
9857718be8SEnji Cooper	of_bused=$((${f_blocks} - ${f_bfree}))
9957718be8SEnji Cooper	atf_check -s eq:1 -o ignore -e ignore \
10057718be8SEnji Cooper	    dd if=/dev/zero of=a bs=1m count=15
10157718be8SEnji Cooper	atf_check -s eq:0 -o empty -e empty rm a
10257718be8SEnji Cooper	eval $($(atf_get_srcdir)/h_tools statvfs .)
10357718be8SEnji Cooper	f_bused=$((${f_blocks} - ${f_bfree}))
10457718be8SEnji Cooper	[ ${f_bused} -ge ${of_bused} -a ${f_bused} -le $((${of_bused} + 1)) ] \
10557718be8SEnji Cooper	    || atf_fail "Incorrect bused"
10657718be8SEnji Cooper
10757718be8SEnji Cooper	test_unmount
10857718be8SEnji Cooper}
10957718be8SEnji Cooper
11057718be8SEnji Cooperatf_test_case overwrite
11157718be8SEnji Cooperoverwrite_head() {
11257718be8SEnji Cooper	atf_set "descr" "Checks that writing to the middle of a file" \
11357718be8SEnji Cooper	                "does not change its size"
11457718be8SEnji Cooper	atf_set "require.user" "root"
11557718be8SEnji Cooper}
11657718be8SEnji Cooperoverwrite_body() {
11757718be8SEnji Cooper	test_mount -o -s10M
11857718be8SEnji Cooper
11957718be8SEnji Cooper	atf_check -s eq:0 -o ignore -e ignore \
12057718be8SEnji Cooper	    dd if=/dev/zero of=a bs=1024 count=10
12157718be8SEnji Cooper	sync
12257718be8SEnji Cooper	atf_check -s eq:0 -o ignore -e ignore \
12357718be8SEnji Cooper	    dd if=/dev/zero of=a bs=1024 conv=notrunc seek=1 count=1
12457718be8SEnji Cooper	sync
12557718be8SEnji Cooper	eval $(stat -s a)
12657718be8SEnji Cooper	[ ${st_size} -eq 10240 ] || atf_fail "Incorrect file size"
12757718be8SEnji Cooper
12857718be8SEnji Cooper	test_unmount
12957718be8SEnji Cooper}
13057718be8SEnji Cooper
13157718be8SEnji Cooperatf_init_test_cases() {
13257718be8SEnji Cooper	. $(atf_get_srcdir)/../h_funcs.subr
13357718be8SEnji Cooper	. $(atf_get_srcdir)/h_funcs.subr
13457718be8SEnji Cooper
13557718be8SEnji Cooper	atf_add_test_case small
13657718be8SEnji Cooper	atf_add_test_case big
13757718be8SEnji Cooper	atf_add_test_case overflow
13857718be8SEnji Cooper	atf_add_test_case overwrite
13957718be8SEnji Cooper}
140