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