On Solaris 11.3/sparc64, I see a test failure: FAIL test-malloc-gnu (exit status: 1)
Now, there are 3 possible reasons for exit status 1 in this test. This makes the investigation of the cause unnecessarily time consuming. Similarly, test-reallocarray has exit statuses 1, 2, 3, 4, but this does not scale: there are only 125 possible exit codes available in this way. Better use the ASSERT macro, which we are using for many years in other places and which points immediately to the line in question. 2021-05-14 Bruno Haible <br...@clisp.org> *alloc-gnu tests: Use ASSERT macro. * tests/test-malloc-gnu.c: Include "macros.h". (main): Use ASSERT. * tests/test-calloc-gnu.c: Include "macros.h". (main): Use ASSERT. * tests/test-realloc-gnu.c: Include "macros.h". (main): Use ASSERT. * tests/test-reallocarray.c: Include "macros.h". (main): Use ASSERT. * modules/malloc-gnu-tests (Files): Add tests/macros.h. * modules/calloc-gnu-tests (Files): Likewise. * modules/realloc-gnu-tests (Files): Likewise. * modules/reallocarray-tests (Files): Likewise. diff --git a/modules/calloc-gnu-tests b/modules/calloc-gnu-tests index a4804fd..f0f061c 100644 --- a/modules/calloc-gnu-tests +++ b/modules/calloc-gnu-tests @@ -1,5 +1,6 @@ Files: tests/test-calloc-gnu.c +tests/macros.h Depends-on: stdint diff --git a/modules/malloc-gnu-tests b/modules/malloc-gnu-tests index 9a6f01c..dc1a34f 100644 --- a/modules/malloc-gnu-tests +++ b/modules/malloc-gnu-tests @@ -1,5 +1,6 @@ Files: tests/test-malloc-gnu.c +tests/macros.h Depends-on: stdint diff --git a/modules/realloc-gnu-tests b/modules/realloc-gnu-tests index 9d26260..c1dbe17 100644 --- a/modules/realloc-gnu-tests +++ b/modules/realloc-gnu-tests @@ -1,5 +1,6 @@ Files: tests/test-realloc-gnu.c +tests/macros.h Depends-on: stdint diff --git a/modules/reallocarray-tests b/modules/reallocarray-tests index 4b61da1..3082281 100644 --- a/modules/reallocarray-tests +++ b/modules/reallocarray-tests @@ -1,6 +1,7 @@ Files: tests/test-reallocarray.c tests/signature.h +tests/macros.h Depends-on: stdint diff --git a/tests/test-calloc-gnu.c b/tests/test-calloc-gnu.c index dbef019..a98a75f 100644 --- a/tests/test-calloc-gnu.c +++ b/tests/test-calloc-gnu.c @@ -16,11 +16,14 @@ #include <config.h> +/* Specification. */ #include <stdlib.h> #include <errno.h> #include <stdint.h> +#include "macros.h" + /* Return N. Usual compilers are not able to infer something about the return value. */ static size_t @@ -44,8 +47,7 @@ main () /* Check that calloc (0, 0) is not a NULL pointer. */ { void * volatile p = calloc (0, 0); - if (p == NULL) - return 1; + ASSERT (p != NULL); free (p); } @@ -58,11 +60,12 @@ main () for (size_t n = 2; n != 0; n <<= 1) { void *volatile p = calloc (PTRDIFF_MAX / n + 1, identity (n)); - if (!(p == NULL && errno == ENOMEM)) - return 2; - p = calloc (SIZE_MAX / n + 1, identity (n)); - if (!(p == NULL && errno == ENOMEM)) - return 3; + ASSERT (p == NULL); + ASSERT (errno == ENOMEM); + + p = calloc (SIZE_MAX / n + 1, identity (n)); + ASSERT (p == NULL); + ASSERT (errno == ENOMEM); } } diff --git a/tests/test-malloc-gnu.c b/tests/test-malloc-gnu.c index 13217c1..0160c6c 100644 --- a/tests/test-malloc-gnu.c +++ b/tests/test-malloc-gnu.c @@ -16,18 +16,20 @@ #include <config.h> +/* Specification. */ #include <stdlib.h> #include <errno.h> #include <stdint.h> +#include "macros.h" + int main (int argc, char **argv) { /* Check that malloc (0) is not a NULL pointer. */ void *volatile p = malloc (0); - if (p == NULL) - return 1; + ASSERT (p != NULL); free (p); /* Check that malloc (n) fails when n exceeds PTRDIFF_MAX. */ @@ -35,8 +37,8 @@ main (int argc, char **argv) { size_t one = argc != 12345; p = malloc (PTRDIFF_MAX + one); - if (!(p == NULL && errno == ENOMEM)) - return 1; + ASSERT (p == NULL); + ASSERT (errno == ENOMEM); } return 0; diff --git a/tests/test-realloc-gnu.c b/tests/test-realloc-gnu.c index a366738..3a787ed 100644 --- a/tests/test-realloc-gnu.c +++ b/tests/test-realloc-gnu.c @@ -16,18 +16,20 @@ #include <config.h> +/* Specification. */ #include <stdlib.h> #include <errno.h> #include <stdint.h> +#include "macros.h" + int main (int argc, char **argv) { /* Check that realloc (NULL, 0) is not a NULL pointer. */ void *volatile p = realloc (NULL, 0); - if (p == NULL) - return 1; + ASSERT (p != NULL); /* Check that realloc (p, n) fails when p is non-null and n exceeds PTRDIFF_MAX. */ @@ -35,8 +37,8 @@ main (int argc, char **argv) { size_t one = argc != 12345; p = realloc (p, PTRDIFF_MAX + one); - if (!(p == NULL && errno == ENOMEM)) - return 1; + ASSERT (p == NULL); + ASSERT (errno == ENOMEM); } free (p); diff --git a/tests/test-reallocarray.c b/tests/test-reallocarray.c index 8067542..f0839ff 100644 --- a/tests/test-reallocarray.c +++ b/tests/test-reallocarray.c @@ -16,13 +16,17 @@ #include <config.h> +/* Specification. */ #include <stdlib.h> + #include <errno.h> #include <stdint.h> #include "signature.h" SIGNATURE_CHECK (reallocarray, void *, (void *, size_t, size_t)); +#include "macros.h" + int main () { @@ -33,17 +37,13 @@ main () void *volatile p = NULL; p = reallocarray (p, PTRDIFF_MAX / n + 1, n); - if (p) - return 1; - if (errno != ENOMEM) - return 2; + ASSERT (p == NULL); + ASSERT (errno == ENOMEM); p = reallocarray (p, SIZE_MAX / n + 1, n); - if (p) - return 3; - if (!(errno == ENOMEM - || errno == EOVERFLOW /* NetBSD */)) - return 4; + ASSERT (p == NULL); + ASSERT (errno == ENOMEM + || errno == EOVERFLOW /* NetBSD */); /* Reallocarray should not crash with zero sizes. */ p = reallocarray (p, 0, n);