summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2019-04-30 10:17:19 +0200
committerLennart Poettering <lennart@poettering.net>2019-05-02 14:53:40 +0200
commit413644757628952af3c9c503be579f094517093d (patch)
treed738f6bb029f1b571c248745b1b6963fd90e501a
parente59054270c6e37fd08fdd5d0231edd17c7f7495a (diff)
downloadsystemd-413644757628952af3c9c503be579f094517093d.tar.gz
test-alloc-util: let's test a few more things around GREEDY_REALLOC()
-rw-r--r--src/test/test-alloc-util.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/test/test-alloc-util.c b/src/test/test-alloc-util.c
index ad10eb178a..2dfdfe35ec 100644
--- a/src/test/test-alloc-util.c
+++ b/src/test/test-alloc-util.c
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
+#include <malloc.h>
#include <stdint.h>
#include "alloc-util.h"
@@ -21,21 +22,35 @@ static void test_alloca(void) {
static void test_GREEDY_REALLOC(void) {
_cleanup_free_ int *a = NULL, *b = NULL;
- size_t n_allocated = 0, i;
+ size_t n_allocated = 0, i, j;
- /* Give valgrind a chance to verify our realloc operations */
+ /* Give valgrind a chance to verify our realloc() operations */
- for (i = 0; i < 2048; i++) {
+ for (i = 0; i < 20480; i++) {
assert_se(GREEDY_REALLOC(a, n_allocated, i + 1));
- a[i] = i;
+ assert_se(n_allocated >= i + 1);
+ assert_se(malloc_usable_size(a) >= (i + 1) * sizeof(int));
+ a[i] = (int) i;
assert_se(GREEDY_REALLOC(a, n_allocated, i / 2));
+ assert_se(n_allocated >= i / 2);
+ assert_se(malloc_usable_size(a) >= (i / 2) * sizeof(int));
}
- for (i = 30, n_allocated = 0; i < 2048; i+=7) {
+ for (j = 0; j < i / 2; j++)
+ assert_se(a[j] == (int) j);
+
+ for (i = 30, n_allocated = 0; i < 20480; i += 7) {
assert_se(GREEDY_REALLOC(b, n_allocated, i + 1));
- b[i] = i;
+ assert_se(n_allocated >= i + 1);
+ assert_se(malloc_usable_size(b) >= (i + 1) * sizeof(int));
+ b[i] = (int) i;
assert_se(GREEDY_REALLOC(b, n_allocated, i / 2));
+ assert_se(n_allocated >= i / 2);
+ assert_se(malloc_usable_size(b) >= (i / 2) * sizeof(int));
}
+
+ for (j = 30; j < i / 2; j += 7)
+ assert_se(b[j] == (int) j);
}
static void test_memdup_multiply_and_greedy_realloc(void) {