mirror of
https://git.savannah.gnu.org/git/coreutils.git
synced 2025-08-07 07:22:55 +03:00
tests: refactor to use the new getlimits utility
* tests/Coreutils.pm: Add function to make limits available * tests/test-lib.sh: ditto * tests/misc/join: Check for both SIZE_OFLOW and UINTMAX_OFLOW rather than using arbitrary 2^128 * tests/misc/sort: ditto * tests/misc/uniq: ditto * tests/misc/printf: Check for both INT_OFLOW and INT_UFLOW rather than using arbitrary -2^31 * tests/misc/seq-long-double: Check for INTMAX_OFLOW rather than using arbitrary 2^63 * tests/misc/split-fail: Check --lines --bytes and --line-bytes options limits on all platforms. Note getlimits obviates the need to use expr to check if 32 bit integers are supported, which I think was invalid anyway as expr now supports bignum? * tests/misc/test: Check for UINTMAX_OFLOW rather than using arbitrary 2^64 and 2^128. Check for INTMAX_UFLOW rather than using arbitrary -2^64 * tests/misc/timeout-parameters: Check for UINT_OFLOW rather than using arbitrary 2^32 * tests/misc/truncate-overflow: Don't depend on truncate to determine if we're on a 32 or 64 bit platform and instead use the various OFF_T limits * tests/misc/sort-merge: Check for UINTMAX_OFLOW rather than using arbitrary 2^64+1 * tests/misc/unexpand: ditto
This commit is contained in:
@@ -24,7 +24,7 @@ use File::Compare qw(compare);
|
|||||||
|
|
||||||
@ISA = qw(Exporter);
|
@ISA = qw(Exporter);
|
||||||
($VERSION = '$Revision: 1.5 $ ') =~ tr/[0-9].//cd;
|
($VERSION = '$Revision: 1.5 $ ') =~ tr/[0-9].//cd;
|
||||||
@EXPORT = qw (run_tests triple_test);
|
@EXPORT = qw (run_tests triple_test getlimits);
|
||||||
|
|
||||||
my $debug = $ENV{DEBUG};
|
my $debug = $ENV{DEBUG};
|
||||||
|
|
||||||
@@ -204,6 +204,14 @@ sub _at_replace ($$)
|
|||||||
return $s;
|
return $s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub getlimits()
|
||||||
|
{
|
||||||
|
my $NV;
|
||||||
|
open $NV, "getlimits |" or die "Error running getlimits\n";
|
||||||
|
my %limits = map {split /=|\n/} <$NV>;
|
||||||
|
return \%limits;
|
||||||
|
}
|
||||||
|
|
||||||
# FIXME: cleanup on interrupt
|
# FIXME: cleanup on interrupt
|
||||||
# FIXME: extract `do_1_test' function
|
# FIXME: extract `do_1_test' function
|
||||||
|
|
||||||
|
@@ -18,6 +18,8 @@
|
|||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
|
|
||||||
|
my $limits = getlimits ();
|
||||||
|
|
||||||
# Turn off localization of executable's output.
|
# Turn off localization of executable's output.
|
||||||
@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
|
@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
|
||||||
|
|
||||||
@@ -138,7 +140,10 @@ my @tv = (
|
|||||||
[t_subst "a:1\nb:1\n", t_subst "a:2:\nb:2:\n"],
|
[t_subst "a:1\nb:1\n", t_subst "a:2:\nb:2:\n"],
|
||||||
t_subst "a:1:2:\nb:1:2:\n", 0],
|
t_subst "a:1:2:\nb:1:2:\n", 0],
|
||||||
|
|
||||||
['bigfield', '-1 340282366920938463463374607431768211456 -2 2',
|
# fields > SIZE_MAX are silently interpreted as SIZE_MAX
|
||||||
|
['bigfield1', "-1 $limits->{'UINTMAX_OFLOW'} -2 2",
|
||||||
|
["a\n", "b\n"], " a b\n", 0],
|
||||||
|
['bigfield2', "-1 $limits->{'SIZE_OFLOW'} -2 2",
|
||||||
["a\n", "b\n"], " a b\n", 0],
|
["a\n", "b\n"], " a b\n", 0],
|
||||||
|
|
||||||
# FIXME: change this to ensure the diagnostic makes sense
|
# FIXME: change this to ensure the diagnostic makes sense
|
||||||
|
@@ -24,6 +24,7 @@ if test "$VERBOSE" = yes; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
. $srcdir/test-lib.sh
|
. $srcdir/test-lib.sh
|
||||||
|
getlimits_
|
||||||
|
|
||||||
fail=0
|
fail=0
|
||||||
|
|
||||||
@@ -67,7 +68,8 @@ POSIXLY_CORRECT=1 \
|
|||||||
|
|
||||||
"$prog" '9 %*dx\n' -2 0 >>out || fail=1
|
"$prog" '9 %*dx\n' -2 0 >>out || fail=1
|
||||||
|
|
||||||
"$prog" '10 %.*dx\n' -2147483648 0 >>out || fail=1
|
"$prog" '10 %.*dx\n' $INT_UFLOW 0 >>out || fail=1
|
||||||
|
"$prog" '%.*dx\n' $INT_OFLOW 0 >>out 2> /dev/null && fail=1
|
||||||
|
|
||||||
"$prog" '11 %*c\n' 2 x >>out || fail=1
|
"$prog" '11 %*c\n' 2 x >>out || fail=1
|
||||||
|
|
||||||
|
@@ -24,6 +24,7 @@ if test "$VERBOSE" = yes; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
. $srcdir/test-lib.sh
|
. $srcdir/test-lib.sh
|
||||||
|
getlimits_
|
||||||
|
|
||||||
# Run this test only with glibc and sizeof (long double) > sizeof (double).
|
# Run this test only with glibc and sizeof (long double) > sizeof (double).
|
||||||
# Otherwise, there are known failures:
|
# Otherwise, there are known failures:
|
||||||
@@ -40,8 +41,8 @@ $CC -c long.c \
|
|||||||
|| skip_test_ \
|
|| skip_test_ \
|
||||||
'this test runs only on systems with glibc and long double != double'
|
'this test runs only on systems with glibc and long double != double'
|
||||||
|
|
||||||
a=9223372036854775807
|
a=$INTMAX_MAX
|
||||||
b=$(echo $a|sed 's/7$/8/')
|
b=$INTMAX_OFLOW
|
||||||
|
|
||||||
fail=0
|
fail=0
|
||||||
seq $a $b > out || fail=1
|
seq $a $b > out || fail=1
|
||||||
|
@@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
|
|
||||||
|
my $limits = getlimits ();
|
||||||
|
|
||||||
my $prog = 'sort';
|
my $prog = 'sort';
|
||||||
|
|
||||||
# Turn off localization of executable's output.
|
# Turn off localization of executable's output.
|
||||||
@@ -302,7 +304,10 @@ my @Tests =
|
|||||||
['nul-tab', "-k2,2 -t '\\0'",
|
['nul-tab', "-k2,2 -t '\\0'",
|
||||||
{IN=>"a\0z\01\nb\0y\02\n"}, {OUT=>"b\0y\02\na\0z\01\n"}],
|
{IN=>"a\0z\01\nb\0y\02\n"}, {OUT=>"b\0y\02\na\0z\01\n"}],
|
||||||
|
|
||||||
["bigfield", qw(-k 340282366920938463463374607431768211456),
|
# fields > SIZE_MAX are silently interpreted as SIZE_MAX
|
||||||
|
["bigfield1", "-k $limits->{'UINTMAX_OFLOW'}",
|
||||||
|
{IN=>"2\n1\n"}, {OUT=>"1\n2\n"}],
|
||||||
|
["bigfield2", "-k $limits->{'SIZE_OFLOW'}",
|
||||||
{IN=>"2\n1\n"}, {OUT=>"1\n2\n"}],
|
{IN=>"2\n1\n"}, {OUT=>"1\n2\n"}],
|
||||||
|
|
||||||
# Using an old-style key-specifying option like +1 with an invalid
|
# Using an old-style key-specifying option like +1 with an invalid
|
||||||
|
@@ -18,6 +18,8 @@
|
|||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
|
|
||||||
|
my $limits = getlimits ();
|
||||||
|
|
||||||
(my $program_name = $0) =~ s|.*/||;
|
(my $program_name = $0) =~ s|.*/||;
|
||||||
my $prog = 'sort';
|
my $prog = 'sort';
|
||||||
|
|
||||||
@@ -32,8 +34,7 @@ my $big_input = "aaa\n" x 1024;
|
|||||||
# don't need to check for existence, since we're running in a temp dir
|
# don't need to check for existence, since we're running in a temp dir
|
||||||
my $badtmp = 'does/not/exist';
|
my $badtmp = 'does/not/exist';
|
||||||
|
|
||||||
# 2^64+1
|
my $bigint = $limits->{'UINTMAX_OFLOW'};
|
||||||
my $bigint = "18446744073709551617";
|
|
||||||
|
|
||||||
my @Tests =
|
my @Tests =
|
||||||
(
|
(
|
||||||
|
@@ -22,6 +22,7 @@ if test "$VERBOSE" = yes; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
. $srcdir/test-lib.sh
|
. $srcdir/test-lib.sh
|
||||||
|
getlimits_
|
||||||
|
|
||||||
touch in || framework_failure
|
touch in || framework_failure
|
||||||
|
|
||||||
@@ -44,19 +45,9 @@ split -1 in 2> /dev/null || fail=1
|
|||||||
# Then make sure that -0 evokes a failure.
|
# Then make sure that -0 evokes a failure.
|
||||||
split -0 in 2> /dev/null && fail=1
|
split -0 in 2> /dev/null && fail=1
|
||||||
|
|
||||||
# Ensure that split --lines=N and --bytes=N work for N=2^32,
|
split --lines=$UINTMAX_MAX in || fail=1
|
||||||
# assuming our host supports integers that wide.
|
split --bytes=$UINTMAX_MAX in || fail=1
|
||||||
if _4gb=`expr 4294967296 + 0 2>/dev/null`; then
|
split --line-bytes=$SIZE_OFLOW 2> /dev/null in && fail=1
|
||||||
split --lines=$_4gb in || fail=1
|
|
||||||
split --bytes=$_4gb in || fail=1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Currently (coreutils-5.0.1) split --line-bytes=M fails
|
|
||||||
# with `invalid number of bytes' for M=2^32 or larger. Actually,
|
|
||||||
# the limit is SIZE_MAX, which is 2^32 on 32-bit systems.
|
|
||||||
# On 64-bit systems, there's no problem with a count of 2^32,
|
|
||||||
# So disable this test in order to avoid the `failure' on 64-bit systems.
|
|
||||||
#split --line-bytes=$_4gb 2> /dev/null in && fail=1
|
|
||||||
|
|
||||||
# Make sure that a huge obsolete option evokes the right failure.
|
# Make sure that a huge obsolete option evokes the right failure.
|
||||||
split -99999999999999999991 2> out && fail=1
|
split -99999999999999999991 2> out && fail=1
|
||||||
|
@@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
|
|
||||||
|
my $limits = getlimits ();
|
||||||
|
|
||||||
my $prog = 'test';
|
my $prog = 'test';
|
||||||
|
|
||||||
# Turn off localization of executable's output.
|
# Turn off localization of executable's output.
|
||||||
@@ -156,19 +158,19 @@ my @Tests =
|
|||||||
['eq-3', qw(0 -eq 00)],
|
['eq-3', qw(0 -eq 00)],
|
||||||
['eq-4', qw(8 -eq 9), {EXIT=>1}],
|
['eq-4', qw(8 -eq 9), {EXIT=>1}],
|
||||||
['eq-5', qw(1 -eq 0), {EXIT=>1}],
|
['eq-5', qw(1 -eq 0), {EXIT=>1}],
|
||||||
['eq-6', qw(340282366920938463463374607431768211456 -eq 0), {EXIT=>1}],
|
['eq-6', "$limits->{'UINTMAX_OFLOW'} -eq 0", {EXIT=>1}],
|
||||||
|
|
||||||
['gt-1', qw(5 -gt 5), {EXIT=>1}],
|
['gt-1', qw(5 -gt 5), {EXIT=>1}],
|
||||||
['gt-2', qw(5 -gt 4)],
|
['gt-2', qw(5 -gt 4)],
|
||||||
['gt-3', qw(4 -gt 5), {EXIT=>1}],
|
['gt-3', qw(4 -gt 5), {EXIT=>1}],
|
||||||
['gt-4', qw(-1 -gt -2)],
|
['gt-4', qw(-1 -gt -2)],
|
||||||
['gt-5', qw(18446744073709551616 -gt -18446744073709551616)],
|
['gt-5', "$limits->{'UINTMAX_OFLOW'} -gt $limits->{'INTMAX_UFLOW'}"],
|
||||||
|
|
||||||
['lt-1', qw(5 -lt 5), {EXIT=>1}],
|
['lt-1', qw(5 -lt 5), {EXIT=>1}],
|
||||||
['lt-2', qw(5 -lt 4), {EXIT=>1}],
|
['lt-2', qw(5 -lt 4), {EXIT=>1}],
|
||||||
['lt-3', qw(4 -lt 5)],
|
['lt-3', qw(4 -lt 5)],
|
||||||
['lt-4', qw(-1 -lt -2), {EXIT=>1}],
|
['lt-4', qw(-1 -lt -2), {EXIT=>1}],
|
||||||
['lt-5', qw(-18446744073709551616 -lt 18446744073709551616)],
|
['lt-5', "$limits->{'INTMAX_UFLOW'} -lt $limits->{'UINTMAX_OFLOW'}"],
|
||||||
|
|
||||||
['inv-1', qw(0x0 -eq 00), {EXIT=>2},
|
['inv-1', qw(0x0 -eq 00), {EXIT=>2},
|
||||||
{ERR=>"$prog: invalid integer `0x0'\n"}],
|
{ERR=>"$prog: invalid integer `0x0'\n"}],
|
||||||
|
@@ -22,6 +22,7 @@ if test "$VERBOSE" = yes; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
. $srcdir/test-lib.sh
|
. $srcdir/test-lib.sh
|
||||||
|
getlimits_
|
||||||
|
|
||||||
fail=0
|
fail=0
|
||||||
|
|
||||||
@@ -35,10 +36,10 @@ timeout invalid sleep 0 && fail=1
|
|||||||
timeout 42D sleep 0 && fail=1
|
timeout 42D sleep 0 && fail=1
|
||||||
|
|
||||||
# timeout overflow
|
# timeout overflow
|
||||||
timeout 4294967296 sleep 0 && fail=1
|
timeout $UINT_OFLOW sleep 0 && fail=1
|
||||||
|
|
||||||
# timeout overflow
|
# timeout overflow
|
||||||
timeout 49711d sleep 0 && fail=1
|
timeout $(expr $UINT_MAX / 86400 + 1)d sleep 0 && fail=1
|
||||||
|
|
||||||
# invalid signal spec
|
# invalid signal spec
|
||||||
timeout --signal=invalid 1 sleep 0 && fail=1
|
timeout --signal=invalid 1 sleep 0 && fail=1
|
||||||
|
@@ -22,6 +22,7 @@ if test "$VERBOSE" = yes; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
. $srcdir/test-lib.sh
|
. $srcdir/test-lib.sh
|
||||||
|
getlimits_
|
||||||
|
|
||||||
fail=0
|
fail=0
|
||||||
|
|
||||||
@@ -30,26 +31,14 @@ truncate -s-1 create-zero-len-file || fail=1
|
|||||||
|
|
||||||
echo > non-empty-file
|
echo > non-empty-file
|
||||||
|
|
||||||
truncate -s2147483648 -c no-such-file && _FILE_OFFSET_BITS=64
|
|
||||||
|
|
||||||
if [ $_FILE_OFFSET_BITS -eq 64 ]; then
|
|
||||||
# signed overflow
|
# signed overflow
|
||||||
truncate -s9223372036854775808 file && fail=1
|
truncate -s$OFF_T_OFLOW file && fail=1
|
||||||
|
|
||||||
# *= signed overflow
|
|
||||||
truncate --io-blocks --size="1E" file && fail=1
|
|
||||||
|
|
||||||
# += signed overflow
|
# += signed overflow
|
||||||
truncate -s+9223372036854775807 non-empty-file && fail=1
|
truncate -s+$OFF_T_MAX non-empty-file && fail=1
|
||||||
else
|
|
||||||
# signed overflow
|
|
||||||
truncate -s2147483648 file && fail=1
|
|
||||||
|
|
||||||
# *= signed overflow
|
# *= signed overflow
|
||||||
truncate --io-blocks --size="1G" file && fail=1
|
IO_BLOCK_OFLOW=$(expr $OFF_T_MAX / $(stat -f -c%s .) + 1)
|
||||||
|
truncate --io-blocks --size=$IO_BLOCK_OFLOW file && fail=1
|
||||||
# += signed overflow
|
|
||||||
truncate -s+2147483647 non-empty-file && fail=1
|
|
||||||
fi
|
|
||||||
|
|
||||||
Exit $fail
|
Exit $fail
|
||||||
|
@@ -18,6 +18,8 @@
|
|||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
|
|
||||||
|
my $limits = getlimits ();
|
||||||
|
|
||||||
(my $program_name = $0) =~ s|.*/||;
|
(my $program_name = $0) =~ s|.*/||;
|
||||||
|
|
||||||
# Turn off localization of executable's output.
|
# Turn off localization of executable's output.
|
||||||
@@ -76,7 +78,7 @@ my @Tests =
|
|||||||
|
|
||||||
# It is debatable whether this test should require an environment
|
# It is debatable whether this test should require an environment
|
||||||
# setting of e.g., _POSIX2_VERSION=1.
|
# setting of e.g., _POSIX2_VERSION=1.
|
||||||
['obs-ovflo', '-18446744073709551617', {IN=>''}, {OUT=>''},
|
['obs-ovflo', "-$limits->{'UINTMAX_OFLOW'}", {IN=>''}, {OUT=>''},
|
||||||
{EXIT => 1}, {ERR => "$prog: tab stop value is too large\n"}],
|
{EXIT => 1}, {ERR => "$prog: tab stop value is too large\n"}],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@@ -18,6 +18,8 @@
|
|||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
|
|
||||||
|
my $limits = getlimits ();
|
||||||
|
|
||||||
my $prog = 'uniq';
|
my $prog = 'uniq';
|
||||||
my $try = "Try \`$prog --help' for more information.\n";
|
my $try = "Try \`$prog --help' for more information.\n";
|
||||||
|
|
||||||
@@ -192,10 +194,11 @@ my @Tests =
|
|||||||
. $try}],
|
. $try}],
|
||||||
# Check that -d and -u suppress all output, as POSIX requires.
|
# Check that -d and -u suppress all output, as POSIX requires.
|
||||||
['120', qw(-d -u), {IN=>"a\na\n\b"}, {OUT=>""}],
|
['120', qw(-d -u), {IN=>"a\na\n\b"}, {OUT=>""}],
|
||||||
['121', qw(-d -u -w340282366920938463463374607431768211456), {IN=>"a\na\n\b"}, {OUT=>""}],
|
['121', "-d -u -w$limits->{'UINTMAX_OFLOW'}", {IN=>"a\na\n\b"}, {OUT=>""}],
|
||||||
|
['122', "-d -u -w$limits->{'SIZE_OFLOW'}", {IN=>"a\na\n\b"}, {OUT=>""}],
|
||||||
# Check that --zero-terminated is synonymous with -z.
|
# Check that --zero-terminated is synonymous with -z.
|
||||||
['122', '--zero-terminated', {IN=>"a\na\nb"}, {OUT=>"a\na\nb\0"}],
|
['123', '--zero-terminated', {IN=>"a\na\nb"}, {OUT=>"a\na\nb\0"}],
|
||||||
['123', '--zero-terminated', {IN=>"a\0a\0b"}, {OUT=>"a\0b\0"}],
|
['124', '--zero-terminated', {IN=>"a\0a\0b"}, {OUT=>"a\0b\0"}],
|
||||||
);
|
);
|
||||||
|
|
||||||
# Set _POSIX2_VERSION=199209 in the environment of each obs-plus* test.
|
# Set _POSIX2_VERSION=199209 in the environment of each obs-plus* test.
|
||||||
|
@@ -14,6 +14,13 @@ skip_test_()
|
|||||||
Exit 77
|
Exit 77
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getlimits_()
|
||||||
|
{
|
||||||
|
eval $(getlimits)
|
||||||
|
test "$INT_MAX" ||
|
||||||
|
error_ "Error running getlimits"
|
||||||
|
}
|
||||||
|
|
||||||
require_acl_()
|
require_acl_()
|
||||||
{
|
{
|
||||||
getfacl --version < /dev/null > /dev/null 2>&1 \
|
getfacl --version < /dev/null > /dev/null 2>&1 \
|
||||||
|
Reference in New Issue
Block a user