tests: factor 350 fail=0 initializations into test-lib.sh
[platform/upstream/coreutils.git] / tests / rm / ext3-perf
1 #!/bin/sh
2 # ensure that "rm -rf DIR-with-many-entries" is not O(N^2)
3
4 # Copyright (C) 2008-2009 Free Software Foundation, Inc.
5
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19 if test "$VERBOSE" = yes; then
20   set -x
21   rm --version
22 fi
23
24 . $srcdir/test-lib.sh
25
26 very_expensive_
27
28 # Using rm -rf to remove a 400k-entry directory takes:
29 # - 9 seconds with the patch, on a 2-yr-old system
30 # - 350 seconds without the patch, on a high-end system (disk 20-30% faster)
31 threshold_seconds=60
32
33 # The number of entries in our test directory.
34 n=400000
35
36 # Choose a value that is large enough to ensure an accidentally
37 # regressed rm would require much longer than $threshold_seconds to remove
38 # the directory.  With n=400k, pre-patch GNU rm would require about 350
39 # seconds even on a fast disk.  On a relatively modern system, the
40 # patched version of rm requires about 10 seconds, so even if you
41 # choose to enable very expensive tests with a disk that is much slower,
42 # the test should still succeed.
43
44 # Skip unless "." is on an ext[34] file system.
45 # FIXME-maybe: try to find a suitable file system or allow
46 # the user to specify it via an envvar.
47 df -T -t ext3 -t ext4dev -t ext4 . \
48   || skip_test_ 'this test runs only on an ext3 or ext4 file system'
49
50 # Skip if there are too few inodes free.  Require some slack.
51 free_inodes=$(stat -f --format=%d .) || framework_failure
52 min_free_inodes=$(expr 12 \* $n / 10)
53 test $min_free_inodes -lt $free_inodes \
54   || skip_test_ "too few free inodes on '.': $free_inodes;" \
55       "this test requires at least $min_free_inodes"
56
57 ok=0
58 start=$(date +%s)
59 mkdir d &&
60   cd d &&
61     seq $n | xargs touch &&
62     test -f 1 &&
63     test -f $n &&
64   cd .. &&
65   ok=1
66 test $ok = 1 || framework_failure
67 setup_duration=$(expr $(date +%s) - $start)
68 echo creating a $n-entry directory took $setup_duration seconds
69
70 # If set-up took longer than the default $threshold_seconds,
71 # use the longer set-up duration as the limit.
72 test $threshold_seconds -lt $setup_duration \
73   && threshold_seconds=$setup_duration
74
75 start=$(date +%s)
76 timeout ${threshold_seconds}s rm -rf d; err=$?
77 duration=$(expr $(date +%s) - $start)
78
79 case $err in
80   124) fail=1; echo rm took longer than $threshold_seconds seconds;;
81   0) ;;
82   *) fail=1;;
83 esac
84
85 echo removing a $n-entry directory took $duration seconds
86
87 Exit $fail