1 /* Smoke test for mallinfo2
2 Copyright (C) 2020-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 /* Test that mallinfo2 is properly exported and basically works. */
21 #include <array_length.h>
24 #include <support/check.h>
26 /* This is not specifically needed for the test, but (1) does
27 something to the data so gcc doesn't optimize it away, and (2) may
28 help when developing future tests. */
30 print_mi (const char *msg
, struct mallinfo2
*m
)
32 printf("\n%s...\n", msg
);
33 #define P(f) printf("%s: %zu\n", #f, m->f)
46 /* We do this to force the call to malloc to not be optimized
53 struct mallinfo2 mi1
, mi2
;
57 /* This is the key difference between mallinfo() and mallinfo2().
58 It may be a false positive if int and size_t are the same
60 TEST_COMPARE (sizeof (mi1
.arena
), sizeof (size_t));
63 print_mi ("before", &mi1
);
65 /* Allocations that are meaningful-sized but not so large as to be
66 mmapped, so that they're all accounted for in the field we test
68 for (i
= 1; i
< 20; ++i
)
70 ptr
= malloc (160 * i
);
75 print_mi ("after", &mi2
);
77 /* Check at least something changed. */
78 TEST_VERIFY (mi2
.uordblks
>= mi1
.uordblks
+ total
);
83 #include <support/test-driver.c>