#include <stdlib.h>
#include <malloc.h>
#include <errno.h>
#include "wine/test.h"
Go to the source code of this file.
|
static | void (__cdecl *p_aligned_free)(void *) |
|
static void *__cdecl * | p_aligned_malloc (size_t, size_t) |
|
static void *__cdecl * | p_aligned_offset_malloc (size_t, size_t, size_t) |
|
static void *__cdecl * | p_aligned_realloc (void *, size_t, size_t) |
|
static void *__cdecl * | p_aligned_offset_realloc (void *, size_t, size_t, size_t) |
|
static void | test_aligned_malloc (unsigned int size, unsigned int alignment) |
|
static void | test_aligned_offset_malloc (unsigned int size, unsigned int alignment, unsigned int offset) |
|
static void | test_aligned_realloc (unsigned int size1, unsigned int size2, unsigned int alignment) |
|
static void | test_aligned_offset_realloc (unsigned int size1, unsigned int size2, unsigned int alignment, unsigned int offset) |
|
static void | test_aligned (void) |
|
static void | test_sbheap (void) |
|
static void | test_calloc (void) |
|
| START_TEST (heap) |
|
◆ p_aligned_malloc()
◆ p_aligned_offset_malloc()
◆ p_aligned_offset_realloc()
◆ p_aligned_realloc()
◆ START_TEST()
Definition at line 492 of file heap.c.
493{
495
497 ok(
mem !=
NULL,
"memory not allocated for size 0\n");
499
501 ok(
mem !=
NULL,
"memory not allocated\n");
502
504 ok(
mem !=
NULL,
"memory not reallocated\n");
505
508
510 ok(
mem !=
NULL,
"memory not (re)allocated for size 0\n");
511
513
517}
static void test_calloc(void)
static void test_aligned(void)
static void test_sbheap(void)
◆ test_aligned()
Definition at line 240 of file heap.c.
241{
243
245 return;
246
252
254 {
255 skip(
"aligned memory tests skipped\n");
256 return;
257 }
258
270
282
294
303
316
329
342
355
368
381
394
407
420}
#define GetProcAddress(x, y)
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
static void test_aligned_malloc(unsigned int size, unsigned int alignment)
static void test_aligned_offset_realloc(unsigned int size1, unsigned int size2, unsigned int alignment, unsigned int offset)
static void *__cdecl * p_aligned_offset_realloc(void *, size_t, size_t, size_t)
static void *__cdecl * p_aligned_offset_malloc(size_t, size_t, size_t)
static void *__cdecl * p_aligned_realloc(void *, size_t, size_t)
static void test_aligned_realloc(unsigned int size1, unsigned int size2, unsigned int alignment)
static void *__cdecl * p_aligned_malloc(size_t, size_t)
static void test_aligned_offset_malloc(unsigned int size, unsigned int alignment, unsigned int offset)
Referenced by START_TEST().
◆ test_aligned_malloc()
Definition at line 38 of file heap.c.
39{
41
43
44 if ((alignment & (alignment - 1)) == 0)
45 ok(
mem !=
NULL,
"_aligned_malloc(%d, %d) failed\n",
size, alignment);
46 else
47 ok(
mem ==
NULL,
"_aligned_malloc(%d, %d) should have failed\n",
size, alignment);
48
50 {
52 "_aligned_malloc(%d, %d) not aligned: %p\n",
size, alignment,
mem);
54 {
55 void *saved;
56 saved = *(
void **)((
DWORD_PTR)((
char *)
mem -
sizeof(
void *)) & ~(
sizeof(
void *) - 1));
57 trace(
"_aligned_malloc(%3d, %3d) returns %p, saved = %p\n",
size, alignment,
mem, saved );
58 }
60 }
61 else
63}
Referenced by test_aligned().
◆ test_aligned_offset_malloc()
Definition at line 65 of file heap.c.
66{
68
70
71 if ((alignment & (alignment - 1)) == 0)
74 else
76 else
77 ok(
mem ==
NULL,
"_aligned_offset_malloc(%d, %d, %d) should have failed\n",
size, alignment,
offset);
78
80 {
82 "_aligned_offset_malloc(%d, %d, %d) not aligned: %p\n",
size, alignment,
offset,
mem);
84 {
85 void *saved;
86 saved = *(
void **)((
DWORD_PTR)((
char *)
mem -
sizeof(
void *)) & ~(
sizeof(
void *) - 1));
87 trace(
"_aligned_offset_malloc(%3d, %3d, %3d) returns %p, saved = %p\n",
89 }
91 }
92 else
94}
Referenced by test_aligned().
◆ test_aligned_offset_realloc()
Definition at line 167 of file heap.c.
169{
170 void *
mem, *mem1, *mem2;
171
173
174 if ((alignment & (alignment - 1)) == 0)
175 ok(
mem !=
NULL,
"_aligned_offset_malloc(%d, %d, %d) failed\n", size1, alignment,
offset);
176 else
177 ok(
mem ==
NULL,
"_aligned_offset_malloc(%d, %d, %d) should have failed\n", size1, alignment,
offset);
178
180 {
182 if (mem1)
183 {
185 for (
i = 0;
i < size1;
i++)
186 ((
char *)
mem)[
i] =
i + 1;
188 }
189
191 "_aligned_offset_malloc(%d, %d, %d) not aligned: %p\n", size1, alignment,
offset,
mem);
193 {
194 void *saved;
195 saved = *(
void **)((
DWORD_PTR)((
char *)
mem -
sizeof(
void *)) & ~(
sizeof(
void *) - 1));
196 trace(
"_aligned_offset_malloc(%3d, %3d, %3d) returns %p, saved = %p\n",
198 }
199
201
202 ok(mem2 !=
NULL,
"_aligned_offset_realloc(%p, %d, %d, %d) failed\n",
mem, size2, alignment,
offset);
203
204 if (mem2)
205 {
207 "_aligned_offset_realloc(%p, %d, %d, %d) not aligned: %p\n",
mem, size2, alignment,
offset, mem2);
209 {
210 void *saved;
211 saved = *(
void **)((
DWORD_PTR)((
char *)mem2 -
sizeof(
void *)) & ~(
sizeof(
void *) - 1));
212 trace(
"_aligned_offset_realloc(%p, %3d, %3d, %3d) returns %p, saved = %p\n",
213 mem, size2, alignment,
offset, mem2, saved);
214 }
215 if (mem1)
216 {
217 ok(
memcmp(mem2, mem1,
min(size1, size2))==0,
"_aligned_offset_realloc(%p, %d, %d, %d) has different data\n",
mem, size2, alignment,
offset);
219 {
221 for (
i = 0;
i <
min(size1, size2);
i++)
222 {
223 if (((
char *)mem2)[
i] != ((
char *)mem1)[
i])
224 trace(
"%d: %02x != %02x\n",
i, ((
char *)mem2)[
i] & 0xff, ((
char *)mem1)[
i] & 0xff);
225 }
226 }
227 }
228 p_aligned_free(mem2);
229 } else {
230 ok(
errno ==
EINVAL,
"_aligned_offset_realloc(%p, %d, %d, %d) errno: %d != %d\n",
mem, size2, alignment,
offset,
errno,
EINVAL);
232 }
233
235 }
236 else
238}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
#define memcpy(s1, s2, n)
Referenced by test_aligned().
◆ test_aligned_realloc()
Definition at line 96 of file heap.c.
97{
98 void *
mem, *mem1, *mem2;
99
101
102 if ((alignment & (alignment - 1)) == 0)
103 ok(
mem !=
NULL,
"_aligned_malloc(%d, %d) failed\n", size1, alignment);
104 else
105 ok(
mem ==
NULL,
"_aligned_malloc(%d, %d) should have failed\n", size1, alignment);
106
108 {
110 if (mem1)
111 {
113 for (
i = 0;
i < size1;
i++)
114 ((
char *)
mem)[
i] =
i + 1;
116 }
117
119 "_aligned_malloc(%d, %d) not aligned: %p\n", size1, alignment,
mem);
121 {
122 void *saved;
123 saved = *(
void **)((
DWORD_PTR)((
char *)
mem -
sizeof(
void *)) & ~(
sizeof(
void *) - 1));
124 trace(
"_aligned_malloc(%3d, %3d) returns %p, saved = %p\n", size1, alignment,
mem, saved);
125 }
126
128
129 ok(mem2 !=
NULL,
"_aligned_realloc(%p, %d, %d) failed\n",
mem, size2, alignment);
130
131 if (mem2)
132 {
133 ok(((
DWORD_PTR)mem2 & (alignment ? alignment - 1 : 0)) == 0,
134 "_aligned_realloc(%p, %d, %d) not aligned: %p\n",
mem, size2, alignment, mem2);
136 {
137 void *saved;
138 saved = *(
void **)((
DWORD_PTR)((
char *)mem2 -
sizeof(
void *)) & ~(
sizeof(
void *) - 1));
139 trace(
"_aligned_realloc(%p, %3d, %3d) returns %p, saved = %p\n",
140 mem, size2, alignment, mem2, saved);
141 }
142 if (mem1)
143 {
144 ok(
memcmp(mem2, mem1,
min(size1, size2))==0,
"_aligned_realloc(%p, %d, %d) has different data\n",
mem, size2, alignment);
146 {
148 for (
i = 0;
i <
min(size1, size2);
i++)
149 {
150 if (((
char *)mem2)[
i] != ((
char *)mem1)[
i])
151 trace(
"%d: %02x != %02x\n",
i, ((
char *)mem2)[
i] & 0xff, ((
char *)mem1)[
i] & 0xff);
152 }
153 }
154 }
155 p_aligned_free(mem2);
156 } else {
159 }
160
162 }
163 else
165}
Referenced by test_aligned().
◆ test_calloc()
Definition at line 465 of file heap.c.
466{
467
468 void *(
__cdecl *p_calloc)(
size_t,
size_t);
470
472
473 ptr = p_calloc(1, 0);
476
477 ptr = p_calloc(0, 0);
480
481 ptr = p_calloc(0, 1);
484
486 ptr = p_calloc(~(
size_t)0 / 2, ~(
size_t)0 / 2);
490}
Referenced by START_TEST().
◆ test_sbheap()
Definition at line 422 of file heap.c.
423{
425 int threshold;
426
427 if(sizeof(void*) == 8) {
430 return;
431 }
432
435
438 ok(threshold == 16,
"threshold = %d\n", threshold);
439
442 ok(threshold == 16,
"threshold = %d\n", threshold);
443
446 ok(threshold == 1008,
"threshold = %d\n", threshold);
447
449
453
457
460 ok(threshold == 0,
"threshold = %d\n", threshold);
461
463}
_CRTIMP int __cdecl _set_sbh_threshold(_In_ size_t _NewValue)
_Check_return_ _CRTIMP size_t __cdecl _get_sbh_threshold(void)
unsigned __int3264 UINT_PTR
Referenced by START_TEST().
◆ void()