xref: /freebsd/tools/regression/tmpfs/t_read_write (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
1f8c94cecSXin LI#!/bin/sh
2f8c94cecSXin LI#
3f8c94cecSXin LI# $NetBSD: t_read_write,v 1.5 2006/11/09 16:20:06 jmmv 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 read and write operations work.
37f8c94cecSXin LI#
38f8c94cecSXin LI
39f8c94cecSXin LItest_run() {
40f8c94cecSXin LI	test_mount
41f8c94cecSXin LI
42f8c94cecSXin LI	test_name "Write to new file works"
43f8c94cecSXin LI	echo foo >a || die
44f8c94cecSXin LI	test_name "Data written is correct"
45f8c94cecSXin LI	[ $(md5 a | cut -d ' ' -f 4) = d3b07384d113edec49eaa6238ad5ff00 ] || die
46f8c94cecSXin LI
47f8c94cecSXin LI	test_name "Append to existing file works"
48f8c94cecSXin LI	echo bar >>a || die
49f8c94cecSXin LI	test_name "Data written is correct"
50f8c94cecSXin LI	[ $(md5 a | cut -d ' ' -f 4) = f47c75614087a8dd938ba4acff252494 ] || die
51f8c94cecSXin LI
52f8c94cecSXin LI	test_name "Write to long file (bigger than a page) works"
53f8c94cecSXin LI	jot 10000 >b || die
54f8c94cecSXin LI	test_name "Data written is correct"
55f8c94cecSXin LI	[ $(md5 b | cut -d ' ' -f 4) = 72d4ff27a28afbc066d5804999d5a504 ] || die
56f8c94cecSXin LI
57f8c94cecSXin LI	dd if=/dev/zero of=c bs=1k count=10 >/dev/null 2>&1 || die
58f8c94cecSXin LI	echo 'dd if=/dev/zero of=c seek=2 bs=1k count=1 conv=notrunc' \
59f8c94cecSXin LI	    '>/dev/null 2>&1' | kqueue_monitor 1 c || die
60f8c94cecSXin LI	test_name "Writing to a file raises NOTE_WRITE"
61f8c94cecSXin LI	kqueue_check c NOTE_WRITE || die
62f8c94cecSXin LI
63f8c94cecSXin LI	echo foo >d
64f8c94cecSXin LI	echo 'echo bar >>d' | kqueue_monitor 2 d || die
65f8c94cecSXin LI	test_name "Appending to a file raises NOTE_EXTEND"
66f8c94cecSXin LI	kqueue_check d NOTE_EXTEND || die
67f8c94cecSXin LI	test_name "Appending to a file raises NOTE_WRITE"
68f8c94cecSXin LI	kqueue_check d NOTE_WRITE || die
69f8c94cecSXin LI
70f8c94cecSXin LI	test_unmount
71f8c94cecSXin LI}
72f8c94cecSXin LI
73f8c94cecSXin LI. ${SUBRDIR}/h_funcs.subr
74