bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] tests: refactor to use the new getlimits utility


From: Pádraig Brady
Subject: Re: [PATCH] tests: refactor to use the new getlimits utility
Date: Fri, 12 Dec 2008 17:14:15 +0000
User-agent: Thunderbird 2.0.0.6 (X11/20071008)

Bo Borgerson wrote:
> Pádraig Brady wrote:
>> I'd especially like a review of the perl bits
> 
> 
> Hi Pádraig,
> 
> I'm not sure that this function will behave quite as you intended it to:
> 
> +sub getlimits()
> +{
> +  my $NV;
> +  open NV, "getlimits |" or die "Error running getlimits\n";
> +  my %limits = map {split /=|\n/} <NV>;
> +  return \%limits;
> +}
> +
> 
> I think that filehandle is opened using a broader scope than you might
> be expecting.  It's not using your subroutine-scoped lexical $NV, but
> rather a package-scoped "NV" symbol.  If you open $NV and read using
> <$NV> it will use your subroutine-scoped lexical variable, as I think
> you intended.

New version attached with that fixed plus some tweaks of the commit log

Thanks Bo!

Pádraig.
>From 1d14587a68e20e6c45d59e48c0b0db43865b8656 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?P=C3=A1draig=20Brady?= <address@hidden>
Date: Fri, 12 Dec 2008 10:25:34 +0000
Subject: [PATCH] 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
(in case they're different), rather than using arbitrary 2^128
* tests/misc/sort: ditto
* tests/misc/uniq: ditto
* tests/misc/printf: Check both INT_[OU]FLOW rather than
a single test for 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 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/Coreutils.pm            |   10 +++++++++-
 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 ++++++---
 tests/test-lib.sh             |    7 +++++++
 13 files changed, 66 insertions(+), 49 deletions(-)

diff --git a/tests/Coreutils.pm b/tests/Coreutils.pm
index bfb4f13..ec4120f 100644
--- a/tests/Coreutils.pm
+++ b/tests/Coreutils.pm
@@ -24,7 +24,7 @@ use File::Compare qw(compare);
 
 @ISA = qw(Exporter);
 ($VERSION = '$Revision: 1.5 $ ') =~ tr/[0-9].//cd;
address@hidden = qw (run_tests triple_test);
address@hidden = 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
 
diff --git a/tests/misc/join b/tests/misc/join
index 4c36c32..2d9db78 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 1cc440e..bf2b49f 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 6b86ae3..fb15668 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 f26bc5f..3e8eda6 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 6b81926..e360d1c 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 0680891..7e56a25 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 43db2e1..ec34f1d 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 27d6b57..fa701d2 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 b903244..3f486c5 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 3e3a3d1..554d18c 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 0350864..a771744 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.
diff --git a/tests/test-lib.sh b/tests/test-lib.sh
index ceb4eb6..8bb88d9 100644
--- a/tests/test-lib.sh
+++ b/tests/test-lib.sh
@@ -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 \
-- 
1.5.3.6


reply via email to

[Prev in Thread] Current Thread [Next in Thread]