X Tutup
Skip to content

Commit cc99274

Browse files
committed
test-alloc-util: add a smoke test for greedy_realloc
1 parent 631427d commit cc99274

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/test/test-alloc-util.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,25 @@ static void test_alloca(void) {
1919
assert_se(!memcmp(t, zero, 997));
2020
}
2121

22+
static void test_GREEDY_REALLOC(void) {
23+
_cleanup_free_ int *a = NULL, *b = NULL;
24+
size_t n_allocated = 0, i;
25+
26+
/* Give valgrind a chance to verify our realloc operations */
27+
28+
for (i = 0; i < 2048; i++) {
29+
assert_se(GREEDY_REALLOC(a, n_allocated, i + 1));
30+
a[i] = i;
31+
assert_se(GREEDY_REALLOC(a, n_allocated, i / 2));
32+
}
33+
34+
for (i = 30, n_allocated = 0; i < 2048; i+=7) {
35+
assert_se(GREEDY_REALLOC(b, n_allocated, i + 1));
36+
b[i] = i;
37+
assert_se(GREEDY_REALLOC(b, n_allocated, i / 2));
38+
}
39+
}
40+
2241
static void test_memdup_multiply_and_greedy_realloc(void) {
2342
int org[] = {1, 2, 3};
2443
_cleanup_free_ int *dup;
@@ -74,6 +93,7 @@ static void test_bool_assign(void) {
7493

7594
int main(int argc, char *argv[]) {
7695
test_alloca();
96+
test_GREEDY_REALLOC();
7797
test_memdup_multiply_and_greedy_realloc();
7898
test_bool_assign();
7999

0 commit comments

Comments
 (0)
X Tutup