From 99be9078383e7fc95bf84b42ea6a0e50afbe6ff4 Mon Sep 17 00:00:00 2001 From: Pádraig Brady Date: Fri, 12 Dec 2008 10:25:34 +0000 Subject: 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 --- tests/misc/join | 7 ++++++- tests/misc/printf | 4 +++- tests/misc/seq-long-double | 5 +++-- tests/misc/sort | 7 ++++++- tests/misc/sort-merge | 5 +++-- tests/misc/split-fail | 17 ++++------------- tests/misc/test | 8 +++++--- tests/misc/timeout-parameters | 5 +++-- tests/misc/truncate-overflow | 27 ++++++++------------------- tests/misc/unexpand | 4 +++- tests/misc/uniq | 9 ++++++--- 11 files changed, 50 insertions(+), 48 deletions(-) (limited to 'tests/misc') diff --git a/tests/misc/join b/tests/misc/join index 4c36c32a5..2d9db78f4 100755 --- a/tests/misc/join +++ b/tests/misc/join @@ -18,6 +18,8 @@ use strict; +my $limits = getlimits (); + # Turn off localization of executable's output. @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: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], # FIXME: change this to ensure the diagnostic makes sense diff --git a/tests/misc/printf b/tests/misc/printf index 1cc440e2e..bf2b49f86 100755 --- a/tests/misc/printf +++ b/tests/misc/printf @@ -24,6 +24,7 @@ if test "$VERBOSE" = yes; then fi . $srcdir/test-lib.sh +getlimits_ fail=0 @@ -67,7 +68,8 @@ POSIXLY_CORRECT=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 diff --git a/tests/misc/seq-long-double b/tests/misc/seq-long-double index 6b86ae301..fb1566873 100755 --- a/tests/misc/seq-long-double +++ b/tests/misc/seq-long-double @@ -24,6 +24,7 @@ if test "$VERBOSE" = yes; then fi . $srcdir/test-lib.sh +getlimits_ # Run this test only with glibc and sizeof (long double) > sizeof (double). # Otherwise, there are known failures: @@ -40,8 +41,8 @@ $CC -c long.c \ || skip_test_ \ 'this test runs only on systems with glibc and long double != double' -a=9223372036854775807 -b=$(echo $a|sed 's/7$/8/') +a=$INTMAX_MAX +b=$INTMAX_OFLOW fail=0 seq $a $b > out || fail=1 diff --git a/tests/misc/sort b/tests/misc/sort index f26bc5fbc..3e8eda6ae 100755 --- a/tests/misc/sort +++ b/tests/misc/sort @@ -17,6 +17,8 @@ use strict; +my $limits = getlimits (); + my $prog = 'sort'; # Turn off localization of executable's output. @@ -302,7 +304,10 @@ my @Tests = ['nul-tab', "-k2,2 -t '\\0'", {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"}], # Using an old-style key-specifying option like +1 with an invalid diff --git a/tests/misc/sort-merge b/tests/misc/sort-merge index 6b8192610..e360d1c8b 100755 --- a/tests/misc/sort-merge +++ b/tests/misc/sort-merge @@ -18,6 +18,8 @@ use strict; +my $limits = getlimits (); + (my $program_name = $0) =~ s|.*/||; 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 my $badtmp = 'does/not/exist'; -# 2^64+1 -my $bigint = "18446744073709551617"; +my $bigint = $limits->{'UINTMAX_OFLOW'}; my @Tests = ( diff --git a/tests/misc/split-fail b/tests/misc/split-fail index 0680891b6..7e56a257a 100755 --- a/tests/misc/split-fail +++ b/tests/misc/split-fail @@ -22,6 +22,7 @@ if test "$VERBOSE" = yes; then fi . $srcdir/test-lib.sh +getlimits_ touch in || framework_failure @@ -44,19 +45,9 @@ split -1 in 2> /dev/null || fail=1 # Then make sure that -0 evokes a failure. split -0 in 2> /dev/null && fail=1 -# Ensure that split --lines=N and --bytes=N work for N=2^32, -# assuming our host supports integers that wide. -if _4gb=`expr 4294967296 + 0 2>/dev/null`; then - 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 +split --lines=$UINTMAX_MAX in || fail=1 +split --bytes=$UINTMAX_MAX in || fail=1 +split --line-bytes=$SIZE_OFLOW 2> /dev/null in && fail=1 # Make sure that a huge obsolete option evokes the right failure. split -99999999999999999991 2> out && fail=1 diff --git a/tests/misc/test b/tests/misc/test index 43db2e1a5..ec34f1dd9 100755 --- a/tests/misc/test +++ b/tests/misc/test @@ -17,6 +17,8 @@ use strict; +my $limits = getlimits (); + my $prog = 'test'; # Turn off localization of executable's output. @@ -156,19 +158,19 @@ my @Tests = ['eq-3', qw(0 -eq 00)], ['eq-4', qw(8 -eq 9), {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-2', qw(5 -gt 4)], ['gt-3', qw(4 -gt 5), {EXIT=>1}], ['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-2', qw(5 -lt 4), {EXIT=>1}], ['lt-3', qw(4 -lt 5)], ['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}, {ERR=>"$prog: invalid integer `0x0'\n"}], diff --git a/tests/misc/timeout-parameters b/tests/misc/timeout-parameters index 27d6b570a..fa701d270 100755 --- a/tests/misc/timeout-parameters +++ b/tests/misc/timeout-parameters @@ -22,6 +22,7 @@ if test "$VERBOSE" = yes; then fi . $srcdir/test-lib.sh +getlimits_ fail=0 @@ -35,10 +36,10 @@ timeout invalid sleep 0 && fail=1 timeout 42D sleep 0 && fail=1 # timeout overflow -timeout 4294967296 sleep 0 && fail=1 +timeout $UINT_OFLOW sleep 0 && fail=1 # timeout overflow -timeout 49711d sleep 0 && fail=1 +timeout $(expr $UINT_MAX / 86400 + 1)d sleep 0 && fail=1 # invalid signal spec timeout --signal=invalid 1 sleep 0 && fail=1 diff --git a/tests/misc/truncate-overflow b/tests/misc/truncate-overflow index b903244e6..3f486c58d 100755 --- a/tests/misc/truncate-overflow +++ b/tests/misc/truncate-overflow @@ -22,6 +22,7 @@ if test "$VERBOSE" = yes; then fi . $srcdir/test-lib.sh +getlimits_ fail=0 @@ -30,26 +31,14 @@ truncate -s-1 create-zero-len-file || fail=1 echo > non-empty-file -truncate -s2147483648 -c no-such-file && _FILE_OFFSET_BITS=64 +# signed overflow +truncate -s$OFF_T_OFLOW file && fail=1 -if [ $_FILE_OFFSET_BITS -eq 64 ]; then - # signed overflow - truncate -s9223372036854775808 file && fail=1 +# += signed overflow +truncate -s+$OFF_T_MAX non-empty-file && fail=1 - # *= signed overflow - truncate --io-blocks --size="1E" file && fail=1 - - # += signed overflow - truncate -s+9223372036854775807 non-empty-file && fail=1 -else - # signed overflow - truncate -s2147483648 file && fail=1 - - # *= signed overflow - truncate --io-blocks --size="1G" file && fail=1 - - # += signed overflow - truncate -s+2147483647 non-empty-file && fail=1 -fi +# *= signed overflow +IO_BLOCK_OFLOW=$(expr $OFF_T_MAX / $(stat -f -c%s .) + 1) +truncate --io-blocks --size=$IO_BLOCK_OFLOW file && fail=1 Exit $fail diff --git a/tests/misc/unexpand b/tests/misc/unexpand index 3e3a3d17c..554d18cf5 100755 --- a/tests/misc/unexpand +++ b/tests/misc/unexpand @@ -18,6 +18,8 @@ use strict; +my $limits = getlimits (); + (my $program_name = $0) =~ s|.*/||; # Turn off localization of executable's output. @@ -76,7 +78,7 @@ my @Tests = # It is debatable whether this test should require an environment # 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"}], ); diff --git a/tests/misc/uniq b/tests/misc/uniq index 0350864c0..a7717448f 100755 --- a/tests/misc/uniq +++ b/tests/misc/uniq @@ -18,6 +18,8 @@ use strict; +my $limits = getlimits (); + my $prog = 'uniq'; my $try = "Try \`$prog --help' for more information.\n"; @@ -192,10 +194,11 @@ my @Tests = . $try}], # Check that -d and -u suppress all output, as POSIX requires. ['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. - ['122', '--zero-terminated', {IN=>"a\na\nb"}, {OUT=>"a\na\nb\0"}], - ['123', '--zero-terminated', {IN=>"a\0a\0b"}, {OUT=>"a\0b\0"}], + ['123', '--zero-terminated', {IN=>"a\na\nb"}, {OUT=>"a\na\nb\0"}], + ['124', '--zero-terminated', {IN=>"a\0a\0b"}, {OUT=>"a\0b\0"}], ); # Set _POSIX2_VERSION=199209 in the environment of each obs-plus* test. -- cgit v1.2.3-54-g00ecf