Home | History | Annotate | Line # | Download | only in tmpfs
t_setattr.sh revision 1.1
      1 # $NetBSD: t_setattr.sh,v 1.1 2007/11/12 15:18:26 jmmv Exp $
      2 #
      3 # Copyright (c) 2005, 2006, 2007 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 # 3. All advertising materials mentioning features or use of this software
     15 #    must display the following acknowledgement:
     16 #        This product includes software developed by the NetBSD
     17 #        Foundation, Inc. and its contributors.
     18 # 4. Neither the name of The NetBSD Foundation nor the names of its
     19 #    contributors may be used to endorse or promote products derived
     20 #    from this software without specific prior written permission.
     21 #
     22 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     23 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     24 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     25 # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     26 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     27 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     28 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     29 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     30 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     31 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     32 # POSSIBILITY OF SUCH DAMAGE.
     33 #
     34 
     35 #
     36 # Verifies that the setattr vnode operation works, using several commands
     37 # that require this function.
     38 #
     39 
     40 atf_test_case chown
     41 chown_head() {
     42 	atf_set "descr" "Tests that the file owner can be changed"
     43 	atf_set "require.user" "root"
     44 }
     45 chown_body() {
     46 	test_mount
     47 
     48 	atf_check 'mkdir own' 0 null null
     49 	eval $(stat -s own | sed -e 's|st_|ost_|g')
     50 	atf_check 'chown 1234 own' 0 null null
     51 	eval $(stat -s own)
     52 	[ ${st_uid} -eq 1234 ] || atf_fail "uid was not set"
     53 	[ ${st_gid} -eq ${ost_gid} ] || atf_fail "gid was modified"
     54 
     55 	test_unmount
     56 }
     57 
     58 atf_test_case chown_kqueue
     59 chown_kqueue_head() {
     60 	atf_set "descr" "Tests that changing the file owner raises" \
     61 	                "NOTE_ATTRIB on it"
     62 	atf_set "require.user" "root"
     63 }
     64 chown_kqueue_body() {
     65 	test_mount
     66 
     67 	atf_check 'mkdir ownq' 0 null null
     68 	echo 'chown 1234 ownq' | kqueue_monitor 1 ownq
     69 	kqueue_check ownq NOTE_ATTRIB
     70 
     71 	test_unmount
     72 }
     73 
     74 atf_test_case chgrp
     75 chgrp_head() {
     76 	atf_set "descr" "Tests that the file group can be changed"
     77 	atf_set "require.user" "root"
     78 }
     79 chgrp_body() {
     80 	test_mount
     81 
     82 	atf_check 'mkdir grp' 0 null null
     83 	eval $(stat -s grp | sed -e 's|st_|ost_|g')
     84 	atf_check 'chgrp 5678 grp' 0 null null
     85 	eval $(stat -s grp)
     86 	[ ${st_uid} -eq ${ost_uid} ] || atf_fail "uid was modified"
     87 	[ ${st_gid} -eq 5678 ] || atf_fail "gid was not set"
     88 
     89 	test_unmount
     90 }
     91 
     92 atf_test_case chgrp_kqueue
     93 chgrp_kqueue_head() {
     94 	atf_set "descr" "Tests that changing the file group raises" \
     95 	                "NOTE_ATTRIB on it"
     96 	atf_set "require.user" "root"
     97 }
     98 chgrp_kqueue_body() {
     99 	test_mount
    100 
    101 	atf_check 'mkdir grpq' 0 null null
    102 	echo 'chgrp 1234 grpq' | kqueue_monitor 1 grpq
    103 	kqueue_check grpq NOTE_ATTRIB
    104 
    105 	test_unmount
    106 }
    107 
    108 atf_test_case chowngrp
    109 chowngrp_head() {
    110 	atf_set "descr" "Tests that the file owner and group can be" \
    111 	                "changed at once"
    112 	atf_set "require.user" "root"
    113 }
    114 chowngrp_body() {
    115 	test_mount
    116 
    117 	atf_check 'mkdir owngrp' 0 null null
    118 	atf_check 'chown 1234:5678 owngrp' 0 null null
    119 	eval $(stat -s owngrp)
    120 	[ ${st_uid} -eq 1234 ] || atf_fail "uid was not modified"
    121 	[ ${st_gid} -eq 5678 ] || atf_fail "gid was not modified"
    122 
    123 	test_unmount
    124 }
    125 
    126 atf_test_case chowngrp_kqueue
    127 chowngrp_kqueue_head() {
    128 	atf_set "descr" "Tests that changing the file owner and group" \
    129 	                "raises NOTE_ATTRIB on it"
    130 	atf_set "require.user" "root"
    131 }
    132 chowngrp_kqueue_body() {
    133 	test_mount
    134 
    135 	atf_check 'mkdir owngrpp' 0 null null
    136 	echo 'chown 1234:5678 owngrpp' | kqueue_monitor 1 owngrpp
    137 	kqueue_check owngrpp NOTE_ATTRIB
    138 
    139 	test_unmount
    140 }
    141 
    142 atf_test_case chmod
    143 chmod_head() {
    144 	atf_set "descr" "Tests that the file mode can be changed"
    145 	atf_set "require.user" "root"
    146 }
    147 chmod_body() {
    148 	test_mount
    149 
    150 	atf_check 'mkdir mode' 0 null null
    151 	atf_check 'chmod 0000 mode' 0 null null
    152 	eval $(stat -s mode)
    153 	[ ${st_mode} -eq 40000 ] || af_fail "mode was not set"
    154 
    155 	test_unmount
    156 }
    157 
    158 atf_test_case chmod_kqueue
    159 chmod_kqueue_head() {
    160 	atf_set "descr" "Tests that changing the file mode raises" \
    161 	                "NOTE_ATTRIB on it"
    162 	atf_set "require.user" "root"
    163 }
    164 chmod_kqueue_body() {
    165 	test_mount
    166 
    167 	atf_check 'mkdir modeq' 0 null null
    168 	echo 'chmod 0000 modeq' | kqueue_monitor 1 modeq
    169 	kqueue_check modeq NOTE_ATTRIB
    170 
    171 	test_unmount
    172 }
    173 
    174 atf_test_case chtimes
    175 chtimes_head() {
    176 	atf_set "descr" "Tests that file times can be changed"
    177 	atf_set "require.user" "root"
    178 }
    179 chtimes_body() {
    180 	test_mount
    181 
    182 	atf_check 'mkdir times' 0 null null
    183 	atf_check 'TZ=GMT touch -t 200501010101 times' 0 null null
    184 	eval $(stat -s times)
    185 	[ ${st_atime} = ${st_mtime} ] || \
    186 	    atf_fail "atime does not match mtime"
    187 	[ ${st_atime} = 1104541260 ] || atf_fail "atime does not match"
    188 
    189 	test_unmount
    190 }
    191 
    192 atf_test_case chtimes_kqueue
    193 chtimes_kqueue_head() {
    194 	atf_set "descr" "Tests that changing the file times raises" \
    195 	                "NOTE_ATTRIB on it"
    196 	atf_set "require.user" "root"
    197 }
    198 chtimes_kqueue_body() {
    199 	test_mount
    200 
    201 	atf_check 'mkdir timesq' 0 null null
    202 	echo 'touch timesq' | kqueue_monitor 1 timesq
    203 	kqueue_check timesq NOTE_ATTRIB
    204 
    205 	test_unmount
    206 }
    207 
    208 atf_init_test_cases() {
    209 	. $(atf_get_srcdir)/../h_funcs.subr
    210 	. $(atf_get_srcdir)/h_funcs.subr
    211 
    212 	atf_add_test_case chown
    213 	atf_add_test_case chown_kqueue
    214 	atf_add_test_case chgrp
    215 	atf_add_test_case chgrp_kqueue
    216 	atf_add_test_case chowngrp
    217 	atf_add_test_case chowngrp_kqueue
    218 	atf_add_test_case chmod
    219 	atf_add_test_case chmod_kqueue
    220 	atf_add_test_case chtimes
    221 	atf_add_test_case chtimes_kqueue
    222 }
    223