xref: /aosp_15_r20/external/libyuv/unit_test/unit_test.cc (revision 4e366538070a3a6c5c163c31b791eab742e1657a)
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 #include "../unit_test/unit_test.h"
12 
13 #include <stdlib.h>  // For getenv()
14 
15 #include <cstring>
16 
17 #ifdef LIBYUV_USE_ABSL_FLAGS
18 #include "absl/flags/flag.h"
19 #include "absl/flags/parse.h"
20 #endif
21 #include "libyuv/cpu_id.h"
22 
23 unsigned int fastrand_seed = 0xfb;
24 
25 #ifdef LIBYUV_USE_ABSL_FLAGS
26 ABSL_FLAG(int32_t, libyuv_width, 0, "width of test image.");
27 ABSL_FLAG(int32_t, libyuv_height, 0, "height of test image.");
28 ABSL_FLAG(int32_t, libyuv_repeat, 0, "number of times to repeat test.");
29 ABSL_FLAG(int32_t,
30           libyuv_flags,
31           0,
32           "cpu flags for reference code. 1 = C, -1 = SIMD");
33 ABSL_FLAG(int32_t,
34           libyuv_cpu_info,
35           0,
36           "cpu flags for benchmark code. 1 = C, -1 = SIMD");
37 #else
38 // Disable command line parameters if absl/flags disabled.
39 static const int32_t FLAGS_libyuv_width = 0;
40 static const int32_t FLAGS_libyuv_height = 0;
41 static const int32_t FLAGS_libyuv_repeat = 0;
42 static const int32_t FLAGS_libyuv_flags = 0;
43 static const int32_t FLAGS_libyuv_cpu_info = 0;
44 #endif
45 
46 #ifdef LIBYUV_USE_ABSL_FLAGS
47 #define LIBYUV_GET_FLAG(f) absl::GetFlag(f)
48 #else
49 #define LIBYUV_GET_FLAG(f) f
50 #endif
51 
52 // Test environment variable for disabling CPU features. Any non-zero value
53 // to disable. Zero ignored to make it easy to set the variable on/off.
54 #if !defined(__native_client__) && !defined(_M_ARM)
TestEnv(const char * name)55 static LIBYUV_BOOL TestEnv(const char* name) {
56   const char* var = getenv(name);
57   if (var) {
58     if (var[0] != '0') {
59       return LIBYUV_TRUE;
60     }
61   }
62   return LIBYUV_FALSE;
63 }
64 #else  // nacl does not support getenv().
TestEnv(const char *)65 static LIBYUV_BOOL TestEnv(const char*) {
66   return LIBYUV_FALSE;
67 }
68 #endif
69 
TestCpuEnv(int cpu_info)70 int TestCpuEnv(int cpu_info) {
71 #if defined(__arm__) || defined(__aarch64__)
72   if (TestEnv("LIBYUV_DISABLE_NEON")) {
73     cpu_info &= ~libyuv::kCpuHasNEON;
74   }
75 #endif
76 #if defined(__mips__) && defined(__linux__)
77   if (TestEnv("LIBYUV_DISABLE_MSA")) {
78     cpu_info &= ~libyuv::kCpuHasMSA;
79   }
80 #endif
81 #if defined(__longarch__) && defined(__linux__)
82   if (TestEnv("LIBYUV_DISABLE_LSX")) {
83     cpu_info &= ~libyuv::kCpuHasLSX;
84   }
85 #endif
86 #if defined(__longarch__) && defined(__linux__)
87   if (TestEnv("LIBYUV_DISABLE_LASX")) {
88     cpu_info &= ~libyuv::kCpuHasLASX;
89   }
90 #endif
91 #if defined(__riscv) && defined(__linux__)
92   if (TestEnv("LIBYUV_DISABLE_RVV")) {
93     cpu_info &= ~libyuv::kCpuHasRVV;
94   }
95 #endif
96 #if !defined(__pnacl__) && !defined(__CLR_VER) &&                   \
97     (defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || \
98      defined(_M_IX86))
99   if (TestEnv("LIBYUV_DISABLE_X86")) {
100     cpu_info &= ~libyuv::kCpuHasX86;
101   }
102   if (TestEnv("LIBYUV_DISABLE_SSE2")) {
103     cpu_info &= ~libyuv::kCpuHasSSE2;
104   }
105   if (TestEnv("LIBYUV_DISABLE_SSSE3")) {
106     cpu_info &= ~libyuv::kCpuHasSSSE3;
107   }
108   if (TestEnv("LIBYUV_DISABLE_SSE41")) {
109     cpu_info &= ~libyuv::kCpuHasSSE41;
110   }
111   if (TestEnv("LIBYUV_DISABLE_SSE42")) {
112     cpu_info &= ~libyuv::kCpuHasSSE42;
113   }
114   if (TestEnv("LIBYUV_DISABLE_AVX")) {
115     cpu_info &= ~libyuv::kCpuHasAVX;
116   }
117   if (TestEnv("LIBYUV_DISABLE_AVX2")) {
118     cpu_info &= ~libyuv::kCpuHasAVX2;
119   }
120   if (TestEnv("LIBYUV_DISABLE_ERMS")) {
121     cpu_info &= ~libyuv::kCpuHasERMS;
122   }
123   if (TestEnv("LIBYUV_DISABLE_FMA3")) {
124     cpu_info &= ~libyuv::kCpuHasFMA3;
125   }
126   if (TestEnv("LIBYUV_DISABLE_F16C")) {
127     cpu_info &= ~libyuv::kCpuHasF16C;
128   }
129   if (TestEnv("LIBYUV_DISABLE_AVX512BW")) {
130     cpu_info &= ~libyuv::kCpuHasAVX512BW;
131   }
132   if (TestEnv("LIBYUV_DISABLE_AVX512VL")) {
133     cpu_info &= ~libyuv::kCpuHasAVX512VL;
134   }
135   if (TestEnv("LIBYUV_DISABLE_AVX512VNNI")) {
136     cpu_info &= ~libyuv::kCpuHasAVX512VNNI;
137   }
138   if (TestEnv("LIBYUV_DISABLE_AVX512VBMI")) {
139     cpu_info &= ~libyuv::kCpuHasAVX512VBMI;
140   }
141   if (TestEnv("LIBYUV_DISABLE_AVX512VBMI2")) {
142     cpu_info &= ~libyuv::kCpuHasAVX512VBMI2;
143   }
144   if (TestEnv("LIBYUV_DISABLE_AVX512VBITALG")) {
145     cpu_info &= ~libyuv::kCpuHasAVX512VBITALG;
146   }
147   if (TestEnv("LIBYUV_DISABLE_AVX10")) {
148     cpu_info &= ~libyuv::kCpuHasAVX10;
149   }
150   if (TestEnv("LIBYUV_DISABLE_AVXVNNI")) {
151     cpu_info &= ~libyuv::kCpuHasAVXVNNI;
152   }
153   if (TestEnv("LIBYUV_DISABLE_AVXVNNIINT8")) {
154     cpu_info &= ~libyuv::kCpuHasAVXVNNIINT8;
155   }
156 #endif
157   if (TestEnv("LIBYUV_DISABLE_ASM")) {
158     cpu_info = libyuv::kCpuInitialized;
159   }
160   return cpu_info;
161 }
162 
163 // For quicker unittests, default is 128 x 72.  But when benchmarking,
164 // default to 720p.  Allow size to specify.
165 // Set flags to -1 for benchmarking to avoid slower C code.
166 
LibYUVConvertTest()167 LibYUVConvertTest::LibYUVConvertTest()
168     : benchmark_iterations_(1),
169       benchmark_width_(128),
170       benchmark_height_(72),
171       disable_cpu_flags_(1),
172       benchmark_cpu_info_(-1) {
173   const char* repeat = getenv("LIBYUV_REPEAT");
174   if (repeat) {
175     benchmark_iterations_ = atoi(repeat);  // NOLINT
176   }
177   if (LIBYUV_GET_FLAG(FLAGS_libyuv_repeat)) {
178     benchmark_iterations_ = LIBYUV_GET_FLAG(FLAGS_libyuv_repeat);
179   }
180   if (benchmark_iterations_ > 1) {
181     benchmark_width_ = 1280;
182     benchmark_height_ = 720;
183   }
184   const char* width = getenv("LIBYUV_WIDTH");
185   if (width) {
186     benchmark_width_ = atoi(width);  // NOLINT
187   }
188   if (LIBYUV_GET_FLAG(FLAGS_libyuv_width)) {
189     benchmark_width_ = LIBYUV_GET_FLAG(FLAGS_libyuv_width);
190   }
191   const char* height = getenv("LIBYUV_HEIGHT");
192   if (height) {
193     benchmark_height_ = atoi(height);  // NOLINT
194   }
195   if (LIBYUV_GET_FLAG(FLAGS_libyuv_height)) {
196     benchmark_height_ = LIBYUV_GET_FLAG(FLAGS_libyuv_height);
197   }
198   const char* cpu_flags = getenv("LIBYUV_FLAGS");
199   if (cpu_flags) {
200     disable_cpu_flags_ = atoi(cpu_flags);  // NOLINT
201   }
202   if (LIBYUV_GET_FLAG(FLAGS_libyuv_flags)) {
203     disable_cpu_flags_ = LIBYUV_GET_FLAG(FLAGS_libyuv_flags);
204   }
205   const char* cpu_info = getenv("LIBYUV_CPU_INFO");
206   if (cpu_info) {
207     benchmark_cpu_info_ = atoi(cpu_flags);  // NOLINT
208   }
209   if (LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info)) {
210     benchmark_cpu_info_ = LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info);
211   }
212   disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_);
213   benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_);
214   libyuv::MaskCpuFlags(benchmark_cpu_info_);
215   benchmark_pixels_div1280_ =
216       static_cast<int>((static_cast<double>(Abs(benchmark_width_)) *
217                             static_cast<double>(Abs(benchmark_height_)) *
218                             static_cast<double>(benchmark_iterations_) +
219                         1279.0) /
220                        1280.0);
221 }
222 
LibYUVColorTest()223 LibYUVColorTest::LibYUVColorTest()
224     : benchmark_iterations_(1),
225       benchmark_width_(128),
226       benchmark_height_(72),
227       disable_cpu_flags_(1),
228       benchmark_cpu_info_(-1) {
229   const char* repeat = getenv("LIBYUV_REPEAT");
230   if (repeat) {
231     benchmark_iterations_ = atoi(repeat);  // NOLINT
232   }
233   if (LIBYUV_GET_FLAG(FLAGS_libyuv_repeat)) {
234     benchmark_iterations_ = LIBYUV_GET_FLAG(FLAGS_libyuv_repeat);
235   }
236   if (benchmark_iterations_ > 1) {
237     benchmark_width_ = 1280;
238     benchmark_height_ = 720;
239   }
240   const char* width = getenv("LIBYUV_WIDTH");
241   if (width) {
242     benchmark_width_ = atoi(width);  // NOLINT
243   }
244   if (LIBYUV_GET_FLAG(FLAGS_libyuv_width)) {
245     benchmark_width_ = LIBYUV_GET_FLAG(FLAGS_libyuv_width);
246   }
247   const char* height = getenv("LIBYUV_HEIGHT");
248   if (height) {
249     benchmark_height_ = atoi(height);  // NOLINT
250   }
251   if (LIBYUV_GET_FLAG(FLAGS_libyuv_height)) {
252     benchmark_height_ = LIBYUV_GET_FLAG(FLAGS_libyuv_height);
253   }
254   const char* cpu_flags = getenv("LIBYUV_FLAGS");
255   if (cpu_flags) {
256     disable_cpu_flags_ = atoi(cpu_flags);  // NOLINT
257   }
258   if (LIBYUV_GET_FLAG(FLAGS_libyuv_flags)) {
259     disable_cpu_flags_ = LIBYUV_GET_FLAG(FLAGS_libyuv_flags);
260   }
261   const char* cpu_info = getenv("LIBYUV_CPU_INFO");
262   if (cpu_info) {
263     benchmark_cpu_info_ = atoi(cpu_flags);  // NOLINT
264   }
265   if (LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info)) {
266     benchmark_cpu_info_ = LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info);
267   }
268   disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_);
269   benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_);
270   libyuv::MaskCpuFlags(benchmark_cpu_info_);
271   benchmark_pixels_div1280_ =
272       static_cast<int>((static_cast<double>(Abs(benchmark_width_)) *
273                             static_cast<double>(Abs(benchmark_height_)) *
274                             static_cast<double>(benchmark_iterations_) +
275                         1279.0) /
276                        1280.0);
277 }
278 
LibYUVScaleTest()279 LibYUVScaleTest::LibYUVScaleTest()
280     : benchmark_iterations_(1),
281       benchmark_width_(128),
282       benchmark_height_(72),
283       disable_cpu_flags_(1),
284       benchmark_cpu_info_(-1) {
285   const char* repeat = getenv("LIBYUV_REPEAT");
286   if (repeat) {
287     benchmark_iterations_ = atoi(repeat);  // NOLINT
288   }
289   if (LIBYUV_GET_FLAG(FLAGS_libyuv_repeat)) {
290     benchmark_iterations_ = LIBYUV_GET_FLAG(FLAGS_libyuv_repeat);
291   }
292   if (benchmark_iterations_ > 1) {
293     benchmark_width_ = 1280;
294     benchmark_height_ = 720;
295   }
296   const char* width = getenv("LIBYUV_WIDTH");
297   if (width) {
298     benchmark_width_ = atoi(width);  // NOLINT
299   }
300   if (LIBYUV_GET_FLAG(FLAGS_libyuv_width)) {
301     benchmark_width_ = LIBYUV_GET_FLAG(FLAGS_libyuv_width);
302   }
303   const char* height = getenv("LIBYUV_HEIGHT");
304   if (height) {
305     benchmark_height_ = atoi(height);  // NOLINT
306   }
307   if (LIBYUV_GET_FLAG(FLAGS_libyuv_height)) {
308     benchmark_height_ = LIBYUV_GET_FLAG(FLAGS_libyuv_height);
309   }
310   const char* cpu_flags = getenv("LIBYUV_FLAGS");
311   if (cpu_flags) {
312     disable_cpu_flags_ = atoi(cpu_flags);  // NOLINT
313   }
314   if (LIBYUV_GET_FLAG(FLAGS_libyuv_flags)) {
315     disable_cpu_flags_ = LIBYUV_GET_FLAG(FLAGS_libyuv_flags);
316   }
317   const char* cpu_info = getenv("LIBYUV_CPU_INFO");
318   if (cpu_info) {
319     benchmark_cpu_info_ = atoi(cpu_flags);  // NOLINT
320   }
321   if (LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info)) {
322     benchmark_cpu_info_ = LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info);
323   }
324   disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_);
325   benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_);
326   libyuv::MaskCpuFlags(benchmark_cpu_info_);
327   benchmark_pixels_div1280_ =
328       static_cast<int>((static_cast<double>(Abs(benchmark_width_)) *
329                             static_cast<double>(Abs(benchmark_height_)) *
330                             static_cast<double>(benchmark_iterations_) +
331                         1279.0) /
332                        1280.0);
333 }
334 
LibYUVRotateTest()335 LibYUVRotateTest::LibYUVRotateTest()
336     : benchmark_iterations_(1),
337       benchmark_width_(128),
338       benchmark_height_(72),
339       disable_cpu_flags_(1),
340       benchmark_cpu_info_(-1) {
341   const char* repeat = getenv("LIBYUV_REPEAT");
342   if (repeat) {
343     benchmark_iterations_ = atoi(repeat);  // NOLINT
344   }
345   if (LIBYUV_GET_FLAG(FLAGS_libyuv_repeat)) {
346     benchmark_iterations_ = LIBYUV_GET_FLAG(FLAGS_libyuv_repeat);
347   }
348   if (benchmark_iterations_ > 1) {
349     benchmark_width_ = 1280;
350     benchmark_height_ = 720;
351   }
352   const char* width = getenv("LIBYUV_WIDTH");
353   if (width) {
354     benchmark_width_ = atoi(width);  // NOLINT
355   }
356   if (LIBYUV_GET_FLAG(FLAGS_libyuv_width)) {
357     benchmark_width_ = LIBYUV_GET_FLAG(FLAGS_libyuv_width);
358   }
359   const char* height = getenv("LIBYUV_HEIGHT");
360   if (height) {
361     benchmark_height_ = atoi(height);  // NOLINT
362   }
363   if (LIBYUV_GET_FLAG(FLAGS_libyuv_height)) {
364     benchmark_height_ = LIBYUV_GET_FLAG(FLAGS_libyuv_height);
365   }
366   const char* cpu_flags = getenv("LIBYUV_FLAGS");
367   if (cpu_flags) {
368     disable_cpu_flags_ = atoi(cpu_flags);  // NOLINT
369   }
370   if (LIBYUV_GET_FLAG(FLAGS_libyuv_flags)) {
371     disable_cpu_flags_ = LIBYUV_GET_FLAG(FLAGS_libyuv_flags);
372   }
373   const char* cpu_info = getenv("LIBYUV_CPU_INFO");
374   if (cpu_info) {
375     benchmark_cpu_info_ = atoi(cpu_flags);  // NOLINT
376   }
377   if (LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info)) {
378     benchmark_cpu_info_ = LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info);
379   }
380   disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_);
381   benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_);
382   libyuv::MaskCpuFlags(benchmark_cpu_info_);
383   benchmark_pixels_div1280_ =
384       static_cast<int>((static_cast<double>(Abs(benchmark_width_)) *
385                             static_cast<double>(Abs(benchmark_height_)) *
386                             static_cast<double>(benchmark_iterations_) +
387                         1279.0) /
388                        1280.0);
389 }
390 
LibYUVPlanarTest()391 LibYUVPlanarTest::LibYUVPlanarTest()
392     : benchmark_iterations_(1),
393       benchmark_width_(128),
394       benchmark_height_(72),
395       disable_cpu_flags_(1),
396       benchmark_cpu_info_(-1) {
397   const char* repeat = getenv("LIBYUV_REPEAT");
398   if (repeat) {
399     benchmark_iterations_ = atoi(repeat);  // NOLINT
400   }
401   if (LIBYUV_GET_FLAG(FLAGS_libyuv_repeat)) {
402     benchmark_iterations_ = LIBYUV_GET_FLAG(FLAGS_libyuv_repeat);
403   }
404   if (benchmark_iterations_ > 1) {
405     benchmark_width_ = 1280;
406     benchmark_height_ = 720;
407   }
408   const char* width = getenv("LIBYUV_WIDTH");
409   if (width) {
410     benchmark_width_ = atoi(width);  // NOLINT
411   }
412   if (LIBYUV_GET_FLAG(FLAGS_libyuv_width)) {
413     benchmark_width_ = LIBYUV_GET_FLAG(FLAGS_libyuv_width);
414   }
415   const char* height = getenv("LIBYUV_HEIGHT");
416   if (height) {
417     benchmark_height_ = atoi(height);  // NOLINT
418   }
419   if (LIBYUV_GET_FLAG(FLAGS_libyuv_height)) {
420     benchmark_height_ = LIBYUV_GET_FLAG(FLAGS_libyuv_height);
421   }
422   const char* cpu_flags = getenv("LIBYUV_FLAGS");
423   if (cpu_flags) {
424     disable_cpu_flags_ = atoi(cpu_flags);  // NOLINT
425   }
426   if (LIBYUV_GET_FLAG(FLAGS_libyuv_flags)) {
427     disable_cpu_flags_ = LIBYUV_GET_FLAG(FLAGS_libyuv_flags);
428   }
429   const char* cpu_info = getenv("LIBYUV_CPU_INFO");
430   if (cpu_info) {
431     benchmark_cpu_info_ = atoi(cpu_flags);  // NOLINT
432   }
433   if (LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info)) {
434     benchmark_cpu_info_ = LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info);
435   }
436   disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_);
437   benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_);
438   libyuv::MaskCpuFlags(benchmark_cpu_info_);
439   benchmark_pixels_div1280_ =
440       static_cast<int>((static_cast<double>(Abs(benchmark_width_)) *
441                             static_cast<double>(Abs(benchmark_height_)) *
442                             static_cast<double>(benchmark_iterations_) +
443                         1279.0) /
444                        1280.0);
445 }
446 
LibYUVBaseTest()447 LibYUVBaseTest::LibYUVBaseTest()
448     : benchmark_iterations_(1),
449       benchmark_width_(128),
450       benchmark_height_(72),
451       disable_cpu_flags_(1),
452       benchmark_cpu_info_(-1) {
453   const char* repeat = getenv("LIBYUV_REPEAT");
454   if (repeat) {
455     benchmark_iterations_ = atoi(repeat);  // NOLINT
456   }
457   if (LIBYUV_GET_FLAG(FLAGS_libyuv_repeat)) {
458     benchmark_iterations_ = LIBYUV_GET_FLAG(FLAGS_libyuv_repeat);
459   }
460   if (benchmark_iterations_ > 1) {
461     benchmark_width_ = 1280;
462     benchmark_height_ = 720;
463   }
464   const char* width = getenv("LIBYUV_WIDTH");
465   if (width) {
466     benchmark_width_ = atoi(width);  // NOLINT
467   }
468   if (LIBYUV_GET_FLAG(FLAGS_libyuv_width)) {
469     benchmark_width_ = LIBYUV_GET_FLAG(FLAGS_libyuv_width);
470   }
471   const char* height = getenv("LIBYUV_HEIGHT");
472   if (height) {
473     benchmark_height_ = atoi(height);  // NOLINT
474   }
475   if (LIBYUV_GET_FLAG(FLAGS_libyuv_height)) {
476     benchmark_height_ = LIBYUV_GET_FLAG(FLAGS_libyuv_height);
477   }
478   const char* cpu_flags = getenv("LIBYUV_FLAGS");
479   if (cpu_flags) {
480     disable_cpu_flags_ = atoi(cpu_flags);  // NOLINT
481   }
482   if (LIBYUV_GET_FLAG(FLAGS_libyuv_flags)) {
483     disable_cpu_flags_ = LIBYUV_GET_FLAG(FLAGS_libyuv_flags);
484   }
485   const char* cpu_info = getenv("LIBYUV_CPU_INFO");
486   if (cpu_info) {
487     benchmark_cpu_info_ = atoi(cpu_flags);  // NOLINT
488   }
489   if (LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info)) {
490     benchmark_cpu_info_ = LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info);
491   }
492   disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_);
493   benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_);
494   libyuv::MaskCpuFlags(benchmark_cpu_info_);
495   benchmark_pixels_div1280_ =
496       static_cast<int>((static_cast<double>(Abs(benchmark_width_)) *
497                             static_cast<double>(Abs(benchmark_height_)) *
498                             static_cast<double>(benchmark_iterations_) +
499                         1279.0) /
500                        1280.0);
501 }
502 
LibYUVCompareTest()503 LibYUVCompareTest::LibYUVCompareTest()
504     : benchmark_iterations_(1),
505       benchmark_width_(128),
506       benchmark_height_(72),
507       disable_cpu_flags_(1),
508       benchmark_cpu_info_(-1) {
509   const char* repeat = getenv("LIBYUV_REPEAT");
510   if (repeat) {
511     benchmark_iterations_ = atoi(repeat);  // NOLINT
512   }
513   if (LIBYUV_GET_FLAG(FLAGS_libyuv_repeat)) {
514     benchmark_iterations_ = LIBYUV_GET_FLAG(FLAGS_libyuv_repeat);
515   }
516   if (benchmark_iterations_ > 1) {
517     benchmark_width_ = 1280;
518     benchmark_height_ = 720;
519   }
520   const char* width = getenv("LIBYUV_WIDTH");
521   if (width) {
522     benchmark_width_ = atoi(width);  // NOLINT
523   }
524   if (LIBYUV_GET_FLAG(FLAGS_libyuv_width)) {
525     benchmark_width_ = LIBYUV_GET_FLAG(FLAGS_libyuv_width);
526   }
527   const char* height = getenv("LIBYUV_HEIGHT");
528   if (height) {
529     benchmark_height_ = atoi(height);  // NOLINT
530   }
531   if (LIBYUV_GET_FLAG(FLAGS_libyuv_height)) {
532     benchmark_height_ = LIBYUV_GET_FLAG(FLAGS_libyuv_height);
533   }
534   const char* cpu_flags = getenv("LIBYUV_FLAGS");
535   if (cpu_flags) {
536     disable_cpu_flags_ = atoi(cpu_flags);  // NOLINT
537   }
538   if (LIBYUV_GET_FLAG(FLAGS_libyuv_flags)) {
539     disable_cpu_flags_ = LIBYUV_GET_FLAG(FLAGS_libyuv_flags);
540   }
541   const char* cpu_info = getenv("LIBYUV_CPU_INFO");
542   if (cpu_info) {
543     benchmark_cpu_info_ = atoi(cpu_flags);  // NOLINT
544   }
545   if (LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info)) {
546     benchmark_cpu_info_ = LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info);
547   }
548   disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_);
549   benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_);
550   libyuv::MaskCpuFlags(benchmark_cpu_info_);
551   benchmark_pixels_div1280_ =
552       static_cast<int>((static_cast<double>(Abs(benchmark_width_)) *
553                             static_cast<double>(Abs(benchmark_height_)) *
554                             static_cast<double>(benchmark_iterations_) +
555                         1279.0) /
556                        1280.0);
557 }
558 
main(int argc,char ** argv)559 int main(int argc, char** argv) {
560   ::testing::InitGoogleTest(&argc, argv);
561 #ifdef LIBYUV_USE_ABSL_FLAGS
562   absl::ParseCommandLine(argc, argv);
563 #endif
564   return RUN_ALL_TESTS();
565 }
566