usleep tests: Avoid failure due to known Cygwin 3.5.3 bug.
[gnulib.git] / tests / test-alignalloc.c
blob5a2aaa82066f6ceaf62b0c51dcb7c0fed27cd7c7
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/>. */
18 #include <config.h>
20 #include <alignalloc.h>
22 #include <stdint.h>
23 #include <string.h>
24 #include "intprops.h"
26 #include "signature.h"
27 SIGNATURE_CHECK (alignalloc, void *, (idx_t, idx_t));
28 SIGNATURE_CHECK (alignfree, void, (void *));
30 #include "macros.h"
32 static void
33 test_alignalloc (idx_t alignment, idx_t size)
35 void *p = alignalloc (alignment, size);
36 if (p)
38 memset (p, 0, size);
39 ASSERT ((uintptr_t) p % alignment == 0);
41 alignfree (p);
44 int
45 main ()
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. */
60 alignfree (NULL);
62 return test_exit_status;