webkit  2cdf99a9e3038c7e01b3c37e8ad903ecbe5eecf1
https://github.com/WebKit/webkit
unit_test.h
Go to the documentation of this file.
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 #ifndef SIMD_ALIGNED
26 #if defined(_MSC_VER) && !defined(__CLR_VER)
27 #define SIMD_ALIGNED(var) __declspec(align(16)) var
28 #elif defined(__GNUC__) && !defined(__pnacl__)
29 #define SIMD_ALIGNED(var) var __attribute__((aligned(16)))
30 #else
31 #define SIMD_ALIGNED(var) var
32 #endif
33 #endif
34 
35 static __inline int Abs(int v) {
36  return v >= 0 ? v : -v;
37 }
38 
39 #define OFFBY 0
40 
41 // Scaling uses 16.16 fixed point to step thru the source image, so a
42 // maximum size of 32767.999 can be expressed. 32768 is valid because
43 // the step is 1 beyond the image but not used.
44 // Destination size is mainly constrained by valid scale step not the
45 // absolute size, so it may be possible to relax the destination size
46 // constraint.
47 // Source size is unconstrained for most specialized scalers. e.g.
48 // An image of 65536 scaled to half size would be valid. The test
49 // could be relaxed for special scale factors.
50 // If this test is removed, the scaling function should gracefully
51 // fail with a return code. The test could be changed to know that
52 // libyuv failed in a controlled way.
53 
54 static const int kMaxWidth = 32768;
55 static const int kMaxHeight = 32768;
56 
57 static inline bool SizeValid(int src_width, int src_height,
58  int dst_width, int dst_height) {
59  if (src_width > kMaxWidth || src_height > kMaxHeight ||
60  dst_width > kMaxWidth || dst_height > kMaxHeight) {
61  printf("Warning - size too large to test. Skipping\n");
62  return false;
63  }
64  return true;
65 }
66 
67 #define align_buffer_page_end(var, size) \
68  uint8* var; \
69  uint8* var##_mem; \
70  var##_mem = reinterpret_cast<uint8*>(malloc(((size) + 4095 + 63) & ~4095)); \
71  var = (uint8*)((intptr_t)(var##_mem + (((size) + 4095 + 63) & ~4095) - \
72  (size)) & ~63);
73 
74 #define free_aligned_buffer_page_end(var) \
75  free(var##_mem); \
76  var = 0;
77 
78 #ifdef WIN32
79 static inline double get_time() {
80  LARGE_INTEGER t, f;
81  QueryPerformanceCounter(&t);
82  QueryPerformanceFrequency(&f);
83  return static_cast<double>(t.QuadPart) / static_cast<double>(f.QuadPart);
84 }
85 #else
86 static inline double get_time() {
87  struct timeval t;
88  struct timezone tzp;
89  gettimeofday(&t, &tzp);
90  return t.tv_sec + t.tv_usec * 1e-6;
91 }
92 #endif
93 
94 #ifndef SIMD_ALIGNED
95 #if defined(_MSC_VER) && !defined(__CLR_VER)
96 #define SIMD_ALIGNED(var) __declspec(align(16)) var
97 #elif defined(__GNUC__) && !defined(__pnacl__)
98 #define SIMD_ALIGNED(var) var __attribute__((aligned(16)))
99 #else
100 #define SIMD_ALIGNED(var) var
101 #endif
102 #endif
103 
104 extern unsigned int fastrand_seed;
105 inline int fastrand() {
106  fastrand_seed = fastrand_seed * 214013u + 2531011u;
107  return static_cast<int>((fastrand_seed >> 16) & 0xffff);
108 }
109 
110 static inline void MemRandomize(uint8* dst, int64 len) {
111  int64 i;
112  for (i = 0; i < len - 1; i += 2) {
113  *reinterpret_cast<uint16*>(dst) = fastrand();
114  dst += 2;
115  }
116  for (; i < len; ++i) {
117  *dst++ = fastrand();
118  }
119 }
120 
122  protected:
123  LibYUVColorTest();
124 
125  int benchmark_iterations_; // Default 1. Use 1000 for benchmarking.
126  int benchmark_width_; // Default 1280. Use 640 for benchmarking VGA.
127  int benchmark_height_; // Default 720. Use 360 for benchmarking VGA.
128  int benchmark_pixels_div256_; // Total pixels to benchmark / 256.
129  int benchmark_pixels_div1280_; // Total pixels to benchmark / 1280.
130  int disable_cpu_flags_; // Default 1. Use -1 for benchmarking.
131  int benchmark_cpu_info_; // Default -1. Use 1 to disable SIMD.
132 };
133 
135  protected:
137 
138  int benchmark_iterations_; // Default 1. Use 1000 for benchmarking.
139  int benchmark_width_; // Default 1280. Use 640 for benchmarking VGA.
140  int benchmark_height_; // Default 720. Use 360 for benchmarking VGA.
141  int benchmark_pixels_div256_; // Total pixels to benchmark / 256.
142  int benchmark_pixels_div1280_; // Total pixels to benchmark / 1280.
143  int disable_cpu_flags_; // Default 1. Use -1 for benchmarking.
144  int benchmark_cpu_info_; // Default -1. Use 1 to disable SIMD.
145 };
146 
148  protected:
149  LibYUVScaleTest();
150 
151  int benchmark_iterations_; // Default 1. Use 1000 for benchmarking.
152  int benchmark_width_; // Default 1280. Use 640 for benchmarking VGA.
153  int benchmark_height_; // Default 720. Use 360 for benchmarking VGA.
154  int benchmark_pixels_div256_; // Total pixels to benchmark / 256.
155  int benchmark_pixels_div1280_; // Total pixels to benchmark / 1280.
156  int disable_cpu_flags_; // Default 1. Use -1 for benchmarking.
157  int benchmark_cpu_info_; // Default -1. Use 1 to disable SIMD.
158 };
159 
161  protected:
163 
164  int benchmark_iterations_; // Default 1. Use 1000 for benchmarking.
165  int benchmark_width_; // Default 1280. Use 640 for benchmarking VGA.
166  int benchmark_height_; // Default 720. Use 360 for benchmarking VGA.
167  int benchmark_pixels_div256_; // Total pixels to benchmark / 256.
168  int benchmark_pixels_div1280_; // Total pixels to benchmark / 1280.
169  int disable_cpu_flags_; // Default 1. Use -1 for benchmarking.
170  int benchmark_cpu_info_; // Default -1. Use 1 to disable SIMD.
171 };
172 
174  protected:
176 
177  int benchmark_iterations_; // Default 1. Use 1000 for benchmarking.
178  int benchmark_width_; // Default 1280. Use 640 for benchmarking VGA.
179  int benchmark_height_; // Default 720. Use 360 for benchmarking VGA.
180  int benchmark_pixels_div256_; // Total pixels to benchmark / 256.
181  int benchmark_pixels_div1280_; // Total pixels to benchmark / 1280.
182  int disable_cpu_flags_; // Default 1. Use -1 for benchmarking.
183  int benchmark_cpu_info_; // Default -1. Use 1 to disable SIMD.
184 };
185 
187  protected:
188  LibYUVBaseTest();
189 
190  int benchmark_iterations_; // Default 1. Use 1000 for benchmarking.
191  int benchmark_width_; // Default 1280. Use 640 for benchmarking VGA.
192  int benchmark_height_; // Default 720. Use 360 for benchmarking VGA.
193  int benchmark_pixels_div256_; // Total pixels to benchmark / 256.
194  int benchmark_pixels_div1280_; // Total pixels to benchmark / 1280.
195  int disable_cpu_flags_; // Default 1. Use -1 for benchmarking.
196  int benchmark_cpu_info_; // Default -1. Use 1 to disable SIMD.
197 };
198 
199 #endif // UNIT_TEST_UNIT_TEST_H_ NOLINT
int benchmark_iterations_
Definition: unit_test.h:138
int benchmark_cpu_info_
Definition: unit_test.h:131
int benchmark_pixels_div1280_
Definition: unit_test.h:142
int benchmark_iterations_
Definition: unit_test.h:190
int benchmark_cpu_info_
Definition: unit_test.h:157
int benchmark_width_
Definition: unit_test.h:152
int benchmark_pixels_div1280_
Definition: unit_test.h:181
int benchmark_iterations_
Definition: unit_test.h:164
int benchmark_width_
Definition: unit_test.h:139
OPENSSL_EXPORT pem_password_cb void * u
Definition: pem.h:398
int benchmark_pixels_div256_
Definition: unit_test.h:128
bool t
Definition: UpdateContents.py:37
unsigned char uint8
Definition: basic_types.h:62
int benchmark_pixels_div1280_
Definition: unit_test.h:155
int dst_height
Definition: convert.cc:32
printf("{")
int benchmark_iterations_
Definition: unit_test.h:151
int benchmark_pixels_div1280_
Definition: unit_test.h:129
int benchmark_cpu_info_
Definition: unit_test.h:170
int benchmark_height_
Definition: unit_test.h:192
int64_t int64
Definition: angle_config.h:29
int benchmark_iterations_
Definition: unit_test.h:125
GLenum GLenum dst
Definition: gl2ext.h:304
OPENSSL_EXPORT const ASN1_OBJECT int const unsigned char int len
Definition: x509.h:1053
int benchmark_cpu_info_
Definition: unit_test.h:183
int benchmark_height_
Definition: unit_test.h:179
int benchmark_pixels_div256_
Definition: unit_test.h:141
int benchmark_pixels_div256_
Definition: unit_test.h:154
int benchmark_pixels_div256_
Definition: unit_test.h:193
int disable_cpu_flags_
Definition: unit_test.h:143
int benchmark_cpu_info_
Definition: unit_test.h:196
int disable_cpu_flags_
Definition: unit_test.h:195
int disable_cpu_flags_
Definition: unit_test.h:169
int benchmark_width_
Definition: unit_test.h:165
int benchmark_width_
Definition: unit_test.h:126
unsigned int fastrand_seed
Definition: unit_test.cc:23
Definition: unit_test.h:160
GLfloat f
Definition: gl2.h:417
const GLfloat * v
Definition: gl2.h:514
int fastrand()
Definition: unit_test.h:105
int benchmark_height_
Definition: unit_test.h:127
int benchmark_pixels_div1280_
Definition: unit_test.h:194
Definition: unit_test.h:121
int benchmark_height_
Definition: unit_test.h:166
Definition: gtest.h:341
int dst_width
Definition: convert.cc:32
int disable_cpu_flags_
Definition: unit_test.h:156
Definition: unit_test.h:147
for i
Definition: complexityMeasures.m:24
unsigned short uint16
Definition: basic_types.h:60
int benchmark_width_
Definition: unit_test.h:191
Definition: unit_test.h:186
LibYUVColorTest()
Definition: unit_test.cc:89
int benchmark_iterations_
Definition: unit_test.h:177
int disable_cpu_flags_
Definition: unit_test.h:130
int benchmark_height_
Definition: unit_test.h:153
int benchmark_pixels_div256_
Definition: unit_test.h:180
DOMString e
Definition: WebCryptoAPI.idl:115
int benchmark_pixels_div256_
Definition: unit_test.h:167
Definition: unit_test.h:173
int benchmark_width_
Definition: unit_test.h:178
int benchmark_pixels_div1280_
Definition: unit_test.h:168
Definition: unit_test.h:134
int benchmark_cpu_info_
Definition: unit_test.h:144
int benchmark_height_
Definition: unit_test.h:140
int disable_cpu_flags_
Definition: unit_test.h:182