11.6Srillig# $NetBSD: t_readdir.sh,v 1.6 2024/04/28 07:27:41 rillig Exp $
21.1Sjmmv#
31.3Sjmmv# Copyright (c) 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc.
41.1Sjmmv# All rights reserved.
51.1Sjmmv#
61.1Sjmmv# Redistribution and use in source and binary forms, with or without
71.1Sjmmv# modification, are permitted provided that the following conditions
81.1Sjmmv# are met:
91.1Sjmmv# 1. Redistributions of source code must retain the above copyright
101.1Sjmmv#    notice, this list of conditions and the following disclaimer.
111.1Sjmmv# 2. Redistributions in binary form must reproduce the above copyright
121.1Sjmmv#    notice, this list of conditions and the following disclaimer in the
131.1Sjmmv#    documentation and/or other materials provided with the distribution.
141.1Sjmmv#
151.1Sjmmv# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
161.1Sjmmv# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
171.1Sjmmv# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
181.1Sjmmv# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
191.1Sjmmv# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
201.1Sjmmv# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
211.1Sjmmv# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
221.1Sjmmv# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
231.1Sjmmv# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
241.1Sjmmv# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
251.1Sjmmv# POSSIBILITY OF SUCH DAMAGE.
261.1Sjmmv#
271.1Sjmmv
281.1Sjmmv#
291.1Sjmmv# Verifies that the readdir operation works.
301.1Sjmmv#
311.1Sjmmv
321.1Sjmmvatf_test_case dots
331.1Sjmmvdots_head() {
341.1Sjmmv	atf_set "descr" "Verifies that readdir returns the '.' and '..'" \
351.1Sjmmv	                "entries"
361.1Sjmmv	atf_set "require.user" "root"
371.1Sjmmv}
381.1Sjmmvdots_body() {
391.1Sjmmv	test_mount
401.1Sjmmv
411.6Srillig	atf_check -s exit:0 -o save:stdout -e empty /bin/ls -a
421.6Srillig	atf_check -s exit:0 -o ignore -e empty grep '^\.$' stdout
431.6Srillig	atf_check -s exit:0 -o ignore -e empty grep '^\..$' stdout
441.1Sjmmv
451.1Sjmmv	test_unmount
461.1Sjmmv}
471.1Sjmmv
481.1Sjmmvatf_test_case types
491.1Sjmmvtypes_head() {
501.1Sjmmv	atf_set "descr" "Verifies that readdir works for all different" \
511.1Sjmmv	                "file types"
521.1Sjmmv	atf_set "require.user" "root"
531.1Sjmmv}
541.1Sjmmvtypes_body() {
551.1Sjmmv	test_mount
561.1Sjmmv
571.6Srillig	atf_check -s exit:0 -o empty -e empty mkdir dir
581.6Srillig	atf_check -s exit:0 -o empty -e empty touch reg
591.6Srillig	atf_check -s exit:0 -o empty -e empty ln -s reg lnk
601.6Srillig	atf_check -s exit:0 -o empty -e empty mknod blk b 0 0
611.6Srillig	atf_check -s exit:0 -o empty -e empty mknod chr c 0 0
621.6Srillig	atf_check -s exit:0 -o empty -e empty mknod fifo p
631.6Srillig	atf_check -s exit:0 -o empty -e empty \
641.3Sjmmv	    $(atf_get_srcdir)/h_tools sockets sock
651.1Sjmmv
661.6Srillig	atf_check -s exit:0 -o ignore -e empty ls
671.6Srillig	atf_check -s exit:0 -o empty -e empty rm -rf *
681.1Sjmmv
691.1Sjmmv	test_unmount
701.1Sjmmv}
711.1Sjmmv
721.1Sjmmvatf_test_case caching
731.1Sjmmvcaching_head() {
741.1Sjmmv	atf_set "descr" "Catch a bug caused by incorrect invalidation of" \
751.1Sjmmv	                "readdir caching variables"
761.1Sjmmv	atf_set "require.user" "root"
771.1Sjmmv}
781.1Sjmmvcaching_body() {
791.1Sjmmv	test_mount
801.1Sjmmv
811.6Srillig	atf_check -s exit:0 -o empty -e empty touch $(jot 10)
821.6Srillig	atf_check -s exit:0 -o empty -e empty rm *
831.6Srillig	atf_check -s exit:0 -o empty -e empty touch $(jot 20)
841.6Srillig	atf_check -s exit:0 -o empty -e empty -x "ls >/dev/null"
851.1Sjmmv
861.1Sjmmv	test_unmount
871.1Sjmmv}
881.1Sjmmv
891.1Sjmmvatf_test_case many
901.1Sjmmvmany_head() {
911.1Sjmmv	atf_set "descr" "Verifies that readdir works with many files"
921.1Sjmmv	atf_set "require.user" "root"
931.1Sjmmv}
941.1Sjmmvmany_body() {
951.1Sjmmv	test_mount
961.1Sjmmv
971.6Srillig	atf_check -s exit:0 -o empty -e empty mkdir a
981.1Sjmmv	echo "Creating 500 files"
991.1Sjmmv	for f in $(jot 500); do
1001.1Sjmmv		touch a/$f
1011.1Sjmmv	done
1021.6Srillig	atf_check -s exit:0 -o empty -e empty rm a/*
1031.6Srillig	atf_check -s exit:0 -o empty -e empty rmdir a
1041.1Sjmmv
1051.1Sjmmv	test_unmount
1061.1Sjmmv}
1071.1Sjmmv
1081.1Sjmmvatf_init_test_cases() {
1091.1Sjmmv	. $(atf_get_srcdir)/../h_funcs.subr
1101.1Sjmmv	. $(atf_get_srcdir)/h_funcs.subr
1111.1Sjmmv
1121.1Sjmmv	atf_add_test_case dots
1131.1Sjmmv	atf_add_test_case types
1141.1Sjmmv	atf_add_test_case caching
1151.1Sjmmv	atf_add_test_case many
1161.1Sjmmv}
117