1170809Sdelphij#!/bin/sh
2170809Sdelphij#
3170809Sdelphij# $NetBSD: t_readdir,v 1.5 2006/11/09 16:20:06 jmmv Exp $
4170809Sdelphij#
5170809Sdelphij# Copyright (c) 2005, 2006 The NetBSD Foundation, Inc.
6170809Sdelphij# All rights reserved.
7170809Sdelphij#
8170809Sdelphij# This code is derived from software contributed to The NetBSD Foundation
9170809Sdelphij# by Julio M. Merino Vidal, developed as part of Google's Summer of Code
10170809Sdelphij# 2005 program.
11170809Sdelphij#
12170809Sdelphij# Redistribution and use in source and binary forms, with or without
13170809Sdelphij# modification, are permitted provided that the following conditions
14170809Sdelphij# are met:
15170809Sdelphij# 1. Redistributions of source code must retain the above copyright
16170809Sdelphij#    notice, this list of conditions and the following disclaimer.
17170809Sdelphij# 2. Redistributions in binary form must reproduce the above copyright
18170809Sdelphij#    notice, this list of conditions and the following disclaimer in the
19170809Sdelphij#    documentation and/or other materials provided with the distribution.
20170809Sdelphij#
21170809Sdelphij# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22170809Sdelphij# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23170809Sdelphij# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24170809Sdelphij# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25170809Sdelphij# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26170809Sdelphij# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27170809Sdelphij# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28170809Sdelphij# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29170809Sdelphij# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30170809Sdelphij# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31170809Sdelphij# POSSIBILITY OF SUCH DAMAGE.
32170809Sdelphij#
33170809Sdelphij# $FreeBSD: releng/11.0/tools/regression/tmpfs/t_readdir 204608 2010-03-02 22:25:50Z joel $
34170809Sdelphij#
35170809Sdelphij
36170809Sdelphij#
37170809Sdelphij# Verifies that the readdir operation works.
38170809Sdelphij#
39170809Sdelphij
40170809Sdelphijtest_run() {
41170809Sdelphij	test_mount
42170809Sdelphij
43170809Sdelphij	test_name "Directory has '.' and '..' entries"
44170809Sdelphij	/bin/ls -a | grep '^\.$' >/dev/null || die
45170809Sdelphij	/bin/ls -a | grep '^\..$' >/dev/null || die
46170809Sdelphij
47170809Sdelphij	test_name "Creation of files of all possible types"
48170809Sdelphij	mkdir dir || die
49170809Sdelphij	touch reg || die
50170809Sdelphij	ln -s reg lnk || die
51170809Sdelphij	mknod b blk 0 0 || die
52170809Sdelphij	mknod c chr 0 0 || die
53170809Sdelphij	mkfifo fifo || die
54170809Sdelphij	${Src_Dir}/h_tools sockets sock || die
55170809Sdelphij
56170809Sdelphij	test_name "Read of directory"
57170809Sdelphij	ls >/dev/null || die
58170809Sdelphij	rm -rf * || die
59170809Sdelphij
60170809Sdelphij	# Catch a bug caused by incorrect invalidation of readdir caching
61170809Sdelphij	# variables.
62170809Sdelphij	test_name "Populate directory"
63170809Sdelphij	touch $(jot 10) || die
64170809Sdelphij	test_name "Clean it"
65170809Sdelphij	rm * || die
66170809Sdelphij	test_name "Repopulate directory"
67170809Sdelphij	touch $(jot 20) || die
68170809Sdelphij	test_name "Listing should return all entries"
69170809Sdelphij	ls >/dev/null || die
70170809Sdelphij
71170809Sdelphij	test_name "Creation of many files"
72170809Sdelphij	mkdir a || die
73170809Sdelphij	for f in $(jot 500); do
74170809Sdelphij		touch a/$f || die
75170809Sdelphij	done
76170809Sdelphij
77170809Sdelphij	test_name "Removal of all files using a wildcard"
78170809Sdelphij	rm a/* || die
79170809Sdelphij
80170809Sdelphij	test_name "Removal of should-be-empty directory"
81170809Sdelphij	rmdir a || die
82170809Sdelphij
83170809Sdelphij	test_unmount
84170809Sdelphij}
85170809Sdelphij
86170809Sdelphij. ${SUBRDIR}/h_funcs.subr
87