>From f015bed9d6ad2fde5f0f86e941e8094e3eb14d37 Mon Sep 17 00:00:00 2001 From: Bruce Korb Date: Thu, 11 Nov 2010 08:37:06 -0800 Subject: [PATCH 1/3] exit "test fails" if the first "%011000d\n" formatting fails --- tests/test-dprintf-posix2.c | 20 ++++++++++---------- tests/test-dprintf-posix2.sh | 38 ++++++++++++++------------------------ tests/test-fprintf-posix3.c | 20 ++++++++++---------- tests/test-fprintf-posix3.sh | 38 ++++++++++++++------------------------ 4 files changed, 48 insertions(+), 68 deletions(-) diff --git a/tests/test-dprintf-posix2.c b/tests/test-dprintf-posix2.c index fd54070..bc5a9c5 100644 --- a/tests/test-dprintf-posix2.c +++ b/tests/test-dprintf-posix2.c @@ -73,15 +73,15 @@ main (int argc, char *argv[]) return 77; #endif - arg = atoi (argv[1]); - if (arg == 0) - { - void *memory = malloc (MAX_ALLOC_TOTAL); - if (memory == NULL) - return 1; - memset (memory, 17, MAX_ALLOC_TOTAL); - return 78; - } + { + void *memory = malloc (MAX_ALLOC_TOTAL); + if (memory != NULL) + { + /* seg fault if the memory is not really there */ + memset (memory, 17, MAX_ALLOC_TOTAL); + return 78; + } + } /* Perform the test and test whether it triggers a permanent memory allocation of more than MAX_ALLOC_TOTAL bytes. */ @@ -92,7 +92,7 @@ main (int argc, char *argv[]) but should not result in a permanent memory allocation. */ if (dprintf (STDOUT_FILENO, "%011000d\n", 17) == -1 && errno == ENOMEM) - return 1; + return (repeat == 0) ? 79 : 1; } return 0; diff --git a/tests/test-dprintf-posix2.sh b/tests/test-dprintf-posix2.sh index f1aeacc..fc1bfad 100755 --- a/tests/test-dprintf-posix2.sh +++ b/tests/test-dprintf-posix2.sh @@ -2,30 +2,20 @@ # Test against a memory leak. -(./test-dprintf-posix2${EXEEXT} 0 - result=$? - if test $result != 77 && test $result != 78; then result=1; fi - exit $result -) 2>/dev/null -malloc_result=$? -if test $malloc_result = 77; then - echo "Skipping test: getrlimit and setrlimit don't work" - exit 77 -fi - -./test-dprintf-posix2${EXEEXT} 1 > /dev/null +./test-dprintf-posix2${EXEEXT} > /dev/null result=$? -if test $result = 77; then - echo "Skipping test: getrlimit and setrlimit don't work" - exit 77 -fi -if test $result != 0; then - exit 1 -fi +case $result in +77 ) echo "Skipping test: getrlimit and setrlimit don't work" + exit $result + ;; + +78 ) echo "Skipping test: getrlimit and setrlimit don't work" + exit 77 # ?!?! + ;; -if test $malloc_result = 78; then - echo "Skipping test: getrlimit and setrlimit don't work" - exit 77 -fi +79 ) echo 'Skipping test: format string of "%011000d\n" triggers ENOMEM' + exit 77 + ;; +esac -exit 0 +exit $result diff --git a/tests/test-fprintf-posix3.c b/tests/test-fprintf-posix3.c index 6c0d5f2..ffccfc6 100644 --- a/tests/test-fprintf-posix3.c +++ b/tests/test-fprintf-posix3.c @@ -72,15 +72,15 @@ main (int argc, char *argv[]) return 77; #endif - arg = atoi (argv[1]); - if (arg == 0) - { - void *memory = malloc (MAX_ALLOC_TOTAL); - if (memory == NULL) - return 1; - memset (memory, 17, MAX_ALLOC_TOTAL); - return 78; - } + { + void *memory = malloc (MAX_ALLOC_TOTAL); + if (memory != NULL) + { + /* seg fault if the memory is not really there */ + memset (memory, 17, MAX_ALLOC_TOTAL); + return 78; + } + } /* Perform the test and test whether it triggers a permanent memory allocation of more than MAX_ALLOC_TOTAL bytes. */ @@ -91,7 +91,7 @@ main (int argc, char *argv[]) but should not result in a permanent memory allocation. */ if (fprintf (stdout, "%011000d\n", 17) == -1 && errno == ENOMEM) - return 1; + return (repeat == 0) ? 79 : 1; } return 0; diff --git a/tests/test-fprintf-posix3.sh b/tests/test-fprintf-posix3.sh index 6a6976d..8988ede 100755 --- a/tests/test-fprintf-posix3.sh +++ b/tests/test-fprintf-posix3.sh @@ -2,30 +2,20 @@ # Test against a memory leak. -(./test-fprintf-posix3${EXEEXT} 0 - result=$? - if test $result != 77 && test $result != 78; then result=1; fi - exit $result -) 2>/dev/null -malloc_result=$? -if test $malloc_result = 77; then - echo "Skipping test: getrlimit and setrlimit don't work" - exit 77 -fi - -./test-fprintf-posix3${EXEEXT} 1 > /dev/null +./test-fprintf-posix3${EXEEXT} > /dev/null result=$? -if test $result = 77; then - echo "Skipping test: getrlimit and setrlimit don't work" - exit 77 -fi -if test $result != 0; then - exit 1 -fi +case $result in +77 ) echo "Skipping test: getrlimit and setrlimit don't work" + exit $result + ;; + +78 ) echo "Skipping test: getrlimit and setrlimit don't work" + exit 77 # ?!?! + ;; -if test $malloc_result = 78; then - echo "Skipping test: getrlimit and setrlimit don't work" - exit 77 -fi +79 ) echo 'Skipping test: format string of "%011000d\n" triggers ENOMEM' + exit 77 # ?!?! + ;; +esac -exit 0 +exit $result -- 1.7.1