diff --git a/ChangeLog b/ChangeLog index 1aeaaf0..b336137 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,10 @@ -2011-01-07 Bruce Korb +2011-01-10 Bruce Korb - tests: exercise malloc a tiny bit before setting the rlimit. - * tests/test-dprintf-posix2.c: the test occasionally fails on Linux - if setrlimit is called before any malloc call. - * tests/test-fprintf-posix3.c: likewise + tests: try one test before deciding that the testing works + * tests/test-dprintf-posix2.c: make sure one dprintf() will work + * tests/test-fprintf-posix3.c: make sure one fprintf() will work + * tests/test-dprintf-posix2.sh: redirect usability test stdout + * tests/test-fprintf-posix3.sh: likewise 2011-01-07 Pádraig Brady diff --git a/tests/test-dprintf-posix2.c b/tests/test-dprintf-posix2.c index 60e898d..a3b1c02 100644 --- a/tests/test-dprintf-posix2.c +++ b/tests/test-dprintf-posix2.c @@ -64,7 +64,6 @@ main (int argc, char *argv[]) #endif /* On Linux systems, malloc() is limited by RLIMIT_AS. */ #ifdef RLIMIT_AS - free (malloc (0x88)); if (getrlimit (RLIMIT_AS, &limit) < 0) return 77; if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > MAX_ALLOC_TOTAL) @@ -77,7 +76,19 @@ main (int argc, char *argv[]) arg = atoi (argv[1]); if (arg == 0) { - void *memory = malloc (MAX_ALLOC_TOTAL); + void *memory; + + /* This "dprintf" can draw in a number of libraries triggering many + changes in the address space. There is no trivial way to fiddle + with getrlimit/setrlimit or even to examine /proc/$PID/maps and + figure out how much of the RLIMIT_AS space we are using *or are + about to use*. So, make the assumption that this dprintf call + must work on the first call or we cannot do this test. */ + if (dprintf (STDOUT_FILENO, "%011000d\n", 17) == -1 + && errno == ENOMEM) + return 78; + + memory = malloc (MAX_ALLOC_TOTAL); if (memory == NULL) return 1; memset (memory, 17, MAX_ALLOC_TOTAL); diff --git a/tests/test-dprintf-posix2.sh b/tests/test-dprintf-posix2.sh index f1aeacc..45174d4 100755 --- a/tests/test-dprintf-posix2.sh +++ b/tests/test-dprintf-posix2.sh @@ -2,7 +2,7 @@ # Test against a memory leak. -(./test-dprintf-posix2${EXEEXT} 0 +(./test-dprintf-posix2${EXEEXT} 0 > /dev/null result=$? if test $result != 77 && test $result != 78; then result=1; fi exit $result diff --git a/tests/test-fprintf-posix3.c b/tests/test-fprintf-posix3.c index 646df1b..c73bd5e 100644 --- a/tests/test-fprintf-posix3.c +++ b/tests/test-fprintf-posix3.c @@ -63,7 +63,6 @@ main (int argc, char *argv[]) #endif /* On Linux systems, malloc() is limited by RLIMIT_AS. */ #ifdef RLIMIT_AS - free (malloc (0x88)); if (getrlimit (RLIMIT_AS, &limit) < 0) return 77; if (limit.rlim_max == RLIM_INFINITY || limit.rlim_max > MAX_ALLOC_TOTAL) @@ -76,7 +75,19 @@ main (int argc, char *argv[]) arg = atoi (argv[1]); if (arg == 0) { - void *memory = malloc (MAX_ALLOC_TOTAL); + void *memory; + + /* This "fprintf" can draw in a number of libraries triggering many + changes in the address space. There is no trivial way to fiddle + with getrlimit/setrlimit or even to examine /proc/$PID/maps and + figure out how much of the RLIMIT_AS space we are using *or are + about to use*. So, make the assumption that this dprintf call + must work on the first call or we cannot do this test. */ + if (fprintf (stdout, "%011000d\n", 17) == -1 + && errno == ENOMEM) + return 78; + + memory = malloc (MAX_ALLOC_TOTAL); if (memory == NULL) return 1; memset (memory, 17, MAX_ALLOC_TOTAL); diff --git a/tests/test-fprintf-posix3.sh b/tests/test-fprintf-posix3.sh index 6a6976d..56a9c22 100755 --- a/tests/test-fprintf-posix3.sh +++ b/tests/test-fprintf-posix3.sh @@ -2,7 +2,7 @@ # Test against a memory leak. -(./test-fprintf-posix3${EXEEXT} 0 +(./test-fprintf-posix3${EXEEXT} 0 > /dev/null result=$? if test $result != 77 && test $result != 78; then result=1; fi exit $result