1# $NetBSD: t_mknod.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 mknod operation works. 30# 31 32atf_test_case block 33block_head() { 34 atf_set "descr" "Tests that block devices can be created" 35 atf_set "require.user" "root" 36 atf_set "use.fs" "true" 37} 38block_body() { 39 test_mount 40 umask 022 41 42 atf_check -s eq:0 -o empty -e empty mknod fd0a b 2 0 43 eval $(stat -s fd0a) 44 [ ${st_mode} = 060644 ] || atf_fail "Invalid mode" 45 [ ${st_rdev} -eq 512 ] || atf_fail "Invalid device" 46 47 test_unmount 48} 49 50atf_test_case block_kqueue 51block_kqueue_head() { 52 atf_set "descr" "Tests that creating a block device raises the" \ 53 "appropriate kqueue events" 54 atf_set "require.user" "root" 55 atf_set "use.fs" "true" 56} 57block_kqueue_body() { 58 test_mount 59 umask 022 60 61 atf_check -s eq:0 -o empty -e empty mkdir dir 62 echo 'mknod dir/fd0a b 2 0' | kqueue_monitor 1 dir 63 kqueue_check dir NOTE_WRITE 64 65 test_unmount 66} 67 68atf_test_case char 69char_head() { 70 atf_set "descr" "Tests that character devices can be created" 71 atf_set "require.user" "root" 72 atf_set "use.fs" "true" 73} 74char_body() { 75 test_mount 76 umask 022 77 78 atf_check -s eq:0 -o empty -e empty mknod null c 2 2 79 eval $(stat -s null) 80 [ ${st_mode} = 020644 ] || atf_fail "Invalid mode" 81 [ ${st_rdev} -eq 514 ] || atf_fail "Invalid device" 82 83 test_unmount 84} 85 86atf_test_case char_kqueue 87char_kqueue_head() { 88 atf_set "descr" "Tests that creating a character device raises the" \ 89 "appropriate kqueue events" 90 atf_set "require.user" "root" 91 atf_set "use.fs" "true" 92} 93char_kqueue_body() { 94 test_mount 95 umask 022 96 97 atf_check -s eq:0 -o empty -e empty mkdir dir 98 echo 'mknod dir/null c 2 2' | kqueue_monitor 1 dir 99 kqueue_check dir NOTE_WRITE 100 101 test_unmount 102} 103 104atf_test_case pipe 105pipe_head() { 106 atf_set "descr" "Tests that named pipes can be created" 107 atf_set "require.user" "root" 108 atf_set "use.fs" "true" 109} 110pipe_body() { 111 test_mount 112 umask 022 113 114 atf_check -s eq:0 -o empty -e empty mknod pipe p 115 eval $(stat -s pipe) 116 [ ${st_mode} = 010644 ] || atf_fail "Invalid mode" 117 118 test_unmount 119} 120 121atf_test_case pipe_kqueue 122pipe_kqueue_head() { 123 atf_set "descr" "Tests that creating a named pipe raises the" \ 124 "appropriate kqueue events" 125 atf_set "require.user" "root" 126 atf_set "use.fs" "true" 127} 128pipe_kqueue_body() { 129 test_mount 130 umask 022 131 132 atf_check -s eq:0 -o empty -e empty mkdir dir 133 echo 'mknod dir/pipe p' | kqueue_monitor 1 dir 134 kqueue_check dir NOTE_WRITE 135 136 test_unmount 137} 138 139atf_init_test_cases() { 140 . $(atf_get_srcdir)/../h_funcs.subr 141 . $(atf_get_srcdir)/h_funcs.subr 142 143 atf_add_test_case block 144 atf_add_test_case block_kqueue 145 atf_add_test_case char 146 atf_add_test_case char_kqueue 147 atf_add_test_case pipe 148 atf_add_test_case pipe_kqueue 149} 150