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