~ubuntu-branches/ubuntu/vivid/freerdp/vivid

« back to all changes in this revision

Viewing changes to libfreerdp/primitives/test/prim_test.c

  • Committer: Package Import Robot
  • Author(s): Iain Lane
  • Date: 2014-11-11 12:20:50 UTC
  • mfrom: (1.1.9) (9.1.17 sid)
  • Revision ID: package-import@ubuntu.com-20141111122050-wyr8hrnwco9fcmum
Tags: 1.1.0~git20140921.1.440916e+dfsg1-2ubuntu1
* Merge with Debian unstable, remaining changes
  - Disable ffmpeg support
* Disable gstreamer support, this relies on gstreamer 0.10 and we don't want
  to add any more deps on that.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* prim_test.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
#ifdef HAVE_CONFIG_H
 
16
#include "config.h"
 
17
#endif
 
18
 
 
19
#include "prim_test.h"
 
20
 
 
21
#include <sys/types.h>
 
22
#include <sys/stat.h>
 
23
#include <fcntl.h>
 
24
#include <winpr/platform.h>
 
25
#include <winpr/sysinfo.h>
 
26
 
 
27
#ifdef HAVE_UNISTD_H
 
28
#include <unistd.h>
 
29
#endif
 
30
 
 
31
#include <stdlib.h>
 
32
#include <time.h>
 
33
 
 
34
int test_sizes[] = { 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096 };
 
35
int Quiet = 0;
 
36
 
 
37
 
 
38
 
 
39
/* ------------------------------------------------------------------------- */
 
40
typedef struct
 
41
{
 
42
        UINT32  flag;
 
43
        const char *str;
 
44
} flagpair_t;
 
45
 
 
46
static const flagpair_t flags[] =
 
47
{
 
48
#ifdef _M_IX86_AMD64
 
49
        { PF_MMX_INSTRUCTIONS_AVAILABLE,                "MMX" },
 
50
        { PF_3DNOW_INSTRUCTIONS_AVAILABLE,              "3DNow" },
 
51
        { PF_SSE_INSTRUCTIONS_AVAILABLE,                "SSE" },
 
52
        { PF_SSE2_INSTRUCTIONS_AVAILABLE,               "SSE2" },
 
53
        { PF_SSE3_INSTRUCTIONS_AVAILABLE,               "SSE3" },
 
54
#elif defined(_M_ARM)
 
55
        { PF_ARM_VFP3,                                                  "VFP3" },
 
56
        { PF_ARM_INTEL_WMMX,                                    "IWMMXT" },
 
57
        { PF_ARM_NEON_INSTRUCTIONS_AVAILABLE,   "NEON" },
 
58
#endif
 
59
};
 
60
 
 
61
static const flagpair_t flags_extended[] =
 
62
{
 
63
#ifdef _M_IX86_AMD64
 
64
        { PF_EX_3DNOW_PREFETCH,     "3DNow-PF" },
 
65
        { PF_EX_SSSE3,                          "SSSE3" },
 
66
        { PF_EX_SSE41,                          "SSE4.1" },
 
67
        { PF_EX_SSE42,                          "SSE4.2" },
 
68
        { PF_EX_AVX,                            "AVX" },
 
69
        { PF_EX_FMA,                            "FMA" },
 
70
        { PF_EX_AVX_AES,                        "AVX-AES" },
 
71
        { PF_EX_AVX2,                           "AVX2" },
 
72
#elif defined(_M_ARM)
 
73
        { PF_EX_ARM_VFP1,                       "VFP1"},
 
74
        { PF_EX_ARM_VFP4,                       "VFP4" },
 
75
#endif
 
76
};
 
77
 
 
78
void primitives_flags_str(char* str, size_t len)
 
79
{
 
80
        int i;
 
81
 
 
82
        *str = '\0';
 
83
        --len;  /* for the '/0' */
 
84
 
 
85
        for (i = 0; i < sizeof(flags) / sizeof(flagpair_t); ++i)
 
86
        {
 
87
                if (IsProcessorFeaturePresent(flags[i].flag))
 
88
                {
 
89
                        int slen = strlen(flags[i].str) + 1;
 
90
 
 
91
                        if (len < slen)
 
92
                                break;
 
93
 
 
94
                        if (*str != '\0')
 
95
                                strcat(str, " ");
 
96
 
 
97
                        strcat(str, flags[i].str);
 
98
                        len -= slen;
 
99
                }
 
100
        }
 
101
        for (i = 0; i < sizeof(flags_extended) / sizeof(flagpair_t); ++i)
 
102
        {
 
103
                if (IsProcessorFeaturePresentEx(flags_extended[i].flag))
 
104
                {
 
105
                        int slen = strlen(flags_extended[i].str) + 1;
 
106
 
 
107
                        if (len < slen)
 
108
                                break;
 
109
 
 
110
                        if (*str != '\0')
 
111
                                strcat(str, " ");
 
112
 
 
113
                        strcat(str, flags_extended[i].str);
 
114
                        len -= slen;
 
115
                }
 
116
        }
 
117
}
 
118
 
 
119
/* ------------------------------------------------------------------------- */
 
120
static void get_random_data_lrand(
 
121
    void *buffer,
 
122
    size_t size)
 
123
{
 
124
        static int seeded = 0;
 
125
        long int *ptr = (long int *) buffer;
 
126
        unsigned char *cptr;
 
127
 
 
128
        if (!seeded)
 
129
        {
 
130
                seeded = 1;
 
131
                srand48(time(NULL));
 
132
        }
 
133
        /* This isn't the perfect random number generator, but that's okay. */
 
134
        while (size >= sizeof(long int))
 
135
        {
 
136
                *ptr++ = lrand48();
 
137
                size -= sizeof(long int);
 
138
        }
 
139
        cptr = (unsigned char *) ptr;
 
140
        while (size > 0)
 
141
        {
 
142
                *cptr++ = lrand48() & 0xff;
 
143
                --size;
 
144
        }
 
145
}
 
146
 
 
147
/* ------------------------------------------------------------------------- */
 
148
void get_random_data(
 
149
    void *buffer,
 
150
    size_t size)
 
151
{
 
152
#ifdef linux
 
153
        size_t offset = 0;
 
154
        int fd = open("/dev/urandom", O_RDONLY);
 
155
        if (fd < 0)
 
156
        {
 
157
                get_random_data_lrand(buffer, size);
 
158
                return;
 
159
        }
 
160
 
 
161
        while (size > 0)
 
162
        {
 
163
                ssize_t count = read(fd, buffer+offset, size);
 
164
                size -= count;
 
165
                offset += count;
 
166
        }
 
167
        close(fd);
 
168
#else
 
169
        get_random_data_lrand(buffer, size);
 
170
#endif
 
171
}
 
172
 
 
173
/* ------------------------------------------------------------------------- */
 
174
float _delta_time(
 
175
    const struct timespec *t0,
 
176
    const struct timespec *t1)
 
177
{
 
178
    INT64 secs = (INT64) (t1->tv_sec) - (INT64) (t0->tv_sec);
 
179
    long   nsecs = t1->tv_nsec - t0->tv_nsec;
 
180
        double retval;
 
181
 
 
182
    if (nsecs < 0)
 
183
        {
 
184
        --secs;
 
185
        nsecs += 1000000000;
 
186
    }
 
187
    retval = (double) secs + (double) nsecs / (double) 1000000000.0;
 
188
    return (retval < 0.0) ? 0.0 : (float) retval;
 
189
}
 
190
 
 
191
/* ------------------------------------------------------------------------- */
 
192
void _floatprint(
 
193
    float t,
 
194
    char *output)
 
195
{
 
196
    /* I don't want to link against -lm, so avoid log,exp,... */
 
197
    float f = 10.0;
 
198
        int i;
 
199
    while (t > f) f *= 10.0;
 
200
    f /= 1000.0;
 
201
    i = ((int) (t/f+0.5)) * (int) f;
 
202
    if (t < 0.0) sprintf(output, "%f", t);
 
203
    else if (i == 0) sprintf(output, "%d", (int) (t+0.5));
 
204
    else if (t < 1e+3) sprintf(output, "%3d", i);
 
205
    else if (t < 1e+6) sprintf(output, "%3d,%03d",     
 
206
                i/1000, i % 1000);
 
207
    else if (t < 1e+9) sprintf(output, "%3d,%03d,000", 
 
208
                i/1000000, (i % 1000000) / 1000);
 
209
    else if (t < 1e+12) sprintf(output, "%3d,%03d,000,000", 
 
210
                i/1000000000, (i % 1000000000) / 1000000);
 
211
    else sprintf(output, "%f", t);
 
212
}
 
213
 
 
214
/* ------------------------------------------------------------------------- */
 
215
/* Specific areas to test: */
 
216
#define TEST_COPY8                      (1<<0)
 
217
#define TEST_SET8                       (1<<1)
 
218
#define TEST_SET32S                     (1<<2)
 
219
#define TEST_SET32U                     (1<<3)
 
220
#define TEST_SIGN16S                    (1<<4)
 
221
#define TEST_ADD16S                     (1<<5)
 
222
#define TEST_LSHIFT16S                  (1<<6)
 
223
#define TEST_LSHIFT16U                  (1<<7)
 
224
#define TEST_RSHIFT16S                  (1<<8)
 
225
#define TEST_RSHIFT16U                  (1<<9)
 
226
#define TEST_RGB                        (1<<10)
 
227
#define TEST_ALPHA                      (1<<11)
 
228
#define TEST_AND                        (1<<12)
 
229
#define TEST_OR                         (1<<13)
 
230
 
 
231
/* Specific types of testing: */
 
232
#define TEST_FUNCTIONALITY              (1<<0)
 
233
#define TEST_PERFORMANCE                (1<<1)
 
234
 
 
235
/* ------------------------------------------------------------------------- */
 
236
 
 
237
typedef struct
 
238
{
 
239
        const char *testStr;
 
240
        UINT32 bits;
 
241
} test_t;
 
242
 
 
243
static const test_t testList[] =
 
244
{
 
245
        { "all",                0xFFFFFFFFU },
 
246
        { "copy",               TEST_COPY8 },
 
247
        { "copy8",              TEST_COPY8 },
 
248
        { "set",                TEST_SET8|TEST_SET32S|TEST_SET32U },
 
249
        { "set8",               TEST_SET8 },
 
250
        { "set32",              TEST_SET32S|TEST_SET32U },
 
251
        { "set32s",             TEST_SET32S },
 
252
        { "set32u",             TEST_SET32U },
 
253
        { "sign",               TEST_SIGN16S },
 
254
        { "sign16s",            TEST_SIGN16S },
 
255
        { "add",                TEST_ADD16S },
 
256
        { "add16s",             TEST_ADD16S },
 
257
        { "lshift",             TEST_LSHIFT16S|TEST_LSHIFT16U },
 
258
        { "rshift",             TEST_RSHIFT16S|TEST_RSHIFT16U },
 
259
        { "shift",              TEST_LSHIFT16S|TEST_LSHIFT16U|TEST_RSHIFT16S|TEST_RSHIFT16U },
 
260
        { "lshift16s",          TEST_LSHIFT16S },
 
261
        { "lshift16u",          TEST_LSHIFT16U },
 
262
        { "rshift16s",          TEST_RSHIFT16S },
 
263
        { "rshift16u",          TEST_RSHIFT16U },
 
264
        { "rgb",                TEST_RGB },
 
265
        { "color",              TEST_RGB },
 
266
        { "colors",             TEST_RGB },
 
267
        { "alpha",              TEST_ALPHA },
 
268
        { "and",                TEST_AND },
 
269
        { "or",                 TEST_OR }
 
270
};
 
271
 
 
272
#define NUMTESTS (sizeof(testList)/sizeof(test_t))
 
273
 
 
274
static const test_t testTypeList[] =
 
275
{
 
276
        { "functionality",      TEST_FUNCTIONALITY },
 
277
        { "performance",        TEST_PERFORMANCE },
 
278
};
 
279
 
 
280
#define NUMTESTTYPES (sizeof(testTypeList)/sizeof(test_t))
 
281
 
 
282
int main(int argc, char** argv)
 
283
{
 
284
        int i;
 
285
        char hints[1024];
 
286
        UINT32 testSet = 0;
 
287
        UINT32 testTypes = 0;
 
288
        int results = SUCCESS;
 
289
 
 
290
        /* Parse command line for the test set. */
 
291
 
 
292
        for (i = 1; i < argc; ++i)
 
293
        {
 
294
                int j;
 
295
                BOOL found = 0;
 
296
 
 
297
                for (j=0; j<NUMTESTS; ++j)
 
298
                {
 
299
                        if (strcasecmp(argv[i], testList[j].testStr) == 0)
 
300
                        {
 
301
                                testSet |= testList[j].bits;
 
302
                                found = 1;
 
303
                                break;
 
304
                        }
 
305
                }
 
306
                for (j=0; j<NUMTESTTYPES; ++j)
 
307
                {
 
308
                        if (strcasecmp(argv[i], testTypeList[j].testStr) == 0)
 
309
                        {
 
310
                                testTypes |= testTypeList[j].bits;
 
311
                                found = 1;
 
312
                                break;
 
313
                        }
 
314
                }
 
315
                if (!found)
 
316
                {
 
317
                        if (strstr(argv[i], "help") != NULL)
 
318
                        {
 
319
                                printf("Available tests:\n");
 
320
                                for (j=0; j<NUMTESTS; ++j)
 
321
                                {
 
322
                                        printf("  %s\n", testList[j].testStr);
 
323
                                }
 
324
                                for (j=0; j<NUMTESTTYPES; ++j)
 
325
                                {
 
326
                                        printf("  %s\n", testTypeList[j].testStr);
 
327
                                }
 
328
                        }
 
329
                        else fprintf(stderr, "Unknown parameter '%s'!\n", argv[i]);
 
330
                }
 
331
        }
 
332
 
 
333
        if (testSet == 0)
 
334
                testSet = 0xffffffff;
 
335
        if (testTypes == 0)
 
336
                testTypes = 0xffffffff;
 
337
 
 
338
        primitives_init();
 
339
 
 
340
        primitives_flags_str(hints, sizeof(hints));
 
341
        printf("Hints: %s\n", hints);
 
342
 
 
343
        /* COPY */
 
344
        if (testSet & TEST_COPY8)
 
345
        {
 
346
                if (testTypes & TEST_FUNCTIONALITY)
 
347
                {
 
348
                        results |= test_copy8u_func();
 
349
                }
 
350
                if (testTypes & TEST_PERFORMANCE)
 
351
                {
 
352
                        results |= test_copy8u_speed();
 
353
                }
 
354
        }
 
355
        /* SET */
 
356
        if (testSet & TEST_SET8)
 
357
        {
 
358
                if (testTypes & TEST_FUNCTIONALITY)
 
359
                {
 
360
                        results |= test_set8u_func();
 
361
                }
 
362
                if (testTypes & TEST_PERFORMANCE)
 
363
                {
 
364
                        results |= test_set8u_speed();
 
365
                }
 
366
        }
 
367
        if (testSet & TEST_SET32S)
 
368
        {
 
369
                if (testTypes & TEST_FUNCTIONALITY)
 
370
                {
 
371
                        results |= test_set32s_func();
 
372
                }
 
373
                if (testTypes & TEST_PERFORMANCE)
 
374
                {
 
375
                        results |= test_set32s_speed();
 
376
                }
 
377
        }
 
378
        if (testSet & TEST_SET32U)
 
379
        {
 
380
                if (testTypes & TEST_FUNCTIONALITY)
 
381
                {
 
382
                        results |= test_set32u_func();
 
383
                }
 
384
                if (testTypes & TEST_PERFORMANCE)
 
385
                {
 
386
                        results |= test_set32u_speed();
 
387
                }
 
388
        }
 
389
        /* SIGN */
 
390
        if (testSet & TEST_SIGN16S)
 
391
        {
 
392
                if (testTypes & TEST_FUNCTIONALITY)
 
393
                {
 
394
                        results |= test_sign16s_func();
 
395
                }
 
396
                if (testTypes & TEST_PERFORMANCE)
 
397
                {
 
398
                        results |= test_sign16s_speed();
 
399
                }
 
400
        }
 
401
        /* ADD */
 
402
        if (testSet & TEST_ADD16S)
 
403
        {
 
404
                if (testTypes & TEST_FUNCTIONALITY)
 
405
                {
 
406
                        results |= test_add16s_func();
 
407
                }
 
408
                if (testTypes & TEST_PERFORMANCE)
 
409
                {
 
410
                        results |= test_add16s_speed();
 
411
                }
 
412
        }
 
413
        /* SHIFTS */
 
414
        if (testSet & TEST_LSHIFT16S)
 
415
        {
 
416
                if (testTypes & TEST_FUNCTIONALITY)
 
417
                {
 
418
                        results |= test_lShift_16s_func();
 
419
                }
 
420
                if (testTypes & TEST_PERFORMANCE)
 
421
                {
 
422
                        results |= test_lShift_16s_speed();
 
423
                }
 
424
        }
 
425
        if (testSet & TEST_LSHIFT16U)
 
426
        {
 
427
                if (testTypes & TEST_FUNCTIONALITY)
 
428
                {
 
429
                        results |= test_lShift_16u_func();
 
430
                }
 
431
                if (testTypes & TEST_PERFORMANCE)
 
432
                {
 
433
                        results |= test_lShift_16u_speed();
 
434
                }
 
435
        }
 
436
        if (testSet & TEST_RSHIFT16S)
 
437
        {
 
438
                if (testTypes & TEST_FUNCTIONALITY)
 
439
                {
 
440
                        results |= test_rShift_16s_func();
 
441
                }
 
442
                if (testTypes & TEST_PERFORMANCE)
 
443
                {
 
444
                        results |= test_rShift_16s_speed();
 
445
                }
 
446
        }
 
447
        if (testSet & TEST_RSHIFT16U)
 
448
        {
 
449
                if (testTypes & TEST_FUNCTIONALITY)
 
450
                {
 
451
                        results |= test_rShift_16u_func();
 
452
                }
 
453
                if (testTypes & TEST_PERFORMANCE)
 
454
                {
 
455
                        results |= test_rShift_16u_speed();
 
456
                }
 
457
        }
 
458
        /* COLORS */
 
459
        if (testSet & TEST_RGB)
 
460
        {
 
461
                if (testTypes & TEST_FUNCTIONALITY)
 
462
                {
 
463
                        results |= test_RGBToRGB_16s8u_P3AC4R_func();
 
464
                }
 
465
                if (testTypes & TEST_PERFORMANCE)
 
466
                {
 
467
                        results |= test_RGBToRGB_16s8u_P3AC4R_speed();
 
468
                }
 
469
                if (testTypes & TEST_FUNCTIONALITY)
 
470
                {
 
471
                        results |= test_yCbCrToRGB_16s16s_P3P3_func();
 
472
                }
 
473
                if (testTypes & TEST_PERFORMANCE)
 
474
                {
 
475
                        results |= test_yCbCrToRGB_16s16s_P3P3_speed();
 
476
                }
 
477
        }
 
478
        /* ALPHA COMPOSITION */
 
479
        if (testSet & TEST_ALPHA)
 
480
        {
 
481
                if (testTypes & TEST_FUNCTIONALITY)
 
482
                {
 
483
                        results |= test_alphaComp_func();
 
484
                }
 
485
                if (testTypes & TEST_PERFORMANCE)
 
486
                {
 
487
                        results |= test_alphaComp_speed();
 
488
                }
 
489
        }
 
490
        /* AND & OR */
 
491
        if (testSet & TEST_AND)
 
492
        {
 
493
                if (testTypes & TEST_FUNCTIONALITY)
 
494
                {
 
495
                        results |= test_and_32u_func();
 
496
                }
 
497
                if (testTypes & TEST_PERFORMANCE)
 
498
                {
 
499
                        results |= test_and_32u_speed();
 
500
                }
 
501
        }
 
502
        if (testSet & TEST_OR)
 
503
        {
 
504
                if (testTypes & TEST_FUNCTIONALITY)
 
505
                {
 
506
                        results |= test_or_32u_func();
 
507
                }
 
508
                if (testTypes & TEST_PERFORMANCE)
 
509
                {
 
510
                        results |= test_or_32u_speed();
 
511
                }
 
512
        }
 
513
 
 
514
        primitives_deinit();
 
515
        return results;
 
516
}