xref: /freebsd/tools/regression/tmpfs/t_sizes (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
1f8c94cecSXin LI#!/bin/sh
2f8c94cecSXin LI#
3f8c94cecSXin LI# $NetBSD: t_sizes,v 1.6 2007/03/11 10:09:17 pooka Exp $
4f8c94cecSXin LI#
5f8c94cecSXin LI# Copyright (c) 2005, 2006 The NetBSD Foundation, Inc.
6f8c94cecSXin LI# All rights reserved.
7f8c94cecSXin LI#
8f8c94cecSXin LI# This code is derived from software contributed to The NetBSD Foundation
9f8c94cecSXin LI# by Julio M. Merino Vidal, developed as part of Google's Summer of Code
10f8c94cecSXin LI# 2005 program.
11f8c94cecSXin LI#
12f8c94cecSXin LI# Redistribution and use in source and binary forms, with or without
13f8c94cecSXin LI# modification, are permitted provided that the following conditions
14f8c94cecSXin LI# are met:
15f8c94cecSXin LI# 1. Redistributions of source code must retain the above copyright
16f8c94cecSXin LI#    notice, this list of conditions and the following disclaimer.
17f8c94cecSXin LI# 2. Redistributions in binary form must reproduce the above copyright
18f8c94cecSXin LI#    notice, this list of conditions and the following disclaimer in the
19f8c94cecSXin LI#    documentation and/or other materials provided with the distribution.
20f8c94cecSXin LI#
21f8c94cecSXin LI# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22f8c94cecSXin LI# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23f8c94cecSXin LI# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24f8c94cecSXin LI# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25f8c94cecSXin LI# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26f8c94cecSXin LI# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27f8c94cecSXin LI# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28f8c94cecSXin LI# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29f8c94cecSXin LI# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30f8c94cecSXin LI# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31f8c94cecSXin LI# POSSIBILITY OF SUCH DAMAGE.
32f8c94cecSXin LI#
33f8c94cecSXin LI#
34f8c94cecSXin LI
35f8c94cecSXin LI#
36f8c94cecSXin LI# Verifies that the file system controls memory usage correctly.
37f8c94cecSXin LI#
38f8c94cecSXin LI
39f8c94cecSXin LItest_run() {
40f8c94cecSXin LI	test_mount -o  size=10485760
41f8c94cecSXin LI
42f8c94cecSXin LI	pagesize=$(sysctl hw.pagesize | cut -d ' ' -f 2)
43f8c94cecSXin LI
44f8c94cecSXin LI	test_name "Get status of clean filesystem"
45f8c94cecSXin LI	eval $(${Src_Dir}/h_tools statvfs . | sed -e 's|^f_|cf_|')
46f8c94cecSXin LI	cf_bused=$((${cf_blocks} - ${cf_bfree}))
47f8c94cecSXin LI
48f8c94cecSXin LI	test_name "Creation of small file"
49f8c94cecSXin LI	echo a >a || die
50f8c94cecSXin LI	test_name "statvfs(2) reports correct block accounting"
51f8c94cecSXin LI	eval $(${Src_Dir}/h_tools statvfs .)
52f8c94cecSXin LI	f_bused=$((${f_blocks} - ${f_bfree}))
53f8c94cecSXin LI	[ ${f_bused} -gt 1 ] || die
54f8c94cecSXin LI	rm a || die
55f8c94cecSXin LI
56f8c94cecSXin LI	test_name "Creation of big file"
57f8c94cecSXin LI	dd if=/dev/zero of=a bs=1m count=5 >/dev/null 2>&1 || die
58f8c94cecSXin LI	test_name "statvfs(2) reports correct block accounting"
59f8c94cecSXin LI	eval $(${Src_Dir}/h_tools statvfs .)
60f8c94cecSXin LI	f_bused=$((${f_blocks} - ${f_bfree}))
61f8c94cecSXin LI	[ ${f_bused} -ne ${cf_bused} ] || die
62f8c94cecSXin LI	[ ${f_bused} -gt $((5 * 1024 * 1024 / ${pagesize})) ] || die
63f8c94cecSXin LI	of_bused=${f_bused}
64f8c94cecSXin LI	rm a || die
65f8c94cecSXin LI	eval $(${Src_Dir}/h_tools statvfs .)
66f8c94cecSXin LI	f_bused=$((${f_blocks} - ${f_bfree}))
67f8c94cecSXin LI	[ ${f_bused} -lt ${of_bused} ] || die
68f8c94cecSXin LI
69f8c94cecSXin LI	test_name "Creation of big file that overflows the filesystem"
70f8c94cecSXin LI	of_bused=${f_bused}
71f8c94cecSXin LI	dd if=/dev/zero of=a bs=1m count=15 >/dev/null 2>&1 && die
72f8c94cecSXin LI	rm a || die
73f8c94cecSXin LI	test_name "statvfs(2) reports correct block accounting"
74f8c94cecSXin LI	eval $(${Src_Dir}/h_tools statvfs .)
75f8c94cecSXin LI	f_bused=$((${f_blocks} - ${f_bfree}))
76f8c94cecSXin LI	[ ${f_bused} -ge ${of_bused} -a ${f_bused} -le $((${of_bused} + 1)) ] \
77f8c94cecSXin LI	    || die
78f8c94cecSXin LI
79f8c94cecSXin LI	test_name "Write to middle of a file does not change size"
80f8c94cecSXin LI	dd if=/dev/zero of=a bs=1024 count=10 >/dev/null 2>&1 || die
81f8c94cecSXin LI	sync
82f8c94cecSXin LI	dd if=/dev/zero of=a bs=1024 conv=notrunc seek=1 count=1	\
83f8c94cecSXin LI	     >/dev/null 2>&1 || die
84f8c94cecSXin LI	sync
85f8c94cecSXin LI	eval $(stat -s a)
86f8c94cecSXin LI	[ ${st_size} -eq 10240 ] || die
87f8c94cecSXin LI
88f8c94cecSXin LI	test_unmount
89f8c94cecSXin LI}
90f8c94cecSXin LI
91f8c94cecSXin LI. ${SUBRDIR}/h_funcs.subr
92