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