xref: /freebsd/contrib/netbsd-tests/fs/tmpfs/t_sizes.sh (revision 8ddb146abcdf061be9f2c0db7e391697dafad85c)
1# $NetBSD: t_sizes.sh,v 1.5 2010/11/07 17:51:18 jmmv 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
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 -s eq:0 -o empty -e empty rm a
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	# Begin FreeBSD
58	if true; then
59		pagesize=$(sysctl -n hw.pagesize)
60	else
61	# End FreeBSD
62	pagesize=$(sysctl hw.pagesize | cut -d ' ' -f 3)
63	# Begin FreeBSD
64	fi
65	# End FreeBSD
66	eval $($(atf_get_srcdir)/h_tools statvfs . | sed -e 's|^f_|cf_|')
67	cf_bused=$((${cf_blocks} - ${cf_bfree}))
68
69	atf_check -s eq:0 -o ignore -e ignore \
70	    dd if=/dev/zero of=a bs=1m count=5
71	eval $($(atf_get_srcdir)/h_tools statvfs .)
72	f_bused=$((${f_blocks} - ${f_bfree}))
73	[ ${f_bused} -ne ${cf_bused} ] || atf_fail "bused did not change"
74	[ ${f_bused} -gt $((5 * 1024 * 1024 / ${pagesize})) ] || \
75	    atf_fail "bused too big"
76	of_bused=${f_bused}
77	atf_check -s eq:0 -o empty -e empty rm a
78	eval $($(atf_get_srcdir)/h_tools statvfs .)
79	f_bused=$((${f_blocks} - ${f_bfree}))
80	[ ${f_bused} -lt ${of_bused} ] || \
81	    atf_fail "bused was not correctly restored"
82
83	test_unmount
84}
85
86atf_test_case overflow
87overflow_head() {
88	atf_set "descr" "Checks the status after creating a big file that" \
89	                "overflows the file system limits"
90	atf_set "require.user" "root"
91}
92overflow_body() {
93	test_mount -o -s10M
94
95	atf_check -s eq:0 -o empty -e empty touch a
96	atf_check -s eq:0 -o empty -e empty rm a
97	eval $($(atf_get_srcdir)/h_tools statvfs .)
98	of_bused=$((${f_blocks} - ${f_bfree}))
99	atf_check -s eq:1 -o ignore -e ignore \
100	    dd if=/dev/zero of=a bs=1m count=15
101	atf_check -s eq:0 -o empty -e empty rm a
102	eval $($(atf_get_srcdir)/h_tools statvfs .)
103	f_bused=$((${f_blocks} - ${f_bfree}))
104	[ ${f_bused} -ge ${of_bused} -a ${f_bused} -le $((${of_bused} + 1)) ] \
105	    || atf_fail "Incorrect bused"
106
107	test_unmount
108}
109
110atf_test_case overwrite
111overwrite_head() {
112	atf_set "descr" "Checks that writing to the middle of a file" \
113	                "does not change its size"
114	atf_set "require.user" "root"
115}
116overwrite_body() {
117	test_mount -o -s10M
118
119	atf_check -s eq:0 -o ignore -e ignore \
120	    dd if=/dev/zero of=a bs=1024 count=10
121	sync
122	atf_check -s eq:0 -o ignore -e ignore \
123	    dd if=/dev/zero of=a bs=1024 conv=notrunc seek=1 count=1
124	sync
125	eval $(stat -s a)
126	[ ${st_size} -eq 10240 ] || atf_fail "Incorrect file size"
127
128	test_unmount
129}
130
131atf_init_test_cases() {
132	. $(atf_get_srcdir)/../h_funcs.subr
133	. $(atf_get_srcdir)/h_funcs.subr
134
135	atf_add_test_case small
136	atf_add_test_case big
137	atf_add_test_case overflow
138	atf_add_test_case overwrite
139}
140