xref: /netbsd-src/tests/fs/tmpfs/t_mount.sh (revision b1c86f5f087524e68db12794ee9c3e3da1ab17a0)
1# $NetBSD: t_mount.sh,v 1.5 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 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	atf_set "use.fs" "true"
39}
40plain_body() {
41	test_mount
42	test_unmount
43}
44
45atf_test_case links
46links_head() {
47	atf_set "descr" "Tests that the mount point has two hard links"
48	atf_set "require.user" "root"
49	atf_set "use.fs" "true"
50}
51links_body() {
52	test_mount
53	eval $(stat -s ${Mount_Point})
54	[ ${st_nlink} = 2 ] || \
55	    atf_fail "Root directory does not have two hard links"
56	test_unmount
57}
58
59atf_test_case options
60options_head() {
61	atf_set "descr" "Tests the read-only mount option"
62	atf_set "require.user" "root"
63	atf_set "use.fs" "true"
64}
65options_body() {
66	test_mount -o ro
67	mount | grep ${Mount_Point} | grep -q read-only || \
68	    atf_fail "read-only option (ro) does not work"
69	test_unmount
70}
71
72atf_test_case attrs
73attrs_head() {
74	atf_set "descr" "Tests that root directory attributes are set" \
75	                "correctly"
76	atf_set "require.user" "root"
77	atf_set "use.fs" "true"
78}
79attrs_body() {
80	test_mount -o -u1000 -o -g100 -o -m755
81	eval $(stat -s ${Mount_Point})
82	[ ${st_uid} = 1000 ] || atf_fail "uid is incorrect"
83	[ ${st_gid} = 100 ] || atf_fail "gid is incorrect"
84	[ ${st_mode} = 040755 ] || atf_fail "mode is incorrect"
85	test_unmount
86}
87
88atf_test_case negative
89negative_head() {
90	atf_set "descr" "Tests that negative values passed to to -s are" \
91	                "handled correctly"
92	atf_set "require.user" "root"
93	atf_set "use.fs" "true"
94}
95negative_body() {
96	mkdir tmp
97	test_mount -o -s-10
98	test_unmount
99}
100
101atf_test_case large
102large_head() {
103	atf_set "descr" "Tests that extremely long values passed to -s" \
104	                "are handled correctly"
105	atf_set "require.user" "root"
106	atf_set "use.fs" "true"
107}
108large_body() {
109	test_mount -o -s9223372036854775807
110	test_unmount
111
112	mkdir tmp
113	atf_check -s eq:1 -o empty -e ignore \
114	    mount -t tmpfs -o -s9223372036854775808 tmpfs tmp
115	atf_check -s eq:1 -o empty -e ignore \
116	    mount -t tmpfs -o -s9223372036854775808g tmpfs tmp
117	rmdir tmp
118}
119
120atf_test_case mntpt
121mntpt_head() {
122	atf_set "descr" "Tests that the error messages printed when the" \
123	                "mount point is invalid do not show the source" \
124	                "unused parameter"
125	atf_set "use.fs" "true"
126}
127mntpt_body() {
128	mount_tmpfs unused $(pwd)/mnt >out 2>&1
129	atf_check -s eq:1 -o empty -e empty grep unused out
130	atf_check -s eq:0 -o ignore -e empty grep "$(pwd)/mnt" out
131
132	mount_tmpfs unused mnt >out 2>&1
133	atf_check -s eq:1 -o empty -e empty grep unused out
134	atf_check -s eq:0 -o ignore -e empty grep mnt out
135}
136
137atf_init_test_cases() {
138	. $(atf_get_srcdir)/../h_funcs.subr
139	. $(atf_get_srcdir)/h_funcs.subr
140
141	atf_add_test_case plain
142	atf_add_test_case options
143	atf_add_test_case attrs
144	atf_add_test_case negative
145	atf_add_test_case large
146	atf_add_test_case mntpt
147}
148