FreeRDP
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
TestPrimitivesSign.c
1/* test_sign.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#define TEST_BUFFER_SIZE 65535
21
22/* ------------------------------------------------------------------------- */
23static BOOL test_sign16s_func(void)
24{
25 pstatus_t status = 0;
26 INT16 ALIGN(src[TEST_BUFFER_SIZE + 16]) = { 0 };
27 INT16 ALIGN(d1[TEST_BUFFER_SIZE + 16]) = { 0 };
28 INT16 ALIGN(d2[TEST_BUFFER_SIZE + 16]) = { 0 };
29 winpr_RAND(src, sizeof(src));
30 status = generic->sign_16s(src + 1, d1 + 1, TEST_BUFFER_SIZE);
31
32 if (status != PRIMITIVES_SUCCESS)
33 return FALSE;
34
35 status = optimized->sign_16s(src + 1, d2 + 1, TEST_BUFFER_SIZE);
36
37 if (status != PRIMITIVES_SUCCESS)
38 return FALSE;
39
40 if (memcmp(d1, d2, sizeof(d1)) != 0)
41 return FALSE;
42
43 status = generic->sign_16s(src + 1, d1 + 2, TEST_BUFFER_SIZE);
44
45 if (status != PRIMITIVES_SUCCESS)
46 return FALSE;
47
48 status = optimized->sign_16s(src + 1, d2 + 2, TEST_BUFFER_SIZE);
49
50 if (status != PRIMITIVES_SUCCESS)
51 return FALSE;
52
53 if (memcmp(d1, d2, sizeof(d1)) != 0)
54 return FALSE;
55
56 return TRUE;
57}
58
59static int test_sign16s_speed(void)
60{
61 INT16 ALIGN(src[MAX_TEST_SIZE + 3]) = { 0 };
62 INT16 ALIGN(dst[MAX_TEST_SIZE + 3]) = { 0 };
63 winpr_RAND(src, sizeof(src));
64
65 if (!speed_test("sign16s", "aligned", g_Iterations, (speed_test_fkt)generic->sign_16s,
66 (speed_test_fkt)optimized->sign_16s, src + 1, dst + 1, MAX_TEST_SIZE))
67 return FALSE;
68
69 if (!speed_test("sign16s", "unaligned", g_Iterations, (speed_test_fkt)generic->sign_16s,
70 (speed_test_fkt)optimized->sign_16s, src + 1, dst + 2, MAX_TEST_SIZE))
71 return FALSE;
72
73 return TRUE;
74}
75
76int TestPrimitivesSign(int argc, char* argv[])
77{
78 WINPR_UNUSED(argc);
79 WINPR_UNUSED(argv);
80
81 prim_test_setup(FALSE);
82
83 if (!test_sign16s_func())
84 return 1;
85
86 if (g_TestPrimitivesPerformance)
87 {
88 if (!test_sign16s_speed())
89 return 1;
90 }
91
92 return 0;
93}