tests: add test for locale decimal processing
[coreutils.git] / tests / misc / sort-compress-proc.sh
blobeef8cc87dc63d7e920912dcfd0c0e7b41bedc8c8
1 #!/bin/sh
2 # Test use of compression subprocesses by sort
4 # Copyright (C) 2010-2019 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
20 print_ver_ sort
21 expensive_
23 # Terminate any background processes
24 cleanup_() { kill $pid 2>/dev/null && wait $pid; }
26 SORT_FAILURE=2
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.
33 export PRE_COMPRESS=
34 export POST_COMPRESS=
36 printf '%s\n' '#!'"$SHELL" >compress || framework_failure_
37 cat <<\EOF >>compress || framework_failure_
38 eval "$PRE_COMPRESS"
39 tr 41 14 || exit
40 eval "$POST_COMPRESS"
41 EOF
43 chmod +x compress
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'
54 POST_COMPRESS='
55 test "X$1" != "X'$compress_arg'" || {
56 test "X$1" = "X" && exec <&1
57 size=$(stat -c %s -)
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
63 done
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
74 ) || fail=1
75 compare exp out || fail=1
76 test -f ok || fail=1
77 rm -f ok
79 rm -f compress
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.
85 case $TMPDIR in
86 /*) ;;
87 *) sleep 1;;
88 esac
90 Exit $fail