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 Mount_Point=$(pwd)/mnt _test_unmount || : 102} 103else 104# End FreeBSD 105atf_test_case large 106# Begin FreeBSD 107fi 108# End FreeBSD 109large_head() { 110 atf_set "descr" "Tests that extremely long values passed to -s" \ 111 "are handled correctly" 112 atf_set "require.user" "root" 113} 114large_body() { 115 test_mount -o -s9223372036854775807 116 test_unmount 117 118 # Begin FreeBSD 119 atf_expect_fail "-o -s<large-size> succeeds unexpectedly on FreeBSD - bug 212862" 120 # End FreeBSD 121 122 mkdir tmp 123 atf_check -s eq:1 -o empty -e ignore \ 124 mount -t tmpfs -o -s9223372036854775808 tmpfs tmp 125 atf_check -s eq:1 -o empty -e ignore \ 126 mount -t tmpfs -o -s9223372036854775808g tmpfs tmp 127 rmdir tmp 128} 129 130atf_test_case mntpt 131mntpt_head() { 132 atf_set "descr" "Tests that the error messages printed when the" \ 133 "mount point is invalid do not show the source" \ 134 "unused parameter" 135} 136mntpt_body() { 137 mount_tmpfs unused $(pwd)/mnt >out 2>&1 138 atf_check -s eq:1 -o empty -e empty grep unused out 139 atf_check -s eq:0 -o ignore -e empty grep "$(pwd)/mnt" out 140 141 mount_tmpfs unused mnt >out 2>&1 142 atf_check -s eq:1 -o empty -e empty grep unused out 143 atf_check -s eq:0 -o ignore -e empty grep mnt out 144} 145 146atf_init_test_cases() { 147 . $(atf_get_srcdir)/../h_funcs.subr 148 . $(atf_get_srcdir)/h_funcs.subr 149 150 atf_add_test_case plain 151 atf_add_test_case options 152 atf_add_test_case attrs 153 atf_add_test_case negative 154 atf_add_test_case large 155 atf_add_test_case mntpt 156} 157