Home | History | Annotate | Line # | Download | only in tmpfs
t_mount.sh revision 1.7
      1  1.7  rillig # $NetBSD: t_mount.sh,v 1.7 2024/04/28 07:27:41 rillig Exp $
      2  1.1    jmmv #
      3  1.2    jmmv # Copyright (c) 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc.
      4  1.1    jmmv # All rights reserved.
      5  1.1    jmmv #
      6  1.1    jmmv # Redistribution and use in source and binary forms, with or without
      7  1.1    jmmv # modification, are permitted provided that the following conditions
      8  1.1    jmmv # are met:
      9  1.1    jmmv # 1. Redistributions of source code must retain the above copyright
     10  1.1    jmmv #    notice, this list of conditions and the following disclaimer.
     11  1.1    jmmv # 2. Redistributions in binary form must reproduce the above copyright
     12  1.1    jmmv #    notice, this list of conditions and the following disclaimer in the
     13  1.1    jmmv #    documentation and/or other materials provided with the distribution.
     14  1.1    jmmv #
     15  1.1    jmmv # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     16  1.1    jmmv # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     17  1.1    jmmv # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     18  1.1    jmmv # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     19  1.1    jmmv # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     20  1.1    jmmv # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     21  1.1    jmmv # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     22  1.1    jmmv # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     23  1.1    jmmv # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     24  1.1    jmmv # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     25  1.1    jmmv # POSSIBILITY OF SUCH DAMAGE.
     26  1.1    jmmv #
     27  1.1    jmmv 
     28  1.1    jmmv #
     29  1.1    jmmv # Verifies that an execution of mount and umount works correctly without
     30  1.1    jmmv # causing errors and that the root node gets correct attributes.
     31  1.1    jmmv # Also verifies command line parsing from mount_tmpfs.
     32  1.1    jmmv #
     33  1.1    jmmv 
     34  1.1    jmmv atf_test_case plain
     35  1.1    jmmv plain_head() {
     36  1.1    jmmv 	atf_set "descr" "Tests a mount and unmount without any options"
     37  1.1    jmmv 	atf_set "require.user" "root"
     38  1.1    jmmv }
     39  1.1    jmmv plain_body() {
     40  1.1    jmmv 	test_mount
     41  1.1    jmmv 	test_unmount
     42  1.1    jmmv }
     43  1.1    jmmv 
     44  1.1    jmmv atf_test_case links
     45  1.1    jmmv links_head() {
     46  1.1    jmmv 	atf_set "descr" "Tests that the mount point has two hard links"
     47  1.1    jmmv 	atf_set "require.user" "root"
     48  1.1    jmmv }
     49  1.1    jmmv links_body() {
     50  1.1    jmmv 	test_mount
     51  1.1    jmmv 	eval $(stat -s ${Mount_Point})
     52  1.1    jmmv 	[ ${st_nlink} = 2 ] || \
     53  1.1    jmmv 	    atf_fail "Root directory does not have two hard links"
     54  1.1    jmmv 	test_unmount
     55  1.1    jmmv }
     56  1.1    jmmv 
     57  1.1    jmmv atf_test_case options
     58  1.1    jmmv options_head() {
     59  1.1    jmmv 	atf_set "descr" "Tests the read-only mount option"
     60  1.1    jmmv 	atf_set "require.user" "root"
     61  1.1    jmmv }
     62  1.1    jmmv options_body() {
     63  1.1    jmmv 	test_mount -o ro
     64  1.1    jmmv 	mount | grep ${Mount_Point} | grep -q read-only || \
     65  1.1    jmmv 	    atf_fail "read-only option (ro) does not work"
     66  1.1    jmmv 	test_unmount
     67  1.1    jmmv }
     68  1.1    jmmv 
     69  1.1    jmmv atf_test_case attrs
     70  1.1    jmmv attrs_head() {
     71  1.1    jmmv 	atf_set "descr" "Tests that root directory attributes are set" \
     72  1.1    jmmv 	                "correctly"
     73  1.1    jmmv 	atf_set "require.user" "root"
     74  1.1    jmmv }
     75  1.1    jmmv attrs_body() {
     76  1.1    jmmv 	test_mount -o -u1000 -o -g100 -o -m755
     77  1.1    jmmv 	eval $(stat -s ${Mount_Point})
     78  1.1    jmmv 	[ ${st_uid} = 1000 ] || atf_fail "uid is incorrect"
     79  1.1    jmmv 	[ ${st_gid} = 100 ] || atf_fail "gid is incorrect"
     80  1.1    jmmv 	[ ${st_mode} = 040755 ] || atf_fail "mode is incorrect"
     81  1.1    jmmv 	test_unmount
     82  1.1    jmmv }
     83  1.1    jmmv 
     84  1.1    jmmv atf_test_case negative
     85  1.1    jmmv negative_head() {
     86  1.1    jmmv 	atf_set "descr" "Tests that negative values passed to to -s are" \
     87  1.1    jmmv 	                "handled correctly"
     88  1.1    jmmv 	atf_set "require.user" "root"
     89  1.1    jmmv }
     90  1.1    jmmv negative_body() {
     91  1.1    jmmv 	mkdir tmp
     92  1.1    jmmv 	test_mount -o -s-10
     93  1.1    jmmv 	test_unmount
     94  1.1    jmmv }
     95  1.1    jmmv 
     96  1.1    jmmv atf_test_case large
     97  1.1    jmmv large_head() {
     98  1.1    jmmv 	atf_set "descr" "Tests that extremely long values passed to -s" \
     99  1.1    jmmv 	                "are handled correctly"
    100  1.1    jmmv 	atf_set "require.user" "root"
    101  1.1    jmmv }
    102  1.1    jmmv large_body() {
    103  1.1    jmmv 	test_mount -o -s9223372036854775807
    104  1.1    jmmv 	test_unmount
    105  1.1    jmmv 
    106  1.1    jmmv 	mkdir tmp
    107  1.7  rillig 	atf_check -s exit:1 -o empty -e ignore \
    108  1.4    jmmv 	    mount -t tmpfs -o -s9223372036854775808 tmpfs tmp
    109  1.7  rillig 	atf_check -s exit:1 -o empty -e ignore \
    110  1.4    jmmv 	    mount -t tmpfs -o -s9223372036854775808g tmpfs tmp
    111  1.1    jmmv 	rmdir tmp
    112  1.1    jmmv }
    113  1.1    jmmv 
    114  1.2    jmmv atf_test_case mntpt
    115  1.2    jmmv mntpt_head() {
    116  1.2    jmmv 	atf_set "descr" "Tests that the error messages printed when the" \
    117  1.2    jmmv 	                "mount point is invalid do not show the source" \
    118  1.2    jmmv 	                "unused parameter"
    119  1.2    jmmv }
    120  1.2    jmmv mntpt_body() {
    121  1.2    jmmv 	mount_tmpfs unused $(pwd)/mnt >out 2>&1
    122  1.7  rillig 	atf_check -s exit:1 -o empty -e empty grep unused out
    123  1.7  rillig 	atf_check -s exit:0 -o ignore -e empty grep "$(pwd)/mnt" out
    124  1.2    jmmv 
    125  1.2    jmmv 	mount_tmpfs unused mnt >out 2>&1
    126  1.7  rillig 	atf_check -s exit:1 -o empty -e empty grep unused out
    127  1.7  rillig 	atf_check -s exit:0 -o ignore -e empty grep mnt out
    128  1.2    jmmv }
    129  1.2    jmmv 
    130  1.1    jmmv atf_init_test_cases() {
    131  1.1    jmmv 	. $(atf_get_srcdir)/../h_funcs.subr
    132  1.1    jmmv 	. $(atf_get_srcdir)/h_funcs.subr
    133  1.1    jmmv 
    134  1.1    jmmv 	atf_add_test_case plain
    135  1.1    jmmv 	atf_add_test_case options
    136  1.1    jmmv 	atf_add_test_case attrs
    137  1.1    jmmv 	atf_add_test_case negative
    138  1.1    jmmv 	atf_add_test_case large
    139  1.2    jmmv 	atf_add_test_case mntpt
    140  1.1    jmmv }
    141