xref: /aosp_15_r20/external/ltp/testcases/network/nfs/nfs_stress/nfs07.sh (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0-or-later
3# Copyright (c) 2021 SUSE LLC <[email protected]>
4#
5# DESCRIPTION: Create a large number of files and directories on NFS volume.
6# Then check whether they can be listed via NFS.
7
8FILE_COUNT=5000
9
10TST_OPTS="n:"
11TST_PARSE_ARGS="do_parse_args"
12TST_TESTFUNC="do_test"
13TST_SETUP="do_setup"
14TST_USAGE="show_usage"
15
16do_parse_args()
17{
18	case "$1" in
19	n) FILE_COUNT="$2";;
20	esac
21}
22
23show_usage()
24{
25	nfs_usage
26	echo "-n x    Create x files and x directories, default is 5000"
27}
28
29do_setup()
30{
31	nfs_setup
32
33	local rpath=$(nfs_get_remote_path | sed -e 's/%/%%/g')
34	local file_fmt="$rpath/file%1.0f"
35	local dir_fmt="$rpath/dir%1.0f"
36
37	tst_rhost_run -s -c "touch \$(seq -f \"$file_fmt\" -s ' ' $FILE_COUNT)"
38	tst_rhost_run -s -c "mkdir \$(seq -f \"$dir_fmt\" -s ' ' $FILE_COUNT)"
39}
40
41do_test()
42{
43	local count
44
45	# Pass the list of files through `sort -u` in case `ls` doesn't filter
46	# out potential duplicate filenames returned by buggy NFS
47	count=$(ls | grep '^file' | sort -u | wc -l)
48
49	if [ $count -ne $FILE_COUNT ]; then
50		tst_res TFAIL "Listing files failed: $count != $FILE_COUNT"
51		return
52	fi
53
54	count=$(ls | grep '^dir' | sort -u | wc -l)
55
56	if [ $count -ne $FILE_COUNT ]; then
57		tst_res TFAIL "Listing dirs failed: $count != $FILE_COUNT"
58		return
59	fi
60
61	tst_res TPASS "All files and directories were correctly listed"
62}
63
64. nfs_lib.sh
65tst_run
66