]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: refactor to use the new getlimits utility
authorPádraig Brady <P@draigBrady.com>
Fri, 12 Dec 2008 10:25:34 +0000 (10:25 +0000)
committerPádraig Brady <P@draigBrady.com>
Sat, 3 Jan 2009 15:10:42 +0000 (15:10 +0000)
* 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

13 files changed:
tests/Coreutils.pm
tests/misc/join
tests/misc/printf
tests/misc/seq-long-double
tests/misc/sort
tests/misc/sort-merge
tests/misc/split-fail
tests/misc/test
tests/misc/timeout-parameters
tests/misc/truncate-overflow
tests/misc/unexpand
tests/misc/uniq
tests/test-lib.sh

index bfb4f130e678d7446987c751f85dee106e5a0fc2..ec4120fddcec2711ff8f45167baf3f83aae3340d 100644 (file)
@@ -24,7 +24,7 @@ use File::Compare qw(compare);
 
 @ISA = qw(Exporter);
 ($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};
 
@@ -204,6 +204,14 @@ sub _at_replace ($$)
   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: extract `do_1_test' function
 
index 4c36c32a52f9a9396b33da2483eaa163bcc072fe..2d9db78f44a85fd3edf8eef96d2d21c0084c5b3e 100755 (executable)
@@ -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
index 1cc440e2e0ea0a998f82da56845bf7ae14cb4cba..bf2b49f8695771874efbb0977b669e4117291154 100755 (executable)
@@ -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
 
index 6b86ae301b3cd2814fae4dfb1f6586757c4ef20e..fb1566873aee7b45341e185c0e8bbb1a7259fb1e 100755 (executable)
@@ -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
index f26bc5fbcb077bcbcbd9f1ebdcae0b29c2ebb9cc..3e8eda6ae57c2f93e4881c977bed4145eb20a6aa 100755 (executable)
@@ -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
index 6b8192610454166e8e2a4d5b22eb9284de360c15..e360d1c8b97ec5c797689eaff83f6938136bd046 100755 (executable)
@@ -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 =
     (
index 0680891b64503d4826b1082b7feee8ca143ebefb..7e56a257aab5cd1125013d313fa74cab98b7043d 100755 (executable)
@@ -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
index 43db2e1a55cb5f9cd050c1761d505cb201153392..ec34f1dd9aa7e3de0b887d59d42f246c4aa97f7e 100755 (executable)
@@ -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"}],
index 27d6b570a9558cbaecb5491935547bffbf95d3a9..fa701d2707b1a3427fa16696d57c543377cf6806 100755 (executable)
@@ -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
index b903244e6209b9ba92b0b8b9472d9782e1ec3b89..3f486c58da196b5dae963cc3364e3308b84855d2 100755 (executable)
@@ -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
index 3e3a3d17c6af31d136196f57309c887d43d21118..554d18cf5e054beae2e721a6a223ca071d308f16 100755 (executable)
@@ -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"}],
     );
 
index 0350864c0bd4df14926b5b47fd77fd517d5ca094..a7717448fcbb3285339f09755655261de4a24413 100755 (executable)
@@ -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.
index ceb4eb673a4ed27eda17b6cf13f1a22812233cc9..8bb88d9745f413cf3820840a7f58bb6c02bd23c9 100644 (file)
@@ -14,6 +14,13 @@ skip_test_()
   Exit 77
 }
 
+getlimits_()
+{
+    eval $(getlimits)
+    test "$INT_MAX" ||
+    error_ "Error running getlimits"
+}
+
 require_acl_()
 {
   getfacl --version < /dev/null > /dev/null 2>&1 \