build: ensure make-prime-list doesn't access out of bounds memory
[platform/upstream/coreutils.git] / tests / misc / sort-compress.sh
1 #!/bin/sh
2 # Test use of compression by sort
3
4 # Copyright (C) 2007-2013 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 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20 print_ver_ sort
21
22 seq -w 2000 > exp || framework_failure_
23 tac exp > in || framework_failure_
24
25 # This should force the use of temp files
26 sort -S 1k in > out || fail=1
27 compare exp out || fail=1
28
29 # Create our own gzip program that will be used as the default
30 cat <<\EOF > gzip || fail=1
31 #!/bin/sh
32 tr 41 14
33 touch ok
34 EOF
35
36 chmod +x gzip
37
38 # Ensure 'sort' is immune to parent's SIGCHLD handler
39 # Use a subshell and an exec to work around a bug in FreeBSD 5.0 /bin/sh.
40 (
41   # ash doesn't support "trap '' CHLD"; it knows only signal numbers.
42   sig=$("$abs_top_builddir/src/kill" -l CHLD 2>/dev/null) && trap '' $sig
43
44   # This should force the use of child processes for "compression"
45   PATH=.:$PATH exec sort -S 1k --compress-program=gzip in > /dev/null
46 ) || fail=1
47
48 # This will find our new gzip in PATH
49 PATH=.:$PATH sort -S 1k --compress-program=gzip in > out || fail=1
50 compare exp out || fail=1
51 test -f ok || fail=1
52 rm -f ok
53
54 # This is to make sure it works with no compression.
55 PATH=.:$PATH sort -S 1k in > out || fail=1
56 compare exp out || fail=1
57 test -f ok && fail=1
58
59 # This is to make sure we can use something other than gzip
60 mv gzip dzip || fail=1
61 sort --compress-program=./dzip -S 1k in > out || fail=1
62 compare exp out || fail=1
63 test -f ok || fail=1
64 rm -f ok
65
66 # Make sure it can find other programs in PATH correctly
67 PATH=.:$PATH sort --compress-program=dzip -S 1k in > out || fail=1
68 compare exp out || fail=1
69 test -f ok || fail=1
70 rm -f dzip ok
71
72 Exit $fail