1 /* Test for C17 alignment requirements.
2 Copyright (C) 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/>. */
25 #include <libc-diag.h>
26 #include <support/check.h>
39 /* The implementation supports alignments that are non-negative powers of 2.
40 We test 5 distinct conditions here:
41 - A non-negative power of 2 alignment e.g. 64.
42 - A degenerate zero power of 2 alignment e.g. 1.
43 - A non-power-of-2 alignment e.g. 65.
45 - A corner case SIZE_MAX / 2 + 1 alignment.
48 p1
= aligned_alloc (64, 64);
51 FAIL_EXIT1 ("aligned_alloc(64, 64) failed");
53 p2
= aligned_alloc (1, 64);
56 FAIL_EXIT1 ("aligned_alloc(1, 64) failed");
58 p3
= aligned_alloc (65, 64);
61 FAIL_EXIT1 ("aligned_alloc(65, 64) did not fail");
63 p4
= aligned_alloc (0, 64);
66 FAIL_EXIT1 ("aligned_alloc(0, 64) did not fail");
68 /* This is an alignment like 0x80000000...UL */
69 p5
= aligned_alloc (SIZE_MAX
/ 2 + 1, 64);
72 FAIL_EXIT1 ("aligned_alloc(SIZE_MAX/2+1, 64) did not fail");
79 #define TEST_FUNCTION do_test ()
80 #include "../test-skeleton.c"