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_GFLAGS 18 #include "gflags/gflags.h" 19 #endif 20 21 // Change this to 1000 for benchmarking. 22 // TODO(fbarchard): Add command line parsing to pass this as option. 23 #define BENCHMARK_ITERATIONS 1 24 25 unsigned int fastrand_seed = 0xfb; 26 27 #ifdef LIBYUV_USE_GFLAGS 28 DEFINE_int32(libyuv_width, 0, "width of test image."); 29 DEFINE_int32(libyuv_height, 0, "height of test image."); 30 DEFINE_int32(libyuv_repeat, 0, "number of times to repeat test."); 31 DEFINE_int32(libyuv_flags, 0, "cpu flags for reference code. 1 = C, -1 = SIMD"); 32 DEFINE_int32(libyuv_cpu_info, 33 0, 34 "cpu flags for benchmark code. 1 = C, -1 = SIMD"); 35 #else 36 // Disable command line parameters if gflags disabled. 37 static const int32 FLAGS_libyuv_width = 0; 38 static const int32 FLAGS_libyuv_height = 0; 39 static const int32 FLAGS_libyuv_repeat = 0; 40 static const int32 FLAGS_libyuv_flags = 0; 41 static const int32 FLAGS_libyuv_cpu_info = 0; 42 #endif 43 44 // For quicker unittests, default is 128 x 72. But when benchmarking, 45 // default to 720p. Allow size to specify. 46 // Set flags to -1 for benchmarking to avoid slower C code. 47 48 LibYUVConvertTest::LibYUVConvertTest() 49 : benchmark_iterations_(BENCHMARK_ITERATIONS), 50 benchmark_width_(128), 51 benchmark_height_(72), 52 disable_cpu_flags_(1), 53 benchmark_cpu_info_(-1) { 54 const char* repeat = getenv("LIBYUV_REPEAT"); 55 if (repeat) { 56 benchmark_iterations_ = atoi(repeat); // NOLINT 57 } 58 if (FLAGS_libyuv_repeat) { 59 benchmark_iterations_ = FLAGS_libyuv_repeat; 60 } 61 if (benchmark_iterations_ > 1) { 62 benchmark_width_ = 1280; 63 benchmark_height_ = 720; 64 } 65 const char* width = getenv("LIBYUV_WIDTH"); 66 if (width) { 67 benchmark_width_ = atoi(width); // NOLINT 68 } 69 if (FLAGS_libyuv_width) { 70 benchmark_width_ = FLAGS_libyuv_width; 71 } 72 const char* height = getenv("LIBYUV_HEIGHT"); 73 if (height) { 74 benchmark_height_ = atoi(height); // NOLINT 75 } 76 if (FLAGS_libyuv_height) { 77 benchmark_height_ = FLAGS_libyuv_height; 78 } 79 const char* cpu_flags = getenv("LIBYUV_FLAGS"); 80 if (cpu_flags) { 81 disable_cpu_flags_ = atoi(cpu_flags); // NOLINT 82 } 83 if (FLAGS_libyuv_flags) { 84 disable_cpu_flags_ = FLAGS_libyuv_flags; 85 } 86 const char* cpu_info = getenv("LIBYUV_CPU_INFO"); 87 if (cpu_info) { 88 benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT 89 } 90 if (FLAGS_libyuv_cpu_info) { 91 benchmark_cpu_info_ = FLAGS_libyuv_cpu_info; 92 } 93 benchmark_pixels_div256_ = 94 static_cast<int>((static_cast<double>(Abs(benchmark_width_)) * 95 static_cast<double>(Abs(benchmark_height_)) * 96 static_cast<double>(benchmark_iterations_) + 97 255.0) / 98 256.0); 99 benchmark_pixels_div1280_ = 100 static_cast<int>((static_cast<double>(Abs(benchmark_width_)) * 101 static_cast<double>(Abs(benchmark_height_)) * 102 static_cast<double>(benchmark_iterations_) + 103 1279.0) / 104 1280.0); 105 } 106 107 LibYUVColorTest::LibYUVColorTest() 108 : benchmark_iterations_(BENCHMARK_ITERATIONS), 109 benchmark_width_(128), 110 benchmark_height_(72), 111 disable_cpu_flags_(1), 112 benchmark_cpu_info_(-1) { 113 const char* repeat = getenv("LIBYUV_REPEAT"); 114 if (repeat) { 115 benchmark_iterations_ = atoi(repeat); // NOLINT 116 } 117 if (FLAGS_libyuv_repeat) { 118 benchmark_iterations_ = FLAGS_libyuv_repeat; 119 } 120 if (benchmark_iterations_ > 1) { 121 benchmark_width_ = 1280; 122 benchmark_height_ = 720; 123 } 124 const char* width = getenv("LIBYUV_WIDTH"); 125 if (width) { 126 benchmark_width_ = atoi(width); // NOLINT 127 } 128 if (FLAGS_libyuv_width) { 129 benchmark_width_ = FLAGS_libyuv_width; 130 } 131 const char* height = getenv("LIBYUV_HEIGHT"); 132 if (height) { 133 benchmark_height_ = atoi(height); // NOLINT 134 } 135 if (FLAGS_libyuv_height) { 136 benchmark_height_ = FLAGS_libyuv_height; 137 } 138 const char* cpu_flags = getenv("LIBYUV_FLAGS"); 139 if (cpu_flags) { 140 disable_cpu_flags_ = atoi(cpu_flags); // NOLINT 141 } 142 if (FLAGS_libyuv_flags) { 143 disable_cpu_flags_ = FLAGS_libyuv_flags; 144 } 145 const char* cpu_info = getenv("LIBYUV_CPU_INFO"); 146 if (cpu_info) { 147 benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT 148 } 149 if (FLAGS_libyuv_cpu_info) { 150 benchmark_cpu_info_ = FLAGS_libyuv_cpu_info; 151 } 152 benchmark_pixels_div256_ = 153 static_cast<int>((static_cast<double>(Abs(benchmark_width_)) * 154 static_cast<double>(Abs(benchmark_height_)) * 155 static_cast<double>(benchmark_iterations_) + 156 255.0) / 157 256.0); 158 benchmark_pixels_div1280_ = 159 static_cast<int>((static_cast<double>(Abs(benchmark_width_)) * 160 static_cast<double>(Abs(benchmark_height_)) * 161 static_cast<double>(benchmark_iterations_) + 162 1279.0) / 163 1280.0); 164 } 165 166 LibYUVScaleTest::LibYUVScaleTest() 167 : benchmark_iterations_(BENCHMARK_ITERATIONS), 168 benchmark_width_(128), 169 benchmark_height_(72), 170 disable_cpu_flags_(1), 171 benchmark_cpu_info_(-1) { 172 const char* repeat = getenv("LIBYUV_REPEAT"); 173 if (repeat) { 174 benchmark_iterations_ = atoi(repeat); // NOLINT 175 } 176 if (FLAGS_libyuv_repeat) { 177 benchmark_iterations_ = FLAGS_libyuv_repeat; 178 } 179 if (benchmark_iterations_ > 1) { 180 benchmark_width_ = 1280; 181 benchmark_height_ = 720; 182 } 183 const char* width = getenv("LIBYUV_WIDTH"); 184 if (width) { 185 benchmark_width_ = atoi(width); // NOLINT 186 } 187 if (FLAGS_libyuv_width) { 188 benchmark_width_ = FLAGS_libyuv_width; 189 } 190 const char* height = getenv("LIBYUV_HEIGHT"); 191 if (height) { 192 benchmark_height_ = atoi(height); // NOLINT 193 } 194 if (FLAGS_libyuv_height) { 195 benchmark_height_ = FLAGS_libyuv_height; 196 } 197 const char* cpu_flags = getenv("LIBYUV_FLAGS"); 198 if (cpu_flags) { 199 disable_cpu_flags_ = atoi(cpu_flags); // NOLINT 200 } 201 if (FLAGS_libyuv_flags) { 202 disable_cpu_flags_ = FLAGS_libyuv_flags; 203 } 204 const char* cpu_info = getenv("LIBYUV_CPU_INFO"); 205 if (cpu_info) { 206 benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT 207 } 208 if (FLAGS_libyuv_cpu_info) { 209 benchmark_cpu_info_ = FLAGS_libyuv_cpu_info; 210 } 211 benchmark_pixels_div256_ = 212 static_cast<int>((static_cast<double>(Abs(benchmark_width_)) * 213 static_cast<double>(Abs(benchmark_height_)) * 214 static_cast<double>(benchmark_iterations_) + 215 255.0) / 216 256.0); 217 benchmark_pixels_div1280_ = 218 static_cast<int>((static_cast<double>(Abs(benchmark_width_)) * 219 static_cast<double>(Abs(benchmark_height_)) * 220 static_cast<double>(benchmark_iterations_) + 221 1279.0) / 222 1280.0); 223 } 224 225 LibYUVRotateTest::LibYUVRotateTest() 226 : benchmark_iterations_(BENCHMARK_ITERATIONS), 227 benchmark_width_(128), 228 benchmark_height_(72), 229 disable_cpu_flags_(1), 230 benchmark_cpu_info_(-1) { 231 const char* repeat = getenv("LIBYUV_REPEAT"); 232 if (repeat) { 233 benchmark_iterations_ = atoi(repeat); // NOLINT 234 } 235 if (FLAGS_libyuv_repeat) { 236 benchmark_iterations_ = FLAGS_libyuv_repeat; 237 } 238 if (benchmark_iterations_ > 1) { 239 benchmark_width_ = 1280; 240 benchmark_height_ = 720; 241 } 242 const char* width = getenv("LIBYUV_WIDTH"); 243 if (width) { 244 benchmark_width_ = atoi(width); // NOLINT 245 } 246 if (FLAGS_libyuv_width) { 247 benchmark_width_ = FLAGS_libyuv_width; 248 } 249 const char* height = getenv("LIBYUV_HEIGHT"); 250 if (height) { 251 benchmark_height_ = atoi(height); // NOLINT 252 } 253 if (FLAGS_libyuv_height) { 254 benchmark_height_ = FLAGS_libyuv_height; 255 } 256 const char* cpu_flags = getenv("LIBYUV_FLAGS"); 257 if (cpu_flags) { 258 disable_cpu_flags_ = atoi(cpu_flags); // NOLINT 259 } 260 if (FLAGS_libyuv_flags) { 261 disable_cpu_flags_ = FLAGS_libyuv_flags; 262 } 263 const char* cpu_info = getenv("LIBYUV_CPU_INFO"); 264 if (cpu_info) { 265 benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT 266 } 267 if (FLAGS_libyuv_cpu_info) { 268 benchmark_cpu_info_ = FLAGS_libyuv_cpu_info; 269 } 270 benchmark_pixels_div256_ = 271 static_cast<int>((static_cast<double>(Abs(benchmark_width_)) * 272 static_cast<double>(Abs(benchmark_height_)) * 273 static_cast<double>(benchmark_iterations_) + 274 255.0) / 275 256.0); 276 benchmark_pixels_div1280_ = 277 static_cast<int>((static_cast<double>(Abs(benchmark_width_)) * 278 static_cast<double>(Abs(benchmark_height_)) * 279 static_cast<double>(benchmark_iterations_) + 280 1279.0) / 281 1280.0); 282 } 283 284 LibYUVPlanarTest::LibYUVPlanarTest() 285 : benchmark_iterations_(BENCHMARK_ITERATIONS), 286 benchmark_width_(128), 287 benchmark_height_(72), 288 disable_cpu_flags_(1), 289 benchmark_cpu_info_(-1) { 290 const char* repeat = getenv("LIBYUV_REPEAT"); 291 if (repeat) { 292 benchmark_iterations_ = atoi(repeat); // NOLINT 293 } 294 if (FLAGS_libyuv_repeat) { 295 benchmark_iterations_ = FLAGS_libyuv_repeat; 296 } 297 if (benchmark_iterations_ > 1) { 298 benchmark_width_ = 1280; 299 benchmark_height_ = 720; 300 } 301 const char* width = getenv("LIBYUV_WIDTH"); 302 if (width) { 303 benchmark_width_ = atoi(width); // NOLINT 304 } 305 if (FLAGS_libyuv_width) { 306 benchmark_width_ = FLAGS_libyuv_width; 307 } 308 const char* height = getenv("LIBYUV_HEIGHT"); 309 if (height) { 310 benchmark_height_ = atoi(height); // NOLINT 311 } 312 if (FLAGS_libyuv_height) { 313 benchmark_height_ = FLAGS_libyuv_height; 314 } 315 const char* cpu_flags = getenv("LIBYUV_FLAGS"); 316 if (cpu_flags) { 317 disable_cpu_flags_ = atoi(cpu_flags); // NOLINT 318 } 319 if (FLAGS_libyuv_flags) { 320 disable_cpu_flags_ = FLAGS_libyuv_flags; 321 } 322 const char* cpu_info = getenv("LIBYUV_CPU_INFO"); 323 if (cpu_info) { 324 benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT 325 } 326 if (FLAGS_libyuv_cpu_info) { 327 benchmark_cpu_info_ = FLAGS_libyuv_cpu_info; 328 } 329 benchmark_pixels_div256_ = 330 static_cast<int>((static_cast<double>(Abs(benchmark_width_)) * 331 static_cast<double>(Abs(benchmark_height_)) * 332 static_cast<double>(benchmark_iterations_) + 333 255.0) / 334 256.0); 335 benchmark_pixels_div1280_ = 336 static_cast<int>((static_cast<double>(Abs(benchmark_width_)) * 337 static_cast<double>(Abs(benchmark_height_)) * 338 static_cast<double>(benchmark_iterations_) + 339 1279.0) / 340 1280.0); 341 } 342 343 LibYUVBaseTest::LibYUVBaseTest() 344 : benchmark_iterations_(BENCHMARK_ITERATIONS), 345 benchmark_width_(128), 346 benchmark_height_(72), 347 disable_cpu_flags_(1), 348 benchmark_cpu_info_(-1) { 349 const char* repeat = getenv("LIBYUV_REPEAT"); 350 if (repeat) { 351 benchmark_iterations_ = atoi(repeat); // NOLINT 352 } 353 if (FLAGS_libyuv_repeat) { 354 benchmark_iterations_ = FLAGS_libyuv_repeat; 355 } 356 if (benchmark_iterations_ > 1) { 357 benchmark_width_ = 1280; 358 benchmark_height_ = 720; 359 } 360 const char* width = getenv("LIBYUV_WIDTH"); 361 if (width) { 362 benchmark_width_ = atoi(width); // NOLINT 363 } 364 if (FLAGS_libyuv_width) { 365 benchmark_width_ = FLAGS_libyuv_width; 366 } 367 const char* height = getenv("LIBYUV_HEIGHT"); 368 if (height) { 369 benchmark_height_ = atoi(height); // NOLINT 370 } 371 if (FLAGS_libyuv_height) { 372 benchmark_height_ = FLAGS_libyuv_height; 373 } 374 const char* cpu_flags = getenv("LIBYUV_FLAGS"); 375 if (cpu_flags) { 376 disable_cpu_flags_ = atoi(cpu_flags); // NOLINT 377 } 378 if (FLAGS_libyuv_flags) { 379 disable_cpu_flags_ = FLAGS_libyuv_flags; 380 } 381 const char* cpu_info = getenv("LIBYUV_CPU_INFO"); 382 if (cpu_info) { 383 benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT 384 } 385 if (FLAGS_libyuv_cpu_info) { 386 benchmark_cpu_info_ = FLAGS_libyuv_cpu_info; 387 } 388 benchmark_pixels_div256_ = 389 static_cast<int>((static_cast<double>(Abs(benchmark_width_)) * 390 static_cast<double>(Abs(benchmark_height_)) * 391 static_cast<double>(benchmark_iterations_) + 392 255.0) / 393 256.0); 394 benchmark_pixels_div1280_ = 395 static_cast<int>((static_cast<double>(Abs(benchmark_width_)) * 396 static_cast<double>(Abs(benchmark_height_)) * 397 static_cast<double>(benchmark_iterations_) + 398 1279.0) / 399 1280.0); 400 } 401 402 int main(int argc, char** argv) { 403 ::testing::InitGoogleTest(&argc, argv); 404 #ifdef LIBYUV_USE_GFLAGS 405 // AllowCommandLineParsing allows us to ignore flags passed on to us by 406 // Chromium build bots without having to explicitly disable them. 407 google::AllowCommandLineReparsing(); 408 google::ParseCommandLineFlags(&argc, &argv, true); 409 #endif 410 return RUN_ALL_TESTS(); 411 } 412