Imported Upstream version 4.5.14
[platform/upstream/findutils.git] / find / testsuite / sv-34079.sh
1 #! /bin/sh
2 # Copyright (C) 2011 Free Software Foundation, Inc.
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 #
17
18 # This test verifies that find does not have excessive memory consumption
19 # even for large directories.   It's not executed by default; it will only
20 # run if the environment variable RUN_VERY_EXPENSIVE_TESTS is set.
21
22 testname="$(basename $0)"
23
24 . "${srcdir}"/binary_locations.sh
25
26 make_test_data() {
27     d="$1"
28     (
29         cd "$1" && echo "Creating test data in $(pwd -P)" >&2 || exit 1
30         max=400
31         for i in $(seq 0 400)
32         do
33             printf "\r%03d/%03d" $i $max >&2
34             for j in $(seq 0 10000)
35             do
36                 printf "%03d_%04d " $i $j
37             done
38         done | xargs sh -c 'touch "$@" || exit 255' fnord || exit 1
39         printf "\rTest files created.\n" >&2
40     )
41 }
42
43
44 if [[ -n "${RUN_VERY_EXPENSIVE_TESTS}" ]]; then
45     if outdir=$(mktemp -d); then
46         # Create some test files.
47         bad=""
48         printf "Generating test data in %s (this may take some time...):\n" \
49             "${outdir}" >&2
50         if make_test_data "${outdir}"; then
51             # We don't check oldfind, as it uses savedir, meaning that
52             # it stores all the directory entries.  Hence the excessive
53             # memory consumption bug applies to oldfind even though it is
54             # not using fts.
55             for exe in "${ftsfind}" "${oldfind}"; do
56                 echo "Checking memory consumption of ${exe}..." >&2
57                 if ( ulimit -v 50000 && ${exe} "${outdir}" >/dev/null; ); then
58                         echo "Memory consumption of ${exe} is reasonable" >&2
59                 else
60                         bad="${bad}${bad:+\n}Memory consumption of ${exe} is too high"
61                 fi
62             done
63         else
64             bad="failed to set up the test in ${outdir}"
65         fi
66         rm -rf "${outdir}" || exit 1
67         if [[ -n "${bad}" ]]; then
68             echo "${bad}" >&2
69             exit 1
70         fi
71     else
72         echo "FAIL: could not create a test output file." >&2
73         exit 1
74     fi
75 else
76     echo "${testname} was not run because" '${RUN_VERY_EXPENSIVE_TESTS}' \
77         "is unset."
78 fi
79