FreeRDP
Loading...
Searching...
No Matches
TestPrimitivesSet.c
1/* test_set.c
2 * vi:ts=4 sw=4
3 *
4 * (c) Copyright 2012 Hewlett-Packard Development Company, L.P.
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may
6 * not use this file except in compliance with the License. You may obtain
7 * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 * or implied. See the License for the specific language governing
12 * permissions and limitations under the License.
13 */
14
15#include <freerdp/config.h>
16
17#include <winpr/sysinfo.h>
18#include "prim_test.h"
19
20/* ------------------------------------------------------------------------- */
21static BOOL check8(const BYTE* src, UINT32 length, UINT32 offset, BYTE value)
22{
23 for (UINT32 i = 0; i < length; ++i)
24 {
25 if (src[offset + i] != value)
26 {
27 printf("SET8U FAILED: off=%" PRIu32 " len=%" PRIu32 " dest[%" PRIu32 "]=0x%02" PRIx8
28 "\n",
29 offset, length, i + offset, src[i + offset]);
30 return FALSE;
31 }
32 }
33
34 return TRUE;
35}
36
37static BOOL test_set8u_func(void)
38{
39 pstatus_t status = 0;
40
41 for (UINT32 off = 0; off < 16; ++off)
42 {
43 BYTE dest[1024];
44
45 memset(dest, 3, sizeof(dest));
46 for (UINT32 len = 1; len < 48 - off; ++len)
47 {
48 status = generic->set_8u(0xa5, dest + off, len);
49
50 if (status != PRIMITIVES_SUCCESS)
51 return FALSE;
52
53 if (!check8(dest, len, off, 0xa5))
54 return FALSE;
55 }
56 }
57
58 for (UINT32 off = 0; off < 16; ++off)
59 {
60 BYTE dest[1024];
61
62 memset(dest, 3, sizeof(dest));
63 for (UINT32 len = 1; len < 48 - off; ++len)
64 {
65 status = optimized->set_8u(0xa5, dest + off, len);
66
67 if (status != PRIMITIVES_SUCCESS)
68 return FALSE;
69
70 if (!check8(dest, len, off, 0xa5))
71 return FALSE;
72 }
73 }
74
75 return TRUE;
76}
77
78/* ------------------------------------------------------------------------- */
79static BOOL test_set8u_speed(void)
80{
81 BYTE dest[1024];
82 BYTE value = 0;
83
84 for (UINT32 x = 0; x < 16; x++)
85 {
86 if (winpr_RAND(&value, sizeof(value)) < 0)
87 return FALSE;
88
89 if (!speed_test("set_8u", "", g_Iterations, (speed_test_fkt)generic->set_8u,
90 (speed_test_fkt)optimized->set_8u, value, dest + x, x))
91 return FALSE;
92 }
93
94 return TRUE;
95}
96
97static BOOL check32s(const INT32* src, UINT32 length, UINT32 offset, INT32 value)
98{
99 for (UINT32 i = 0; i < length; ++i)
100 {
101 if (src[offset + i] != value)
102 {
103 printf("SET8U FAILED: off=%" PRIu32 " len=%" PRIu32 " dest[%" PRIu32 "]=0x%08" PRIx32
104 "\n",
105 offset, length, i + offset, src[i + offset]);
106 return FALSE;
107 }
108 }
109
110 return TRUE;
111}
112
113/* ------------------------------------------------------------------------- */
114static BOOL test_set32s_func(void)
115{
116 pstatus_t status = 0;
117 const INT32 value = -0x12345678;
118
119 for (UINT32 off = 0; off < 16; ++off)
120 {
121 INT32 dest[1024] = WINPR_C_ARRAY_INIT;
122
123 for (UINT32 len = 1; len < 48 - off; ++len)
124 {
125 status = generic->set_32s(value, dest + off, len);
126
127 if (status != PRIMITIVES_SUCCESS)
128 return FALSE;
129
130 if (!check32s(dest, len, off, value))
131 return FALSE;
132 }
133 }
134
135 for (UINT32 off = 0; off < 16; ++off)
136 {
137 INT32 dest[1024] = WINPR_C_ARRAY_INIT;
138
139 for (UINT32 len = 1; len < 48 - off; ++len)
140 {
141 status = optimized->set_32s(value, dest + off, len);
142
143 if (status != PRIMITIVES_SUCCESS)
144 return FALSE;
145
146 if (!check32s(dest, len, off, value))
147 return FALSE;
148 }
149 }
150
151 return TRUE;
152}
153
154static BOOL check32u(const UINT32* src, UINT32 length, UINT32 offset, UINT32 value)
155{
156 for (UINT32 i = 0; i < length; ++i)
157 {
158 if (src[offset + i] != value)
159 {
160 printf("SET8U FAILED: off=%" PRIu32 " len=%" PRIu32 " dest[%" PRIu32 "]=0x%08" PRIx32
161 "\n",
162 offset, length, i + offset, src[i + offset]);
163 return FALSE;
164 }
165 }
166
167 return TRUE;
168}
169
170/* ------------------------------------------------------------------------- */
171static BOOL test_set32u_func(void)
172{
173 pstatus_t status = 0;
174 const UINT32 value = 0xABCDEF12;
175
176 for (UINT32 off = 0; off < 16; ++off)
177 {
178 UINT32 dest[1024] = WINPR_C_ARRAY_INIT;
179
180 for (UINT32 len = 1; len < 48 - off; ++len)
181 {
182 status = generic->set_32u(value, dest + off, len);
183
184 if (status != PRIMITIVES_SUCCESS)
185 return FALSE;
186
187 if (!check32u(dest, len, off, value))
188 return FALSE;
189 }
190 }
191
192 for (UINT32 off = 0; off < 16; ++off)
193 {
194 UINT32 dest[1024] = WINPR_C_ARRAY_INIT;
195
196 for (UINT32 len = 1; len < 48 - off; ++len)
197 {
198 status = optimized->set_32u(value, dest + off, len);
199
200 if (status != PRIMITIVES_SUCCESS)
201 return FALSE;
202
203 if (!check32u(dest, len, off, value))
204 return FALSE;
205 }
206 }
207
208 return TRUE;
209}
210
211/* ------------------------------------------------------------------------- */
212static BOOL test_set32u_speed(void)
213{
214 UINT32 dest[1024];
215 BYTE value = 0;
216
217 for (UINT32 x = 0; x < 16; x++)
218 {
219 if (winpr_RAND(&value, sizeof(value)) < 0)
220 return FALSE;
221
222 if (!speed_test("set_32u", "", g_Iterations, (speed_test_fkt)generic->set_32u,
223 (speed_test_fkt)optimized->set_32u, value, dest + x, x))
224 return FALSE;
225 }
226
227 return TRUE;
228}
229
230/* ------------------------------------------------------------------------- */
231static BOOL test_set32s_speed(void)
232{
233 INT32 dest[1024];
234 BYTE value = 0;
235
236 for (UINT32 x = 0; x < 16; x++)
237 {
238 if (winpr_RAND(&value, sizeof(value)) < 0)
239 return FALSE;
240
241 if (!speed_test("set_32s", "", g_Iterations, (speed_test_fkt)generic->set_32s,
242 (speed_test_fkt)optimized->set_32s, value, dest + x, x))
243 return FALSE;
244 }
245
246 return TRUE;
247}
248
249int TestPrimitivesSet(int argc, char* argv[])
250{
251 WINPR_UNUSED(argc);
252 WINPR_UNUSED(argv);
253 prim_test_setup(FALSE);
254
255 if (!test_set8u_func())
256 return -1;
257
258 if (!test_set32s_func())
259 return -1;
260
261 if (!test_set32u_func())
262 return -1;
263
264 if (g_TestPrimitivesPerformance)
265 {
266 if (!test_set8u_speed())
267 return -1;
268
269 if (!test_set32s_speed())
270 return -1;
271
272 if (!test_set32u_speed())
273 return -1;
274 }
275
276 return 0;
277}