summaryrefslogtreecommitdiff
path: root/malloc/tst-mallocstate.c
diff options
context:
space:
mode:
Diffstat (limited to 'malloc/tst-mallocstate.c')
-rw-r--r--malloc/tst-mallocstate.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/malloc/tst-mallocstate.c b/malloc/tst-mallocstate.c
index 7e081c548a..bd6678e1aa 100644
--- a/malloc/tst-mallocstate.c
+++ b/malloc/tst-mallocstate.c
@@ -186,6 +186,10 @@ struct allocation
unsigned int seed;
};
+/* After heap initialization, we can call malloc_usable_size to check
+ if it gives valid results. */
+static bool malloc_usable_size_valid;
+
/* Check that the allocation task allocation has the expected
contents. */
static void
@@ -221,6 +225,23 @@ check_allocation (const struct allocation *alloc, int index)
putc ('\n', stdout);
errors = true;
}
+
+ if (malloc_usable_size_valid)
+ {
+ size_t usable = malloc_usable_size (alloc->data);
+ if (usable < size)
+ {
+ printf ("error: allocation %d has reported size %zu (expected %zu)\n",
+ index, usable, size);
+ errors = true;
+ }
+ else if (usable > size + 4096)
+ {
+ printf ("error: allocation %d reported as %zu bytes (requested %zu)\n",
+ index, usable, size);
+ errors = true;
+ }
+ }
}
/* A heap allocation combined with pending actions on it. */
@@ -317,6 +338,10 @@ init_heap (void)
write_message ("error: malloc_set_state failed\n");
_exit (1);
}
+
+ /* The heap has been initialized. We may now call
+ malloc_usable_size. */
+ malloc_usable_size_valid = true;
}
/* Interpose the initialization callback. */