summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog16
-rw-r--r--modules/calloc-gnu-tests1
-rw-r--r--modules/malloc-gnu-tests1
-rw-r--r--modules/realloc-gnu-tests1
-rw-r--r--modules/reallocarray-tests1
-rw-r--r--tests/test-calloc-gnu.c17
-rw-r--r--tests/test-malloc-gnu.c10
-rw-r--r--tests/test-realloc-gnu.c10
-rw-r--r--tests/test-reallocarray.c18
9 files changed, 51 insertions, 24 deletions
diff --git a/ChangeLog b/ChangeLog
index 35afdfeb95..3367d8dda5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2021-05-14 Bruno Haible <bruno@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.
+
2021-05-14 Simon Josefsson <simon@josefsson.org>
valgrind-tests: Fix 'sh: yes: unknown operand' error.
diff --git a/modules/calloc-gnu-tests b/modules/calloc-gnu-tests
index a4804fd282..f0f061cd11 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 9a6f01cfa9..dc1a34fe5c 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 9d26260ba7..c1dbe17b18 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 4b61da1435..3082281dea 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 dbef019143..a98a75f703 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 13217c1b51..0160c6c49c 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 a36673888b..3a787ed91f 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 8067542d58..f0839ff748 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);