15 #include <freerdp/config.h>
17 #include <winpr/sysinfo.h>
18 #include "prim_test.h"
21 static BOOL check8(
const BYTE* src, UINT32 length, UINT32 offset, BYTE value)
23 for (UINT32 i = 0; i < length; ++i)
25 if (src[offset + i] != value)
27 printf(
"SET8U FAILED: off=%" PRIu32
" len=%" PRIu32
" dest[%" PRIu32
"]=0x%02" PRIx8
29 offset, length, i + offset, src[i + offset]);
37 static BOOL test_set8u_func(
void)
41 for (UINT32 off = 0; off < 16; ++off)
45 memset(dest, 3,
sizeof(dest));
46 for (UINT32 len = 1; len < 48 - off; ++len)
48 status =
generic->set_8u(0xa5, dest + off, len);
50 if (status != PRIMITIVES_SUCCESS)
53 if (!check8(dest, len, off, 0xa5))
58 for (UINT32 off = 0; off < 16; ++off)
62 memset(dest, 3,
sizeof(dest));
63 for (UINT32 len = 1; len < 48 - off; ++len)
65 status = optimized->set_8u(0xa5, dest + off, len);
67 if (status != PRIMITIVES_SUCCESS)
70 if (!check8(dest, len, off, 0xa5))
79 static BOOL test_set8u_speed(
void)
84 for (UINT32 x = 0; x < 16; x++)
86 winpr_RAND(&value,
sizeof(value));
88 if (!speed_test(
"set_8u",
"", g_Iterations, (speed_test_fkt)generic->set_8u,
89 (speed_test_fkt)optimized->set_8u, value, dest + x, x))
96 static BOOL check32s(
const INT32* src, UINT32 length, UINT32 offset, INT32 value)
98 for (UINT32 i = 0; i < length; ++i)
100 if (src[offset + i] != value)
102 printf(
"SET8U FAILED: off=%" PRIu32
" len=%" PRIu32
" dest[%" PRIu32
"]=0x%08" PRIx32
104 offset, length, i + offset, src[i + offset]);
113 static BOOL test_set32s_func(
void)
115 pstatus_t status = 0;
116 const INT32 value = -0x12345678;
118 for (UINT32 off = 0; off < 16; ++off)
120 INT32 dest[1024] = { 0 };
122 for (UINT32 len = 1; len < 48 - off; ++len)
124 status =
generic->set_32s(value, dest + off, len);
126 if (status != PRIMITIVES_SUCCESS)
129 if (!check32s(dest, len, off, value))
134 for (UINT32 off = 0; off < 16; ++off)
136 INT32 dest[1024] = { 0 };
138 for (UINT32 len = 1; len < 48 - off; ++len)
140 status = optimized->set_32s(value, dest + off, len);
142 if (status != PRIMITIVES_SUCCESS)
145 if (!check32s(dest, len, off, value))
153 static BOOL check32u(
const UINT32* src, UINT32 length, UINT32 offset, UINT32 value)
155 for (UINT32 i = 0; i < length; ++i)
157 if (src[offset + i] != value)
159 printf(
"SET8U FAILED: off=%" PRIu32
" len=%" PRIu32
" dest[%" PRIu32
"]=0x%08" PRIx32
161 offset, length, i + offset, src[i + offset]);
170 static BOOL test_set32u_func(
void)
172 pstatus_t status = 0;
173 const UINT32 value = 0xABCDEF12;
175 for (UINT32 off = 0; off < 16; ++off)
177 UINT32 dest[1024] = { 0 };
179 for (UINT32 len = 1; len < 48 - off; ++len)
181 status =
generic->set_32u(value, dest + off, len);
183 if (status != PRIMITIVES_SUCCESS)
186 if (!check32u(dest, len, off, value))
191 for (UINT32 off = 0; off < 16; ++off)
193 UINT32 dest[1024] = { 0 };
195 for (UINT32 len = 1; len < 48 - off; ++len)
197 status = optimized->set_32u(value, dest + off, len);
199 if (status != PRIMITIVES_SUCCESS)
202 if (!check32u(dest, len, off, value))
211 static BOOL test_set32u_speed(
void)
216 for (UINT32 x = 0; x < 16; x++)
218 winpr_RAND(&value,
sizeof(value));
220 if (!speed_test(
"set_32u",
"", g_Iterations, (speed_test_fkt)generic->set_32u,
221 (speed_test_fkt)optimized->set_32u, value, dest + x, x))
229 static BOOL test_set32s_speed(
void)
234 for (UINT32 x = 0; x < 16; x++)
236 winpr_RAND(&value,
sizeof(value));
238 if (!speed_test(
"set_32s",
"", g_Iterations, (speed_test_fkt)generic->set_32s,
239 (speed_test_fkt)optimized->set_32s, value, dest + x, x))
246 int TestPrimitivesSet(
int argc,
char* argv[])
250 prim_test_setup(FALSE);
252 if (!test_set8u_func())
255 if (!test_set32s_func())
258 if (!test_set32u_func())
261 if (g_TestPrimitivesPerformance)
263 if (!test_set8u_speed())
266 if (!test_set32s_speed())
269 if (!test_set32u_speed())