xref: /netbsd-src/tests/fs/tmpfs/t_sizes.sh (revision 179b12252ecaf3553d9c2b7458ce62b6a2203d0c)
1# $NetBSD: t_sizes.sh,v 1.4 2010/06/04 08:39:40 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	atf_set "use.fs" "true"
37}
38small_body() {
39	test_mount -o -s10M
40
41	echo a >a || atf_fail "Could not create file"
42	eval $($(atf_get_srcdir)/h_tools statvfs .)
43	f_bused=$((${f_blocks} - ${f_bfree}))
44	[ ${f_bused} -gt 1 ] || atf_fail "Incorrect bused count"
45	atf_check -s eq:0 -o empty -e empty rm a
46
47	test_unmount
48}
49
50atf_test_case big
51big_head() {
52	atf_set "descr" "Checks the status after creating a big file"
53	atf_set "require.user" "root"
54	atf_set "use.fs" "true"
55}
56big_body() {
57	test_mount -o -s10M
58
59	pagesize=$(sysctl hw.pagesize | cut -d ' ' -f 3)
60	eval $($(atf_get_srcdir)/h_tools statvfs . | sed -e 's|^f_|cf_|')
61	cf_bused=$((${cf_blocks} - ${cf_bfree}))
62
63	atf_check -s eq:0 -o ignore -e ignore \
64	    dd if=/dev/zero of=a bs=1m count=5
65	eval $($(atf_get_srcdir)/h_tools statvfs .)
66	f_bused=$((${f_blocks} - ${f_bfree}))
67	[ ${f_bused} -ne ${cf_bused} ] || atf_fail "bused did not change"
68	[ ${f_bused} -gt $((5 * 1024 * 1024 / ${pagesize})) ] || \
69	    atf_fail "bused too big"
70	of_bused=${f_bused}
71	atf_check -s eq:0 -o empty -e empty rm a
72	eval $($(atf_get_srcdir)/h_tools statvfs .)
73	f_bused=$((${f_blocks} - ${f_bfree}))
74	[ ${f_bused} -lt ${of_bused} ] || \
75	    atf_fail "bused was not correctly restored"
76
77	test_unmount
78}
79
80atf_test_case overflow
81overflow_head() {
82	atf_set "descr" "Checks the status after creating a big file that" \
83	                "overflows the file system limits"
84	atf_set "require.user" "root"
85	atf_set "use.fs" "true"
86}
87overflow_body() {
88	test_mount -o -s10M
89
90	atf_check -s eq:0 -o empty -e empty touch a
91	atf_check -s eq:0 -o empty -e empty rm a
92	eval $($(atf_get_srcdir)/h_tools statvfs .)
93	of_bused=$((${f_blocks} - ${f_bfree}))
94	atf_check -s eq:1 -o ignore -e ignore \
95	    dd if=/dev/zero of=a bs=1m count=15
96	atf_check -s eq:0 -o empty -e empty rm a
97	eval $($(atf_get_srcdir)/h_tools statvfs .)
98	f_bused=$((${f_blocks} - ${f_bfree}))
99	[ ${f_bused} -ge ${of_bused} -a ${f_bused} -le $((${of_bused} + 1)) ] \
100	    || atf_fail "Incorrect bused"
101
102	test_unmount
103}
104
105atf_test_case overwrite
106overwrite_head() {
107	atf_set "descr" "Checks that writing to the middle of a file" \
108	                "does not change its size"
109	atf_set "require.user" "root"
110	atf_set "use.fs" "true"
111}
112overwrite_body() {
113	test_mount -o -s10M
114
115	atf_check -s eq:0 -o ignore -e ignore \
116	    dd if=/dev/zero of=a bs=1024 count=10
117	sync
118	atf_check -s eq:0 -o ignore -e ignore \
119	    dd if=/dev/zero of=a bs=1024 conv=notrunc seek=1 count=1
120	sync
121	eval $(stat -s a)
122	[ ${st_size} -eq 10240 ] || atf_fail "Incorrect file size"
123
124	test_unmount
125}
126
127atf_init_test_cases() {
128	. $(atf_get_srcdir)/../h_funcs.subr
129	. $(atf_get_srcdir)/h_funcs.subr
130
131	atf_add_test_case small
132	atf_add_test_case big
133	atf_add_test_case overflow
134	atf_add_test_case overwrite
135}
136