1272343Sngie# $NetBSD: t_mount.sh,v 1.6 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 an execution of mount and umount works correctly without
30272343Sngie# causing errors and that the root node gets correct attributes.
31272343Sngie# Also verifies command line parsing from mount_tmpfs.
32272343Sngie#
33272343Sngie
34272343Sngieatf_test_case plain
35272343Sngieplain_head() {
36272343Sngie	atf_set "descr" "Tests a mount and unmount without any options"
37272343Sngie	atf_set "require.user" "root"
38272343Sngie}
39272343Sngieplain_body() {
40272343Sngie	test_mount
41272343Sngie	test_unmount
42272343Sngie}
43272343Sngie
44272343Sngieatf_test_case links
45272343Sngielinks_head() {
46272343Sngie	atf_set "descr" "Tests that the mount point has two hard links"
47272343Sngie	atf_set "require.user" "root"
48272343Sngie}
49272343Sngielinks_body() {
50272343Sngie	test_mount
51272343Sngie	eval $(stat -s ${Mount_Point})
52272343Sngie	[ ${st_nlink} = 2 ] || \
53272343Sngie	    atf_fail "Root directory does not have two hard links"
54272343Sngie	test_unmount
55272343Sngie}
56272343Sngie
57272343Sngieatf_test_case options
58272343Sngieoptions_head() {
59272343Sngie	atf_set "descr" "Tests the read-only mount option"
60272343Sngie	atf_set "require.user" "root"
61272343Sngie}
62272343Sngieoptions_body() {
63272343Sngie	test_mount -o ro
64272343Sngie	mount | grep ${Mount_Point} | grep -q read-only || \
65272343Sngie	    atf_fail "read-only option (ro) does not work"
66272343Sngie	test_unmount
67272343Sngie}
68272343Sngie
69272343Sngieatf_test_case attrs
70272343Sngieattrs_head() {
71272343Sngie	atf_set "descr" "Tests that root directory attributes are set" \
72272343Sngie	                "correctly"
73272343Sngie	atf_set "require.user" "root"
74272343Sngie}
75272343Sngieattrs_body() {
76272343Sngie	test_mount -o -u1000 -o -g100 -o -m755
77272343Sngie	eval $(stat -s ${Mount_Point})
78272343Sngie	[ ${st_uid} = 1000 ] || atf_fail "uid is incorrect"
79272343Sngie	[ ${st_gid} = 100 ] || atf_fail "gid is incorrect"
80272343Sngie	[ ${st_mode} = 040755 ] || atf_fail "mode is incorrect"
81272343Sngie	test_unmount
82272343Sngie}
83272343Sngie
84272343Sngieatf_test_case negative
85272343Sngienegative_head() {
86272343Sngie	atf_set "descr" "Tests that negative values passed to to -s are" \
87272343Sngie	                "handled correctly"
88272343Sngie	atf_set "require.user" "root"
89272343Sngie}
90272343Sngienegative_body() {
91272343Sngie	mkdir tmp
92272343Sngie	test_mount -o -s-10
93272343Sngie	test_unmount
94272343Sngie}
95272343Sngie
96272343Sngieatf_test_case large
97272343Sngielarge_head() {
98272343Sngie	atf_set "descr" "Tests that extremely long values passed to -s" \
99272343Sngie	                "are handled correctly"
100272343Sngie	atf_set "require.user" "root"
101272343Sngie}
102272343Sngielarge_body() {
103272343Sngie	test_mount -o -s9223372036854775807
104272343Sngie	test_unmount
105272343Sngie
106272343Sngie	mkdir tmp
107272343Sngie	atf_check -s eq:1 -o empty -e ignore \
108272343Sngie	    mount -t tmpfs -o -s9223372036854775808 tmpfs tmp
109272343Sngie	atf_check -s eq:1 -o empty -e ignore \
110272343Sngie	    mount -t tmpfs -o -s9223372036854775808g tmpfs tmp
111272343Sngie	rmdir tmp
112272343Sngie}
113272343Sngie
114272343Sngieatf_test_case mntpt
115272343Sngiemntpt_head() {
116272343Sngie	atf_set "descr" "Tests that the error messages printed when the" \
117272343Sngie	                "mount point is invalid do not show the source" \
118272343Sngie	                "unused parameter"
119272343Sngie}
120272343Sngiemntpt_body() {
121272343Sngie	mount_tmpfs unused $(pwd)/mnt >out 2>&1
122272343Sngie	atf_check -s eq:1 -o empty -e empty grep unused out
123272343Sngie	atf_check -s eq:0 -o ignore -e empty grep "$(pwd)/mnt" out
124272343Sngie
125272343Sngie	mount_tmpfs unused mnt >out 2>&1
126272343Sngie	atf_check -s eq:1 -o empty -e empty grep unused out
127272343Sngie	atf_check -s eq:0 -o ignore -e empty grep mnt out
128272343Sngie}
129272343Sngie
130272343Sngieatf_init_test_cases() {
131272343Sngie	. $(atf_get_srcdir)/../h_funcs.subr
132272343Sngie	. $(atf_get_srcdir)/h_funcs.subr
133272343Sngie
134272343Sngie	atf_add_test_case plain
135272343Sngie	atf_add_test_case options
136272343Sngie	atf_add_test_case attrs
137272343Sngie	atf_add_test_case negative
138272343Sngie	atf_add_test_case large
139272343Sngie	atf_add_test_case mntpt
140272343Sngie}
141