This source file includes following definitions.
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 #include <config.h>
21
22
23 #include <stdlib.h>
24
25 #include <stdint.h>
26 #include <stdio.h>
27 #include <string.h>
28
29 #include "macros.h"
30
31 #define ROUNDUP(x,y) (((x) + (y) - 1) & - (y))
32
33 int
34 main (int argc, char *argv[])
35 {
36 #if HAVE_ALIGNED_ALLOC
37 static size_t sizes[] =
38 { 13, 8, 17, 450, 320, 1, 99, 4, 15, 16, 2, 76, 37, 127, 2406, 641, 5781 };
39 void *volatile aligned2_blocks[SIZEOF (sizes)];
40 void *volatile aligned4_blocks[SIZEOF (sizes)];
41 void *volatile aligned8_blocks[SIZEOF (sizes)];
42 void *volatile aligned16_blocks[SIZEOF (sizes)];
43 void *volatile aligned32_blocks[SIZEOF (sizes)];
44 void *volatile aligned64_blocks[SIZEOF (sizes)];
45 size_t i;
46
47 for (i = 0; i < SIZEOF (sizes); i++)
48 {
49 size_t size = sizes[i];
50
51 aligned2_blocks[i] = aligned_alloc (2, ROUNDUP (size, 2));
52 ASSERT (aligned2_blocks[i] != NULL);
53 ASSERT (((uintptr_t) aligned2_blocks[i] % 2) == 0);
54 memset (aligned2_blocks[i], 'u', size);
55
56 aligned4_blocks[i] = aligned_alloc (4, ROUNDUP (size, 4));
57 ASSERT (aligned4_blocks[i] != NULL);
58 ASSERT (((uintptr_t) aligned4_blocks[i] % 4) == 0);
59 memset (aligned4_blocks[i], 'v', size);
60
61 aligned8_blocks[i] = aligned_alloc (8, ROUNDUP (size, 8));
62 ASSERT (aligned8_blocks[i] != NULL);
63 ASSERT (((uintptr_t) aligned8_blocks[i] % 8) == 0);
64 memset (aligned8_blocks[i], 'w', size);
65
66 aligned16_blocks[i] = aligned_alloc (16, ROUNDUP (size, 16));
67 ASSERT (aligned16_blocks[i] != NULL);
68 ASSERT (((uintptr_t) aligned16_blocks[i] % 16) == 0);
69 memset (aligned16_blocks[i], 'x', size);
70
71 aligned32_blocks[i] = aligned_alloc (32, ROUNDUP (size, 32));
72 ASSERT (aligned32_blocks[i] != NULL);
73 ASSERT (((uintptr_t) aligned32_blocks[i] % 32) == 0);
74 memset (aligned32_blocks[i], 'y', size);
75
76 aligned64_blocks[i] = aligned_alloc (64, ROUNDUP (size, 64));
77 ASSERT (aligned64_blocks[i] != NULL);
78 ASSERT (((uintptr_t) aligned64_blocks[i] % 64) == 0);
79 memset (aligned64_blocks[i], 'z', size);
80 }
81
82 for (i = 0; i < SIZEOF (sizes); i++)
83 {
84 free (aligned2_blocks[i]);
85 free (aligned4_blocks[i]);
86 free (aligned8_blocks[i]);
87 free (aligned16_blocks[i]);
88 free (aligned32_blocks[i]);
89 free (aligned64_blocks[i]);
90 }
91
92 return 0;
93 #else
94 fputs ("Skipping test: function 'aligned_alloc' does not exist\n", stderr);
95 return 77;
96 #endif
97 }