2 # Test use of compression subprocesses by sort
4 # Copyright (C) 2010-2024 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 <https://www.gnu.org/licenses/>.
19 .
"${srcdir=.}/tests/init.sh"; path_prepend_ .
/src
23 # Terminate any background processes
24 cleanup_
() { kill $pid 2>/dev
/null
&& wait $pid; }
28 seq -w 2000 > exp || fail
=1
29 tac exp
> in || fail
=1
30 insize
=$
(stat
-c %s
- <in) || fail
=1
32 # This compressor's behavior is adjustable via environment variables.
36 printf '%s\n' '#!'"$SHELL" >compress || framework_failure_
37 cat <<\EOF
>>compress || framework_failure_
45 # "Impatient exit" tests
47 # In these test cases, the biggest compressor (or decompressor) exits
48 # with nonzero status, after sleeping a bit. Until coreutils 8.7
49 # 'sort' impatiently exited without waiting for its decompression
50 # subprocesses in these cases. Check compression too, while we're here.
52 for compress_arg
in '' '-d'
55 test "X$1" != "X'$compress_arg'" || {
56 test "X$1" = "X" && exec <&1
58 exec >/dev/null 2>&1 <&1 || exit
59 expr $size "<" '"$insize"' / 2 || { sleep 1; exit 1; }
61 ' sort --compress-program=.
/compress -S 1k
--batch-size=2 in > out
62 test $?
-eq $SORT_FAILURE || fail
=1
65 # "Pre-exec child" test
67 # Ignore a random child process created before 'sort' was exec'ed.
68 # This bug was also present in coreutils 8.7.
70 ( (sleep 1; exec false
) & pid
=$
!
71 PRE_COMPRESS
='test -f ok || sleep 2'
72 POST_COMPRESS
='touch ok'
73 exec sort --compress-program=.
/compress -S 1k
in >out
75 compare exp out || fail
=1
81 # If $TMPDIR is relative, give subprocesses time to react when 'sort' exits.
82 # Otherwise, under NFS, when 'sort' unlinks the temp files and they
83 # are renamed to .nfsXXXX instead of being removed, the parent cleanup
84 # of this directory will fail because the files are still open.