sigprocmask: Fix configuration failure on Solaris 10 (regr. 2020-07-25).
[gnulib.git] / tests / test-aligned-malloc.c
blob6368746e7c5104833c7408df99a4698bf3ec9733
1 /* Test of allocating memory with given alignment.
3 Copyright (C) 2020 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 /* Written by Bruno Haible <bruno@clisp.org>, 2020. */
20 #include <config.h>
22 #include <stdint.h>
23 #include <stdlib.h>
25 #define ALIGNMENT 4
26 #define aligned_malloc aligned4_malloc
27 #define aligned_free aligned4_free
28 #include "aligned-malloc.h"
29 #undef aligned_free
30 #undef aligned_malloc
31 #undef ALIGNMENT
33 #define ALIGNMENT 8
34 #define aligned_malloc aligned8_malloc
35 #define aligned_free aligned8_free
36 #include "aligned-malloc.h"
37 #undef aligned_free
38 #undef aligned_malloc
39 #undef ALIGNMENT
41 #define ALIGNMENT 16
42 #define aligned_malloc aligned16_malloc
43 #define aligned_free aligned16_free
44 #include "aligned-malloc.h"
45 #undef aligned_free
46 #undef aligned_malloc
47 #undef ALIGNMENT
49 #define ALIGNMENT 32
50 #define aligned_malloc aligned32_malloc
51 #define aligned_free aligned32_free
52 #include "aligned-malloc.h"
53 #undef aligned_free
54 #undef aligned_malloc
55 #undef ALIGNMENT
57 #include <string.h>
59 #include "macros.h"
61 int
62 main (int argc, char *argv[])
64 static size_t sizes[] =
65 { 13, 8, 17, 450, 320, 1, 99, 4, 15, 16, 2, 76, 37, 127, 2406, 641 };
66 void *aligned4_blocks[SIZEOF (sizes)];
67 void *aligned8_blocks[SIZEOF (sizes)];
68 void *aligned16_blocks[SIZEOF (sizes)];
69 void *aligned32_blocks[SIZEOF (sizes)];
70 size_t i;
72 for (i = 0; i < SIZEOF (sizes); i++)
74 size_t size = sizes[i];
76 aligned4_blocks[i] = aligned4_malloc (size);
77 ASSERT (((uintptr_t) aligned4_blocks[i] % 4) == 0);
78 memset (aligned4_blocks[i], 'w', size);
80 aligned8_blocks[i] = aligned8_malloc (size);
81 ASSERT (((uintptr_t) aligned8_blocks[i] % 8) == 0);
82 memset (aligned8_blocks[i], 'x', size);
84 aligned16_blocks[i] = aligned16_malloc (size);
85 ASSERT (((uintptr_t) aligned16_blocks[i] % 16) == 0);
86 memset (aligned16_blocks[i], 'y', size);
88 aligned32_blocks[i] = aligned32_malloc (size);
89 ASSERT (((uintptr_t) aligned32_blocks[i] % 32) == 0);
90 memset (aligned32_blocks[i], 'z', size);
93 for (i = 0; i < SIZEOF (sizes); i++)
95 aligned4_free (aligned4_blocks[i]);
96 aligned8_free (aligned8_blocks[i]);
97 aligned16_free (aligned16_blocks[i]);
98 aligned32_free (aligned32_blocks[i]);
101 return 0;