FreeRDP
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
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 winpr_RAND(&value, sizeof(value));
87
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))
90 return FALSE;
91 }
92
93 return TRUE;
94}
95
96static BOOL check32s(const INT32* src, UINT32 length, UINT32 offset, INT32 value)
97{
98 for (UINT32 i = 0; i < length; ++i)
99 {
100 if (src[offset + i] != value)
101 {
102 printf("SET8U FAILED: off=%" PRIu32 " len=%" PRIu32 " dest[%" PRIu32 "]=0x%08" PRIx32
103 "\n",
104 offset, length, i + offset, src[i + offset]);
105 return FALSE;
106 }
107 }
108
109 return TRUE;
110}
111
112/* ------------------------------------------------------------------------- */
113static BOOL test_set32s_func(void)
114{
115 pstatus_t status = 0;
116 const INT32 value = -0x12345678;
117
118 for (UINT32 off = 0; off < 16; ++off)
119 {
120 INT32 dest[1024] = { 0 };
121
122 for (UINT32 len = 1; len < 48 - off; ++len)
123 {
124 status = generic->set_32s(value, dest + off, len);
125
126 if (status != PRIMITIVES_SUCCESS)
127 return FALSE;
128
129 if (!check32s(dest, len, off, value))
130 return FALSE;
131 }
132 }
133
134 for (UINT32 off = 0; off < 16; ++off)
135 {
136 INT32 dest[1024] = { 0 };
137
138 for (UINT32 len = 1; len < 48 - off; ++len)
139 {
140 status = optimized->set_32s(value, dest + off, len);
141
142 if (status != PRIMITIVES_SUCCESS)
143 return FALSE;
144
145 if (!check32s(dest, len, off, value))
146 return FALSE;
147 }
148 }
149
150 return TRUE;
151}
152
153static BOOL check32u(const UINT32* src, UINT32 length, UINT32 offset, UINT32 value)
154{
155 for (UINT32 i = 0; i < length; ++i)
156 {
157 if (src[offset + i] != value)
158 {
159 printf("SET8U FAILED: off=%" PRIu32 " len=%" PRIu32 " dest[%" PRIu32 "]=0x%08" PRIx32
160 "\n",
161 offset, length, i + offset, src[i + offset]);
162 return FALSE;
163 }
164 }
165
166 return TRUE;
167}
168
169/* ------------------------------------------------------------------------- */
170static BOOL test_set32u_func(void)
171{
172 pstatus_t status = 0;
173 const UINT32 value = 0xABCDEF12;
174
175 for (UINT32 off = 0; off < 16; ++off)
176 {
177 UINT32 dest[1024] = { 0 };
178
179 for (UINT32 len = 1; len < 48 - off; ++len)
180 {
181 status = generic->set_32u(value, dest + off, len);
182
183 if (status != PRIMITIVES_SUCCESS)
184 return FALSE;
185
186 if (!check32u(dest, len, off, value))
187 return FALSE;
188 }
189 }
190
191 for (UINT32 off = 0; off < 16; ++off)
192 {
193 UINT32 dest[1024] = { 0 };
194
195 for (UINT32 len = 1; len < 48 - off; ++len)
196 {
197 status = optimized->set_32u(value, dest + off, len);
198
199 if (status != PRIMITIVES_SUCCESS)
200 return FALSE;
201
202 if (!check32u(dest, len, off, value))
203 return FALSE;
204 }
205 }
206
207 return TRUE;
208}
209
210/* ------------------------------------------------------------------------- */
211static BOOL test_set32u_speed(void)
212{
213 UINT32 dest[1024];
214 BYTE value = 0;
215
216 for (UINT32 x = 0; x < 16; x++)
217 {
218 winpr_RAND(&value, sizeof(value));
219
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))
222 return FALSE;
223 }
224
225 return TRUE;
226}
227
228/* ------------------------------------------------------------------------- */
229static BOOL test_set32s_speed(void)
230{
231 INT32 dest[1024];
232 BYTE value = 0;
233
234 for (UINT32 x = 0; x < 16; x++)
235 {
236 winpr_RAND(&value, sizeof(value));
237
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))
240 return FALSE;
241 }
242
243 return TRUE;
244}
245
246int TestPrimitivesSet(int argc, char* argv[])
247{
248 WINPR_UNUSED(argc);
249 WINPR_UNUSED(argv);
250 prim_test_setup(FALSE);
251
252 if (!test_set8u_func())
253 return -1;
254
255 if (!test_set32s_func())
256 return -1;
257
258 if (!test_set32u_func())
259 return -1;
260
261 if (g_TestPrimitivesPerformance)
262 {
263 if (!test_set8u_speed())
264 return -1;
265
266 if (!test_set32s_speed())
267 return -1;
268
269 if (!test_set32u_speed())
270 return -1;
271 }
272
273 return 0;
274}