xref: /freebsd/contrib/netbsd-tests/fs/tmpfs/t_mknod.sh (revision cdebaff820b2a4915a16cedfd511823d78aab171)
1# $NetBSD: t_mknod.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 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}
37block_body() {
38	test_mount
39	umask 022
40
41	atf_check -s eq: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
49atf_test_case block_kqueue
50block_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}
55block_kqueue_body() {
56	test_mount
57	umask 022
58
59	atf_check -s eq: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
66atf_test_case char
67char_head() {
68	atf_set "descr" "Tests that character devices can be created"
69	atf_set "require.user" "root"
70}
71char_body() {
72	test_mount
73	umask 022
74
75	atf_check -s eq: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
83atf_test_case char_kqueue
84char_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}
89char_kqueue_body() {
90	test_mount
91	umask 022
92
93	atf_check -s eq: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
100atf_test_case pipe
101pipe_head() {
102	atf_set "descr" "Tests that named pipes can be created"
103	atf_set "require.user" "root"
104}
105pipe_body() {
106	test_mount
107	umask 022
108
109	# Begin FreeBSD
110	if true; then
111	atf_check -s eq:0 -o empty -e empty mkfifo pipe
112	else
113	# End FreeBSD
114	atf_check -s eq:0 -o empty -e empty mknod pipe p
115	# Begin FreeBSD
116	fi
117	# End FreeBSD
118	eval $(stat -s pipe)
119	[ ${st_mode} = 010644 ] || atf_fail "Invalid mode"
120
121	test_unmount
122}
123
124atf_test_case pipe_kqueue
125pipe_kqueue_head() {
126	atf_set "descr" "Tests that creating a named pipe raises the" \
127	                "appropriate kqueue events"
128	atf_set "require.user" "root"
129}
130pipe_kqueue_body() {
131	test_mount
132	umask 022
133
134	atf_check -s eq:0 -o empty -e empty mkdir dir
135	# Begin FreeBSD
136	if true; then
137	echo 'mkfifo dir/pipe' | kqueue_monitor 1 dir
138	else
139	# End FreeBSD
140	echo 'mknod dir/pipe p' | kqueue_monitor 1 dir
141	# Begin FreeBSD
142	fi
143	# End FreeBSD
144	kqueue_check dir NOTE_WRITE
145
146	test_unmount
147}
148
149atf_init_test_cases() {
150	. $(atf_get_srcdir)/../h_funcs.subr
151	. $(atf_get_srcdir)/h_funcs.subr
152
153	atf_add_test_case block
154	atf_add_test_case block_kqueue
155	atf_add_test_case char
156	atf_add_test_case char_kqueue
157	atf_add_test_case pipe
158	atf_add_test_case pipe_kqueue
159}
160