Home | History | Annotate | Line # | Download | only in tmpfs
t_create.sh revision 1.5
      1 # $NetBSD: t_create.sh,v 1.5 2010/06/07 03:39:41 riz 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 the create operation works.
     30 #
     31 
     32 atf_test_case create
     33 create_head() {
     34 	atf_set "descr" "Verifies that files can be created"
     35 	atf_set "require.user" "root"
     36 	atf_set "use.fs" "true"
     37 }
     38 create_body() {
     39 	test_mount
     40 
     41 	atf_check -s eq:1 -o empty -e empty test -f a
     42 	atf_check -s eq:0 -o empty -e empty touch a
     43 	atf_check -s eq:0 -o empty -e empty test -f a
     44 
     45 	test_unmount
     46 }
     47 
     48 atf_test_case attrs
     49 attrs_head() {
     50 	atf_set "descr" "Verifies that a new file gets the correct" \
     51 	                "attributes"
     52 	atf_set "require.config" "unprivileged-user"
     53 	atf_set "require.user" "root"
     54 	atf_set "use.fs" "true"
     55 }
     56 attrs_body() {
     57 	# Allow the unprivileged user to access the work directory.
     58 	chmod 711 .
     59 
     60 	test_mount
     61 
     62 	umask 022
     63 	atf_check -s eq:1 -o empty -e empty test -f a
     64 	atf_check -s eq:0 -o empty -e empty touch a
     65 	atf_check -s eq:0 -o empty -e empty test -f a
     66 
     67 	eval $(stat -s . | sed -e 's|st_|dst_|g')
     68 	eval $(stat -s a)
     69 	test ${st_flags} -eq 0 || atf_fail "Incorrect flags"
     70 	test ${st_size} -eq 0 || atf_fail "Incorrect size"
     71 	test ${st_uid} -eq $(id -u) || atf_fail "Incorrect uid"
     72 	test ${st_gid} -eq ${dst_gid} || atf_fail "Incorrect gid"
     73 	test ${st_mode} = 0100644 || atf_fail "Incorrect mode"
     74 
     75 	user=$(atf_config_get unprivileged-user)
     76 
     77 	atf_check -s eq:0 -o empty -e empty mkdir b c
     78 
     79 	atf_check -s eq:0 -o empty -e empty chown ${user}:0 b
     80 	eval $(stat -s b)
     81 	[ ${st_uid} -eq $(id -u ${user}) ] || atf_fail "Incorrect owner"
     82 	[ ${st_gid} -eq 0 ] || atf_fail "Incorrect group"
     83 
     84 	atf_check -s eq:0 -o empty -e empty chown ${user}:100 c
     85 	eval $(stat -s c)
     86 	[ ${st_uid} -eq $(id -u ${user}) ] || atf_fail "Incorrect owner"
     87 	[ ${st_gid} -eq 100 ] || atf_fail "Incorrect group"
     88 
     89 	atf_check -s eq:0 -o empty -e empty su ${user} -c 'touch b/a'
     90 	eval $(stat -s b/a)
     91 	[ ${st_uid} -eq $(id -u ${user}) ] || atf_fail "Incorrect owner"
     92 	[ ${st_gid} -eq 0 ] || atf_fail "Incorrect group"
     93 
     94 	atf_check -s eq:0 -o empty -e empty su ${user} -c 'touch c/a'
     95 	eval $(stat -s c/a)
     96 	[ ${st_uid} -eq $(id -u ${user}) ] || atf_fail "Incorrect owner"
     97 	[ ${st_gid} -eq 100 ] || atf_fail "Incorrect group"
     98 
     99 	test_unmount
    100 }
    101 
    102 atf_test_case kqueue
    103 kqueue_head() {
    104 	atf_set "descr" "Verifies that creating a file raises the correct" \
    105 	                "kqueue events"
    106 	atf_set "require.user" "root"
    107 	atf_set "use.fs" "true"
    108 }
    109 kqueue_body() {
    110 	test_mount
    111 
    112 	atf_check -s eq:0 -o empty -e empty mkdir dir
    113 	echo 'touch dir/a' | kqueue_monitor 1 dir
    114 	kqueue_check dir NOTE_WRITE
    115 
    116 	test_unmount
    117 }
    118 
    119 atf_init_test_cases() {
    120 	. $(atf_get_srcdir)/../h_funcs.subr
    121 	. $(atf_get_srcdir)/h_funcs.subr
    122 
    123 	atf_add_test_case create
    124 	atf_add_test_case attrs
    125 	atf_add_test_case kqueue
    126 }
    127