Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / libyuv / unit_test / unit_test.h
1 /*
2  *  Copyright 2011 The LibYuv Project Authors. All rights reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS. All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10
11 #ifndef UNIT_TEST_UNIT_TEST_H_  // NOLINT
12 #define UNIT_TEST_UNIT_TEST_H_
13
14 #ifdef WIN32
15 #include <windows.h>
16 #else
17 #include <sys/time.h>
18 #include <sys/resource.h>
19 #endif
20
21 #include <gtest/gtest.h>
22
23 #include "libyuv/basic_types.h"
24
25 static __inline int Abs(int v) {
26   return v >= 0 ? v : -v;
27 }
28
29 #define OFFBY 0
30
31 #define align_buffer_page_end(var, size)                                       \
32   uint8* var;                                                                  \
33   uint8* var##_mem;                                                            \
34   var##_mem = reinterpret_cast<uint8*>(malloc((((size) + 4095) & ~4095) +      \
35       OFFBY));                                                                 \
36   var = var##_mem + (-(size) & 4095) + OFFBY;
37
38 #define free_aligned_buffer_page_end(var) \
39   free(var##_mem);  \
40   var = 0;
41
42 #ifdef WIN32
43 static inline double get_time() {
44   LARGE_INTEGER t, f;
45   QueryPerformanceCounter(&t);
46   QueryPerformanceFrequency(&f);
47   return static_cast<double>(t.QuadPart) / static_cast<double>(f.QuadPart);
48 }
49
50 #define random rand
51 #define srandom srand
52 #else
53 static inline double get_time() {
54   struct timeval t;
55   struct timezone tzp;
56   gettimeofday(&t, &tzp);
57   return t.tv_sec + t.tv_usec * 1e-6;
58 }
59 #endif
60
61 static inline void MemRandomize(uint8* dst, int len) {
62   int i;
63   for (i = 0; i < len - 1; i += 2) {
64     *reinterpret_cast<uint16*>(dst) = random();
65     dst += 2;
66   }
67   for (; i < len; ++i) {
68     *dst++ = random();
69   }
70 }
71
72 class libyuvTest : public ::testing::Test {
73  protected:
74   libyuvTest();
75
76   const int rotate_max_w_;
77   const int rotate_max_h_;
78
79   int benchmark_iterations_;  // Default 1. Use 1000 for benchmarking.
80   int benchmark_width_;  // Default 1280.  Use 640 for benchmarking VGA.
81   int benchmark_height_;  // Default 720.  Use 360 for benchmarking VGA.
82   int benchmark_pixels_div256_;  // Total pixels to benchmark / 256.
83   int benchmark_pixels_div1280_;  // Total pixels to benchmark / 1280.
84 };
85
86 #endif  // UNIT_TEST_UNIT_TEST_H_  NOLINT