t_read_write.sh revision 296373
1# $NetBSD: t_read_write.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 read and write operations work. 30# 31 32atf_test_case basic 33basic_head() { 34 atf_set "descr" "Checks that file removal works" 35 atf_set "require.user" "root" 36} 37basic_body() { 38 test_mount 39 40 echo "Testing write to a small file" 41 echo foo >a || atf_fail "Failed to write to file" 42 [ $(md5 a | cut -d ' ' -f 4) = d3b07384d113edec49eaa6238ad5ff00 ] || \ 43 atf_fail "Invalid file contents" 44 45 echo "Testing appending to a small file" 46 echo bar >>a || atf_fail "Failed to append data to file" 47 [ $(md5 a | cut -d ' ' -f 4) = f47c75614087a8dd938ba4acff252494 ] || \ 48 atf_fail "Invalid file contents" 49 50 echo "Testing write to a big file (bigger than a page)" 51 jot 10000 >b || atf_fail "Failed to create a big file" 52 [ $(md5 b | cut -d ' ' -f 4) = 72d4ff27a28afbc066d5804999d5a504 ] || \ 53 atf_fail "Invalid file contents" 54 55 test_unmount 56} 57 58atf_test_case kqueue 59kqueue_head() { 60 atf_set "descr" "Checks that writing to a file raises the" \ 61 "appropriate kqueue events" 62 atf_set "require.user" "root" 63} 64kqueue_body() { 65 test_mount 66 67 atf_check -s eq:0 -o ignore -e ignore \ 68 dd if=/dev/zero of=c bs=1k count=10 69 echo 'dd if=/dev/zero of=c seek=2 bs=1k count=1 conv=notrunc' \ 70 '>/dev/null 2>&1' | kqueue_monitor 1 c 71 kqueue_check c NOTE_WRITE 72 73 echo foo >d 74 echo 'echo bar >>d' | kqueue_monitor 2 d 75 kqueue_check d NOTE_EXTEND 76 kqueue_check d NOTE_WRITE 77 78 test_unmount 79} 80 81atf_init_test_cases() { 82 . $(atf_get_srcdir)/../h_funcs.subr 83 . $(atf_get_srcdir)/h_funcs.subr 84 85 atf_add_test_case basic 86 atf_add_test_case kqueue 87} 88