1 /* Test alignalloc and alignfree.
3 Copyright 2022-2024 Free Software Foundation, Inc.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program 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
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
20 #include <alignalloc.h>
26 #include "signature.h"
27 SIGNATURE_CHECK (alignalloc
, void *, (idx_t
, idx_t
));
28 SIGNATURE_CHECK (alignfree
, void, (void *));
33 test_alignalloc (idx_t alignment
, idx_t size
)
35 void *p
= alignalloc (alignment
, size
);
39 ASSERT ((uintptr_t) p
% alignment
== 0);
47 /* Check that alignalloc returns properly aligned storage when it succeeds.
48 Stop at 16 MiB alignments because circa-2022 AddressSanitizer goes
49 catatonic with large alignments in posix_memalign,
50 and there seems to be little point to testing them. */
51 for (idx_t alignment
= 1; alignment
<= 16 * 1024 * 1024; alignment
*= 2)
52 for (idx_t size
= 1; size
<= 1024; size
*= 2)
54 test_alignalloc (alignment
, size
- 1);
55 test_alignalloc (alignment
, size
);
56 test_alignalloc (alignment
, size
+ 1);
59 /* Check that alignfree is a no-op on null pointers. */
62 return test_exit_status
;