2 # Test use of compression subprocesses by sort
4 # Copyright (C) 2010-2013 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
23 seq -w 2000 > exp || fail=1
24 tac exp > in || fail=1
25 insize=$(stat -c %s - <in) || fail=1
27 # This compressor's behavior is adjustable via environment variables.
30 cat <<\EOF >compress || framework_failure_
39 # "Impatient exit" tests
41 # In these test cases, the biggest compressor (or decompressor) exits
42 # with nonzero status, after sleeping a bit. Until coreutils 8.7
43 # 'sort' impatiently exited without waiting for its decompression
44 # subprocesses in these cases. Check compression too, while we're here.
46 for compress_arg in '' '-d'
49 test "X$1" != "X'$compress_arg'" || {
50 test "X$1" = "X" && exec <&1
52 exec >/dev/null 2>&1 <&1 || exit
53 expr $size "<" '"$insize"' / 2 || { sleep 1; exit 1; }
55 ' sort --compress-program=./compress -S 1k --batch-size=2 in > out && fail=1
58 # "Pre-exec child" test
60 # Ignore a random child process created before 'sort' was exec'ed.
61 # This bug was also present in coreutils 8.7.
63 ( (sleep 1; exec false) &
64 PRE_COMPRESS='test -f ok || sleep 2'
65 POST_COMPRESS='touch ok'
66 exec sort --compress-program=./compress -S 1k in >out
68 compare exp out || fail=1
74 # If $TMPDIR is relative, give subprocesses time to react when 'sort' exits.
75 # Otherwise, under NFS, when 'sort' unlinks the temp files and they
76 # are renamed to .nfsXXXX instead of being removed, the parent cleanup
77 # of this directory will fail because the files are still open.