1272343Sngie# $NetBSD: t_mknod.sh,v 1.5 2010/11/07 17:51:18 jmmv Exp $
2272343Sngie#
3272343Sngie# Copyright (c) 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc.
4272343Sngie# All rights reserved.
5272343Sngie#
6272343Sngie# Redistribution and use in source and binary forms, with or without
7272343Sngie# modification, are permitted provided that the following conditions
8272343Sngie# are met:
9272343Sngie# 1. Redistributions of source code must retain the above copyright
10272343Sngie#    notice, this list of conditions and the following disclaimer.
11272343Sngie# 2. Redistributions in binary form must reproduce the above copyright
12272343Sngie#    notice, this list of conditions and the following disclaimer in the
13272343Sngie#    documentation and/or other materials provided with the distribution.
14272343Sngie#
15272343Sngie# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16272343Sngie# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17272343Sngie# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18272343Sngie# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19272343Sngie# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20272343Sngie# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21272343Sngie# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22272343Sngie# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23272343Sngie# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24272343Sngie# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25272343Sngie# POSSIBILITY OF SUCH DAMAGE.
26272343Sngie#
27272343Sngie
28272343Sngie#
29272343Sngie# Verifies that the mknod operation works.
30272343Sngie#
31272343Sngie
32272343Sngieatf_test_case block
33272343Sngieblock_head() {
34272343Sngie	atf_set "descr" "Tests that block devices can be created"
35272343Sngie	atf_set "require.user" "root"
36272343Sngie}
37272343Sngieblock_body() {
38272343Sngie	test_mount
39272343Sngie	umask 022
40272343Sngie
41272343Sngie	atf_check -s eq:0 -o empty -e empty mknod fd0a b 2 0
42272343Sngie	eval $(stat -s fd0a)
43272343Sngie	[ ${st_mode} = 060644 ] || atf_fail "Invalid mode"
44272343Sngie	[ ${st_rdev} -eq 512 ] || atf_fail "Invalid device"
45272343Sngie
46272343Sngie	test_unmount
47272343Sngie}
48272343Sngie
49272343Sngieatf_test_case block_kqueue
50272343Sngieblock_kqueue_head() {
51272343Sngie	atf_set "descr" "Tests that creating a block device raises the" \
52272343Sngie	                "appropriate kqueue events"
53272343Sngie	atf_set "require.user" "root"
54272343Sngie}
55272343Sngieblock_kqueue_body() {
56272343Sngie	test_mount
57272343Sngie	umask 022
58272343Sngie
59272343Sngie	atf_check -s eq:0 -o empty -e empty mkdir dir
60272343Sngie	echo 'mknod dir/fd0a b 2 0' | kqueue_monitor 1 dir
61272343Sngie	kqueue_check dir NOTE_WRITE
62272343Sngie
63272343Sngie	test_unmount
64272343Sngie}
65272343Sngie
66272343Sngieatf_test_case char
67272343Sngiechar_head() {
68272343Sngie	atf_set "descr" "Tests that character devices can be created"
69272343Sngie	atf_set "require.user" "root"
70272343Sngie}
71272343Sngiechar_body() {
72272343Sngie	test_mount
73272343Sngie	umask 022
74272343Sngie
75272343Sngie	atf_check -s eq:0 -o empty -e empty mknod null c 2 2
76272343Sngie	eval $(stat -s null)
77272343Sngie	[ ${st_mode} = 020644 ] || atf_fail "Invalid mode"
78272343Sngie	[ ${st_rdev} -eq 514 ] || atf_fail "Invalid device"
79272343Sngie
80272343Sngie	test_unmount
81272343Sngie}
82272343Sngie
83272343Sngieatf_test_case char_kqueue
84272343Sngiechar_kqueue_head() {
85272343Sngie	atf_set "descr" "Tests that creating a character device raises the" \
86272343Sngie	                "appropriate kqueue events"
87272343Sngie	atf_set "require.user" "root"
88272343Sngie}
89272343Sngiechar_kqueue_body() {
90272343Sngie	test_mount
91272343Sngie	umask 022
92272343Sngie
93272343Sngie	atf_check -s eq:0 -o empty -e empty mkdir dir
94272343Sngie	echo 'mknod dir/null c 2 2' | kqueue_monitor 1 dir
95272343Sngie	kqueue_check dir NOTE_WRITE
96272343Sngie
97272343Sngie	test_unmount
98272343Sngie}
99272343Sngie
100272343Sngieatf_test_case pipe
101272343Sngiepipe_head() {
102272343Sngie	atf_set "descr" "Tests that named pipes can be created"
103272343Sngie	atf_set "require.user" "root"
104272343Sngie}
105272343Sngiepipe_body() {
106272343Sngie	test_mount
107272343Sngie	umask 022
108272343Sngie
109272343Sngie	atf_check -s eq:0 -o empty -e empty mknod pipe p
110272343Sngie	eval $(stat -s pipe)
111272343Sngie	[ ${st_mode} = 010644 ] || atf_fail "Invalid mode"
112272343Sngie
113272343Sngie	test_unmount
114272343Sngie}
115272343Sngie
116272343Sngieatf_test_case pipe_kqueue
117272343Sngiepipe_kqueue_head() {
118272343Sngie	atf_set "descr" "Tests that creating a named pipe raises the" \
119272343Sngie	                "appropriate kqueue events"
120272343Sngie	atf_set "require.user" "root"
121272343Sngie}
122272343Sngiepipe_kqueue_body() {
123272343Sngie	test_mount
124272343Sngie	umask 022
125272343Sngie
126272343Sngie	atf_check -s eq:0 -o empty -e empty mkdir dir
127272343Sngie	echo 'mknod dir/pipe p' | kqueue_monitor 1 dir
128272343Sngie	kqueue_check dir NOTE_WRITE
129272343Sngie
130272343Sngie	test_unmount
131272343Sngie}
132272343Sngie
133272343Sngieatf_init_test_cases() {
134272343Sngie	. $(atf_get_srcdir)/../h_funcs.subr
135272343Sngie	. $(atf_get_srcdir)/h_funcs.subr
136272343Sngie
137272343Sngie	atf_add_test_case block
138272343Sngie	atf_add_test_case block_kqueue
139272343Sngie	atf_add_test_case char
140272343Sngie	atf_add_test_case char_kqueue
141272343Sngie	atf_add_test_case pipe
142272343Sngie	atf_add_test_case pipe_kqueue
143272343Sngie}
144