t_create.sh revision 272345
12343Scsgr# $NetBSD: t_create.sh,v 1.8 2011/03/05 07:41:11 pooka Exp $
22343Scsgr#
32343Scsgr# Copyright (c) 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc.
42343Scsgr# All rights reserved.
52343Scsgr#
62343Scsgr# Redistribution and use in source and binary forms, with or without
72343Scsgr# modification, are permitted provided that the following conditions
82343Scsgr# are met:
92343Scsgr# 1. Redistributions of source code must retain the above copyright
102343Scsgr#    notice, this list of conditions and the following disclaimer.
112343Scsgr# 2. Redistributions in binary form must reproduce the above copyright
122343Scsgr#    notice, this list of conditions and the following disclaimer in the
132343Scsgr#    documentation and/or other materials provided with the distribution.
142343Scsgr#
152343Scsgr# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
162343Scsgr# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
172343Scsgr# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
182343Scsgr# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
192343Scsgr# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
202343Scsgr# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
212343Scsgr# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
222343Scsgr# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
232343Scsgr# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
242343Scsgr# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
252343Scsgr# POSSIBILITY OF SUCH DAMAGE.
262343Scsgr#
272343Scsgr
282343Scsgr#
292343Scsgr# Verifies that the create operation works.
3050477Speter#
312343Scsgr
322343Scsgratf_test_case create
332343Scsgrcreate_head() {
3479535Sru	atf_set "descr" "Verifies that files can be created"
352343Scsgr	atf_set "require.user" "root"
3679755Sdd}
372343Scsgrcreate_body() {
382343Scsgr	test_mount
3927955Scharnier
402343Scsgr	atf_check -s eq:1 -o empty -e empty test -f a
412343Scsgr	atf_check -s eq:0 -o empty -e empty touch a
4295124Scharnier	atf_check -s eq:0 -o empty -e empty test -f a
4395124Scharnier
4495124Scharnier	test_unmount
4579755Sdd}
462343Scsgr
472343Scsgratf_test_case attrs
482343Scsgrattrs_head() {
492343Scsgr	atf_set "descr" "Verifies that a new file gets the correct" \
502343Scsgr	                "attributes"
512343Scsgr	atf_set "require.config" "unprivileged-user"
522343Scsgr	atf_set "require.user" "root"
532343Scsgr}
542343Scsgrattrs_body() {
552343Scsgr	user=$(atf_config_get unprivileged-user)
562343Scsgr	# Allow the unprivileged user to access the work directory.
5795124Scharnier	chown ${user} .
5895124Scharnier
5995124Scharnier	test_mount
60167103Sru
6168854Sru	umask 022
6275546Sru	atf_check -s eq:1 -o empty -e empty test -f a
632343Scsgr	atf_check -s eq:0 -o empty -e empty touch a
642343Scsgr	atf_check -s eq:0 -o empty -e empty test -f a
652343Scsgr
662343Scsgr	eval $(stat -s . | sed -e 's|st_|dst_|g')
672343Scsgr	eval $(stat -s a)
6875495Sdd	test ${st_flags} -eq 0 || atf_fail "Incorrect flags"
692343Scsgr	test ${st_size} -eq 0 || atf_fail "Incorrect size"
702343Scsgr	test ${st_uid} -eq $(id -u) || atf_fail "Incorrect uid"
712343Scsgr	test ${st_gid} -eq ${dst_gid} || atf_fail "Incorrect gid"
722343Scsgr	test ${st_mode} = 0100644 || atf_fail "Incorrect mode"
732343Scsgr
74131491Sru	atf_check -s eq:0 -o empty -e empty mkdir b c
75131491Sru
762343Scsgr	atf_check -s eq:0 -o empty -e empty chown ${user}:0 b
772343Scsgr	eval $(stat -s b)
782343Scsgr	[ ${st_uid} -eq $(id -u ${user}) ] || atf_fail "Incorrect owner"
792343Scsgr	[ ${st_gid} -eq 0 ] || atf_fail "Incorrect group"
802343Scsgr
8177878Ssobomax	atf_check -s eq:0 -o empty -e empty chown ${user}:100 c
82131491Sru	eval $(stat -s c)
83131491Sru	[ ${st_uid} -eq $(id -u ${user}) ] || atf_fail "Incorrect owner"
842343Scsgr	[ ${st_gid} -eq 100 ] || atf_fail "Incorrect group"
852343Scsgr
86131594Sru	atf_check -s eq:0 -o empty -e empty su -m ${user} -c 'touch b/a'
87131594Sru	eval $(stat -s b/a)
882343Scsgr	[ ${st_uid} -eq $(id -u ${user}) ] || atf_fail "Incorrect owner"
892343Scsgr	[ ${st_gid} -eq 0 ] || atf_fail "Incorrect group"
9027955Scharnier
912343Scsgr	atf_check -s eq:0 -o empty -e empty su -m ${user} -c 'touch c/a'
922343Scsgr	eval $(stat -s c/a)
93167103Sru	[ ${st_uid} -eq $(id -u ${user}) ] || atf_fail "Incorrect owner"
942343Scsgr	[ ${st_gid} -eq 100 ] || atf_fail "Incorrect group"
952343Scsgr
96	test_unmount
97}
98
99atf_test_case kqueue
100kqueue_head() {
101	atf_set "descr" "Verifies that creating a file raises the correct" \
102	                "kqueue events"
103	atf_set "require.user" "root"
104}
105kqueue_body() {
106	test_mount
107
108	atf_check -s eq:0 -o empty -e empty mkdir dir
109	echo 'touch dir/a' | kqueue_monitor 1 dir
110	kqueue_check dir NOTE_WRITE
111
112	test_unmount
113}
114
115atf_init_test_cases() {
116	. $(atf_get_srcdir)/../h_funcs.subr
117	. $(atf_get_srcdir)/h_funcs.subr
118
119	atf_add_test_case create
120	atf_add_test_case attrs
121	atf_add_test_case kqueue
122}
123