34
34
* Nicolas Tsiftes <[email protected] >
35
35
*/
36
36
37
+ #include <stdint.h>
37
38
#include <stdio.h>
38
39
#include <stdlib.h>
39
40
#include <string.h>
@@ -77,6 +78,13 @@ UNIT_TEST(do_many_allocations)
77
78
char * ptrs [TEST_CONCURRENT ] = { NULL };
78
79
unsigned failed_allocations = 0 ;
79
80
unsigned failed_deallocations = 0 ;
81
+ unsigned misalignments = 0 ;
82
+ unsigned min_alignment = heapmem_alignment ();
83
+
84
+ UNIT_TEST_ASSERT (min_alignment != 0 );
85
+ UNIT_TEST_ASSERT (!(min_alignment & (min_alignment - 1 )));
86
+
87
+ printf ("Using heapmem alignment of %u\n" , min_alignment );
80
88
81
89
/*
82
90
* Do a number of allocations (TEST_LIMIT) of a random size in the range
@@ -103,6 +111,9 @@ UNIT_TEST(do_many_allocations)
103
111
if (ptrs [alloc_index ] == NULL ) {
104
112
failed_allocations ++ ;
105
113
} else {
114
+ if ((uintptr_t )ptrs [alloc_index ] & (min_alignment - 1 )) {
115
+ misalignments ++ ;
116
+ }
106
117
memset (ptrs [alloc_index ], '!' , alloc_size );
107
118
}
108
119
}
@@ -118,8 +129,10 @@ UNIT_TEST(do_many_allocations)
118
129
119
130
printf ("Failed allocations: %u\n" , failed_allocations );
120
131
printf ("Failed deallocations: %u\n" , failed_deallocations );
132
+ printf ("Misaligned addresses: %u\n" , misalignments );
121
133
UNIT_TEST_ASSERT (failed_allocations == 0 );
122
134
UNIT_TEST_ASSERT (failed_deallocations == 0 );
135
+ UNIT_TEST_ASSERT (misalignments == 0 );
123
136
124
137
UNIT_TEST_END ();
125
138
}
0 commit comments