As was ultimately figured out, unused libraries consume address
space and are not dumped into the core image. "gdb info target"
doesn't yield very friendly information about the issue, either.
You have to suspend GDB and go have a peek at /proc/$PID/maps
and do some hex arithmetic. This patch does a few things:
1. It increases the number of iterations of the test-fprintf-posix3
and test-dprintf-posix2 to 1,500 so that 15MB of address space
is allowed. This is big enough for the additional libposix space
needs on a Linux x86-64 box.
2. It adds another test when the test program's argument is "0".
Mainly, it has to work for one iteration of the test. If it
does not, then this command is run:
echo "Testing error: designated memory size is too small"
3. The tests take micro seconds longer, due to the extra iterations.
>From fabf6211ffe37ca7602112651ed48fb9f62d4959 Mon Sep 17 00:00:00 2001
From: Bruce Korb <[email protected]>
Date: Fri, 14 Jan 2011 14:28:29 -0800
Subject: [PATCH] tests: large libraries may foil setrlimit + printf testing
---
ChangeLog | 9 +++++++++
tests/test-dprintf-posix2.c | 15 ++++++++++++---
tests/test-dprintf-posix2.sh | 12 +++++++++---
tests/test-fprintf-posix3.c | 16 +++++++++++++---
tests/test-fprintf-posix3.sh | 12 +++++++++---
5 files changed, 52 insertions(+), 12 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index d68bd77..cfb143c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2011-01-14 Bruce Korb <[email protected]>
+
+ tests: large libraries may foil setrlimit + printf testing
+ * tests/test-dprintf-posix2.c: bump NUM_ROUNDS to 1500 for
+ libposix and return 79 if one instance of the test fails.
+ * tests/test-fprintf-posix3.c: likewise
+ * tests/test-dprintf-posix2.sh: test for exit code 79
+ * tests/test-fprintf-posix3.sh: likewise
+
2011-01-14 Bruno Haible <[email protected]>
filemode: Make function declarations usable in C++ mode.
diff --git a/tests/test-dprintf-posix2.c b/tests/test-dprintf-posix2.c
index 9fd869a..fd21a2c 100644
--- a/tests/test-dprintf-posix2.c
+++ b/tests/test-dprintf-posix2.c
@@ -33,11 +33,14 @@
/* Test against a memory leak in the fprintf replacement. */
/* Number of iterations across the loop. */
-#define NUM_ROUNDS 1000
+#define NUM_ROUNDS 1500
/* Number of bytes that are allowed to escape per round. */
#define MAX_ALLOC_ROUND 10000
+/* formatting string -- width is 110% of "MAX_ALLOC_ROUND" */
+static char const fmt[] = "%011000d\n";
+
/* Number of bytes that are allowed to escape in total.
This should be at least 10 MB, since it includes the normal memory
or address space of the test program. */
@@ -76,7 +79,13 @@ main (int argc, char *argv[])
arg = atoi (argv[1]);
if (arg == 0)
{
- void *memory = malloc (MAX_ALLOC_TOTAL);
+ void *memory;
+ /* If this fails on the first go-around, then either raise the
+ "NUM_ROUNDS" or raise "MAX_ALLOC_ROUND". */
+ if (dprintf (STDOUT_FILENO, fmt, 17) == -1
+ && errno == ENOMEM)
+ return 79;
+ memory = malloc (MAX_ALLOC_TOTAL);
if (memory == NULL)
return 1;
memset (memory, 17, MAX_ALLOC_TOTAL);
@@ -90,7 +99,7 @@ main (int argc, char *argv[])
{
/* This may produce a temporary memory allocation of 11000 bytes.
but should not result in a permanent memory allocation. */
- if (dprintf (STDOUT_FILENO, "%011000d\n", 17) == -1
+ if (dprintf (STDOUT_FILENO, fmt, 17) == -1
&& errno == ENOMEM)
return 1;
}
diff --git a/tests/test-dprintf-posix2.sh b/tests/test-dprintf-posix2.sh
index f1aeacc..211c6d1 100755
--- a/tests/test-dprintf-posix2.sh
+++ b/tests/test-dprintf-posix2.sh
@@ -6,12 +6,18 @@
result=$?
if test $result != 77 && test $result != 78; then result=1; fi
exit $result
-) 2>/dev/null
+) 2>/dev/null 1>&2
malloc_result=$?
-if test $malloc_result = 77; then
+
+case $malloc_result in
+77 )
echo "Skipping test: getrlimit and setrlimit don't work"
exit 77
-fi
+ ;;
+79 )
+ echo "Testing error: designated memory size is too small"
+ exit 1
+esac
./test-dprintf-posix2${EXEEXT} 1 > /dev/null
result=$?
diff --git a/tests/test-fprintf-posix3.c b/tests/test-fprintf-posix3.c
index 90a2f7c..2af21aa 100644
--- a/tests/test-fprintf-posix3.c
+++ b/tests/test-fprintf-posix3.c
@@ -32,16 +32,20 @@
/* Test against a memory leak in the fprintf replacement. */
/* Number of iterations across the loop. */
-#define NUM_ROUNDS 1000
+#define NUM_ROUNDS 1500
/* Number of bytes that are allowed to escape per round. */
#define MAX_ALLOC_ROUND 10000
+/* formatting string -- width is 110% of "MAX_ALLOC_ROUND" */
+static char const fmt[] = "%011000d\n";
+
/* Number of bytes that are allowed to escape in total.
This should be at least 10 MB, since it includes the normal memory
or address space of the test program. */
#define MAX_ALLOC_TOTAL (NUM_ROUNDS * MAX_ALLOC_ROUND)
+
int
main (int argc, char *argv[])
{
@@ -75,7 +79,13 @@ main (int argc, char *argv[])
arg = atoi (argv[1]);
if (arg == 0)
{
- void *memory = malloc (MAX_ALLOC_TOTAL);
+ void *memory;
+ /* If this fails on the first go-around, then either raise the
+ "NUM_ROUNDS" or raise "MAX_ALLOC_ROUND". */
+ if (fprintf (stdout, fmt, 17) == -1
+ && errno == ENOMEM)
+ return 79;
+ memory = malloc (MAX_ALLOC_TOTAL);
if (memory == NULL)
return 1;
memset (memory, 17, MAX_ALLOC_TOTAL);
@@ -89,7 +99,7 @@ main (int argc, char *argv[])
{
/* This may produce a temporary memory allocation of 11000 bytes.
but should not result in a permanent memory allocation. */
- if (fprintf (stdout, "%011000d\n", 17) == -1
+ if (fprintf (stdout, fmt, 17) == -1
&& errno == ENOMEM)
return 1;
}
diff --git a/tests/test-fprintf-posix3.sh b/tests/test-fprintf-posix3.sh
index 6a6976d..1929f95 100755
--- a/tests/test-fprintf-posix3.sh
+++ b/tests/test-fprintf-posix3.sh
@@ -6,12 +6,18 @@
result=$?
if test $result != 77 && test $result != 78; then result=1; fi
exit $result
-) 2>/dev/null
+) 2>/dev/null 1>&2
malloc_result=$?
-if test $malloc_result = 77; then
+
+case $malloc_result in
+77 )
echo "Skipping test: getrlimit and setrlimit don't work"
exit 77
-fi
+ ;;
+79 )
+ echo "Testing error: designated memory size is too small"
+ exit 1
+esac
./test-fprintf-posix3${EXEEXT} 1 > /dev/null
result=$?
--
1.7.1