bug-gnulib
[Top][All Lists]
Advanced

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

Re: xalloc-die-tests


From: Eric Blake
Subject: Re: xalloc-die-tests
Date: Mon, 16 Nov 2009 21:31:42 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Simon Josefsson on 11/15/2009 9:20 AM:
> Pushed.
> 
> /Simon
> 
>>From a31c6b23b94970756cf070ab279bb6e5e6af0156 Mon Sep 17 00:00:00 2001
> From: Simon Josefsson <address@hidden>
> Date: Sun, 15 Nov 2009 17:20:06 +0100
> Subject: [PATCH] Add xalloc-die self-test.
> 

That failed to link when run in isolation (./gnulib-tool --with-tests
- --test xalloc-die).  Plus it leaked a message to stderr, which in turn
showed that we were depending on unportable printf("%s",NULL) behavior.
This cleans it up.

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAksCJy4ACgkQ84KuGfSFAYCELACfeIT5IKfA5oSFkDam9qfKojxF
95MAn22FQgvaogbiH39KHfaOHsdokxAZ
=k4Fs
-----END PGP SIGNATURE-----
>From 6fb9bcb192e812bbf27fe1eebc6e24f458028893 Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Mon, 16 Nov 2009 21:21:10 -0700
Subject: [PATCH] xalloc-die-tests: avoid printing null pointer

The test leaked "(null): memory exhausted" to stderr, or crashed
for less capable printf.

* modules/xalloc-die-tests (Files, Makefile.am): Wrap execution in
shell script.
* tests/test-xalloc-die.c (program_name): Declare.
* tests/test-xalloc-die.sh (tmpfiles): New file.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog                |    6 ++++++
 modules/xalloc-die-tests |    4 +++-
 tests/test-xalloc-die.c  |    2 ++
 tests/test-xalloc-die.sh |   28 ++++++++++++++++++++++++++++
 4 files changed, 39 insertions(+), 1 deletions(-)
 create mode 100755 tests/test-xalloc-die.sh

diff --git a/ChangeLog b/ChangeLog
index 05f70b7..269ca37 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2009-11-16  Eric Blake  <address@hidden>

+       xalloc-die-tests: avoid printing null pointer
+       * modules/xalloc-die-tests (Files, Makefile.am): Wrap execution in
+       shell script.
+       * tests/test-xalloc-die.c (program_name): Declare.
+       * tests/test-xalloc-die.sh (tmpfiles): New file.
+
        stdlib-safer: preserve cloexec flag for mkostemp[s]
        * lib/mkstemp-safer.c (mkostemp_safer, mkostemps_safer): Use new
        fd_safer_flag.
diff --git a/modules/xalloc-die-tests b/modules/xalloc-die-tests
index 03ee303..97b25e7 100644
--- a/modules/xalloc-die-tests
+++ b/modules/xalloc-die-tests
@@ -1,9 +1,11 @@
 Files:
 tests/test-xalloc-die.c
+tests/test-xalloc-die.sh

 Depends-on:

 Makefile.am:
-TESTS += test-xalloc-die
+TESTS += test-xalloc-die.sh
+TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@'
 XFAIL_TESTS += test-xalloc-die
 check_PROGRAMS += test-xalloc-die
diff --git a/tests/test-xalloc-die.c b/tests/test-xalloc-die.c
index e281767..88461e8 100644
--- a/tests/test-xalloc-die.c
+++ b/tests/test-xalloc-die.c
@@ -20,6 +20,8 @@

 #include "xalloc.h"

+char *program_name = "test-xalloc-die";
+
 int
 main (void)
 {
diff --git a/tests/test-xalloc-die.sh b/tests/test-xalloc-die.sh
new file mode 100755
index 0000000..340a500
--- /dev/null
+++ b/tests/test-xalloc-die.sh
@@ -0,0 +1,28 @@
+#!/bin/sh
+
+tmpfiles=""
+trap '__st=$?; rm -fr $tmpfiles; exit $__st' 0
+trap '__st=$?; (exit $__st); exit $__st' 1 2 3 15
+
+if ( diff --version < /dev/null 2>&1 | grep GNU ) 2>&1 > /dev/null; then
+  compare() { diff -u "$@"; }
+elif ( cmp --version < /dev/null 2>&1 | grep GNU ) 2>&1 > /dev/null; then
+  compare() { cmp -s "$@"; }
+else
+  compare() { cmp "$@"; }
+fi
+
+tmpfiles="t-xalloc-die.tmp"
+./test-xalloc-die${EXEEXT} 2> t-xalloc-die.tmp
+case $? in
+  1) ;;
+  *) (exit 1); exit 1 ;;
+esac
+
+compare - t-xalloc-die.tmp <<\EOF || { (exit 1); exit 1; }
+test-xalloc-die: memory exhausted
+EOF
+
+rm -fr $tmpfiles
+
+exit 0
-- 
1.6.5.rc1


reply via email to

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