xref: /freebsd/contrib/netbsd-tests/fs/tmpfs/t_mount.sh (revision 5dae51da3da0cc94d17bd67b308fad304ebec7e0)
1# $NetBSD: t_mount.sh,v 1.6 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 an execution of mount and umount works correctly without
30# causing errors and that the root node gets correct attributes.
31# Also verifies command line parsing from mount_tmpfs.
32#
33
34atf_test_case plain
35plain_head() {
36	atf_set "descr" "Tests a mount and unmount without any options"
37	atf_set "require.user" "root"
38}
39plain_body() {
40	test_mount
41	test_unmount
42}
43
44atf_test_case links
45links_head() {
46	atf_set "descr" "Tests that the mount point has two hard links"
47	atf_set "require.user" "root"
48}
49links_body() {
50	test_mount
51	eval $(stat -s ${Mount_Point})
52	[ ${st_nlink} = 2 ] || \
53	    atf_fail "Root directory does not have two hard links"
54	test_unmount
55}
56
57atf_test_case options
58options_head() {
59	atf_set "descr" "Tests the read-only mount option"
60	atf_set "require.user" "root"
61}
62options_body() {
63	test_mount -o ro
64	mount | grep ${Mount_Point} | grep -q read-only || \
65	    atf_fail "read-only option (ro) does not work"
66	test_unmount
67}
68
69atf_test_case attrs
70attrs_head() {
71	atf_set "descr" "Tests that root directory attributes are set" \
72	                "correctly"
73	atf_set "require.user" "root"
74}
75attrs_body() {
76	test_mount -o -u1000 -o -g100 -o -m755
77	eval $(stat -s ${Mount_Point})
78	[ ${st_uid} = 1000 ] || atf_fail "uid is incorrect"
79	[ ${st_gid} = 100 ] || atf_fail "gid is incorrect"
80	[ ${st_mode} = 040755 ] || atf_fail "mode is incorrect"
81	test_unmount
82}
83
84atf_test_case negative
85negative_head() {
86	atf_set "descr" "Tests that negative values passed to to -s are" \
87	                "handled correctly"
88	atf_set "require.user" "root"
89}
90negative_body() {
91	mkdir tmp
92	test_mount -o -s-10
93	test_unmount
94}
95
96# Begin FreeBSD
97if true; then
98atf_test_case large cleanup
99large_cleanup() {
100	umount -f tmp 2>/dev/null
101}
102else
103# End FreeBSD
104atf_test_case large
105# Begin FreeBSD
106fi
107# End FreeBSD
108large_head() {
109	atf_set "descr" "Tests that extremely long values passed to -s" \
110	                "are handled correctly"
111	atf_set "require.user" "root"
112}
113large_body() {
114	test_mount -o -s9223372036854775807
115	test_unmount
116
117	# Begin FreeBSD
118	atf_expect_fail "-o -s<large-size> succeeds unexpectedly on FreeBSD - bug 212862"
119	# End FreeBSD
120
121	mkdir tmp
122	atf_check -s eq:1 -o empty -e ignore \
123	    mount -t tmpfs -o -s9223372036854775808 tmpfs tmp
124	atf_check -s eq:1 -o empty -e ignore \
125	    mount -t tmpfs -o -s9223372036854775808g tmpfs tmp
126	rmdir tmp
127}
128
129atf_test_case mntpt
130mntpt_head() {
131	atf_set "descr" "Tests that the error messages printed when the" \
132	                "mount point is invalid do not show the source" \
133	                "unused parameter"
134}
135mntpt_body() {
136	mount_tmpfs unused $(pwd)/mnt >out 2>&1
137	atf_check -s eq:1 -o empty -e empty grep unused out
138	atf_check -s eq:0 -o ignore -e empty grep "$(pwd)/mnt" out
139
140	mount_tmpfs unused mnt >out 2>&1
141	atf_check -s eq:1 -o empty -e empty grep unused out
142	atf_check -s eq:0 -o ignore -e empty grep mnt out
143}
144
145atf_init_test_cases() {
146	. $(atf_get_srcdir)/../h_funcs.subr
147	. $(atf_get_srcdir)/h_funcs.subr
148
149	atf_add_test_case plain
150	atf_add_test_case options
151	atf_add_test_case attrs
152	atf_add_test_case negative
153	atf_add_test_case large
154	atf_add_test_case mntpt
155}
156