tests: avoid false failure in tail inotify test
[coreutils.git] / tests / misc / cut-huge-range.sh
blob92b62a97be4e6e2a615a3b8b78c4924225371233
1 #!/bin/sh
2 # Ensure that cut does not allocate mem for large ranges
4 # Copyright (C) 2012-2016 Free Software Foundation, Inc.
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.
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.
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/>.
19 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20 print_ver_ cut
21 getlimits_
23 vm=$(get_min_ulimit_v_ cut -b1 /dev/null) \
24 || skip_ "this shell lacks ulimit support"
26 # sed script to subtract one from the input.
27 # Each input line should consist of a positive decimal number.
28 # Each output line's number is one less than the input's.
29 # There's no limit (other than line length) on the number's magnitude.
30 subtract_one='
31 s/$/@/
32 : again
33 s/0@/@9/
34 s/1@/0/
35 s/2@/1/
36 s/3@/2/
37 s/4@/3/
38 s/5@/4/
39 s/6@/5/
40 s/7@/6/
41 s/8@/7/
42 s/9@/8/
43 t again
46 # Ensure we can cut up to our sentinel value.
47 # This is currently SIZE_MAX, but could be raised to UINTMAX_MAX
48 # if we didn't allocate memory for each line as a unit.
49 # Don't use expr to subtract one, since SIZE_MAX may exceed its maximum value.
50 CUT_MAX=$(echo $SIZE_MAX | sed "$subtract_one")
52 # From coreutils-8.10 through 8.20, this would make cut try to allocate
53 # a 256MiB bit vector.
54 (ulimit -v $vm && cut -b$CUT_MAX- /dev/null > err 2>&1) || fail=1
56 # Up to and including coreutils-8.21, cut would allocate possibly needed
57 # memory upfront. Subsequently extra memory is no longer needed.
58 (ulimit -v $vm && cut -b1-$CUT_MAX /dev/null >> err 2>&1) || fail=1
60 # Explicitly disallow values above CUT_MAX
61 (ulimit -v $vm && returns_ 1 cut -b$SIZE_MAX /dev/null 2>/dev/null) || fail=1
62 (ulimit -v $vm && returns_ 1 cut -b$SIZE_OFLOW /dev/null 2>/dev/null) || fail=1
64 compare /dev/null err || fail=1
66 Exit $fail