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

2009-01-02 Thread Pádraig Brady
Pádraig Brady wrote:
 New version attached with that fixed plus some tweaks of the commit log
 
 Thanks Bo!

OK I verified that all tests pass with this patch on both
32 bit and 64 bit x86 linux systems, so I'll push it soon
along with this trivial one:

From 1487d7b98b9c65722e4b3fa4a7ee0d17375d1dc4 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?P=C3=A1draig=20Brady?= p...@draigbrady.com
Date: Thu, 1 Jan 2009 01:44:57 +
Subject: [PATCH] src/.gitignore: Ignore getlimits utility

* src/.gitignore: Ignore getlimits
---
 src/.gitignore |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/src/.gitignore b/src/.gitignore
index ac91e1d..bc14523 100644
--- a/src/.gitignore
+++ b/src/.gitignore
@@ -31,6 +31,7 @@ false
 fmt
 fold
 fs.h
+getlimits
 ginstall
 groups
 head
-- 
1.5.3.6



___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


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

2008-12-12 Thread Pádraig Brady
I'd especially like a review of the perl bits
as my perl is _very_ weak.

cheers.
Pádraig.
From daaab330ebcd18ecc45b38270d315ae9e08c6ff9 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?P=C3=A1draig=20Brady?= p...@draigbrady.com
Date: Fri, 12 Dec 2008 10:25:34 +
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 and UINTMAX overflows
(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/sort-merge: Check for UINTMAX_OFLOW rather than
using arbitrary 2^64+1
* 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/unexpand: Check for UINTMAX_OFLOW rather than
using arbitrary 2^64+1
---
 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   |4 +++-
 tests/test-lib.sh |7 +++
 13 files changed, 63 insertions(+), 47 deletions(-)

diff --git a/tests/Coreutils.pm b/tests/Coreutils.pm
index bfb4f13..aceb401 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;
-...@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
 
diff --git a/tests/misc/join b/tests/misc/join
index 4c36c32..0f7889c 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 and 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..9d5330e 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

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

2008-12-12 Thread Bo Borgerson
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.

Please see the attached demonstration of this:

$ ./filehandles.pl
limits: 'foo'
caller: ''

$ ./filehandles.pl safe
limits: 'foo'
caller: 'bar'

Thanks,

Bo
#!/usr/bin/perl

my ($safe) = @ARGV;

system (echo -n foo  test_foo);
system (echo -n bar  test_bar);

sub getlimits {
  my $NV;

  # This clobbers caller's NV
  open NV, , test_foo or die Failed to open test_foo: $!;
  NV;
}

sub getlimits_safe {
  my $NV;

  # This uses subroutine-scoped $NV
  open $NV, , test_foo or die Failed to open test_foo: $!;
  $NV;
}

open NV, , test_bar or die Failed to open test_bar: $!;

my $limits = $safe ? getlimits_safe : getlimits;
my $caller = NV;

print limits: '$limits'\n;
print caller: '$caller'\n;
___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


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

2008-12-12 Thread Pádraig Brady
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?= p...@draigbrady.com
Date: Fri, 12 Dec 2008 10:25:34 +
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;
-...@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
 
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