blob: ed4b6c0d322e31960b1c620b5aa19c4039cce901 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#!/bin/sh
# Exercise sort buffer sizing for streaming input.
# Copyright (C) 2026 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
print_ver_ sort
seq -w 200000 > exp || framework_failure_
# The no-temp-file checks below need about 12 MiB of sort buffer,
# so test 10x that available as the check is somewhat racy.
avail_mem_mb=$(free -m 2>/dev/null | grep '^Mem:' | cut -F 7)
test "$avail_mem_mb" -gt 120 ||
skip_ 'unable to determine enough memory available'
rlimit=$(ulimit -v)
test "$rlimit" = 'unlimited' ||
test "$(($rlimit/1024))" -gt 120 ||
skip_ 'unable to determine enough resources available'
cwd=$(pwd)
# Without an explicit -S, sort should grow a pipe buffer enough to avoid
# creating a temporary file for this input.
tac exp | TMPDIR="$cwd"/no-temp sort --parallel=1 > out || fail=1
{ test -s out && compare exp out; } || fail=1
# Check the same path when sort has precomputed key pointers in the
# line table that must be adjusted after the buffer moves.
sed 's/^/k /' exp > exp-key || framework_failure_
tac exp-key | TMPDIR="$cwd"/no-temp sort --parallel=1 -k2,2 > out || fail=1
{ test -s out && compare exp-key out; } || fail=1
# An explicit -S remains a limit for ordinary buffer growth, so this must
# still need a temporary file and fail because TMPDIR is not a directory.
returns_ 2 env TMPDIR="$cwd"/no-temp \
$SHELL -c 'tac exp | sort --parallel=1 -S 1M > small-out' || fail=1
Exit $fail
|