diff options
Diffstat (limited to 'files/unit_test/unit_test.cc')
-rw-r--r-- | files/unit_test/unit_test.cc | 194 |
1 files changed, 106 insertions, 88 deletions
diff --git a/files/unit_test/unit_test.cc b/files/unit_test/unit_test.cc index a1ae7ea3..61145a46 100644 --- a/files/unit_test/unit_test.cc +++ b/files/unit_test/unit_test.cc @@ -14,23 +14,28 @@ #include <cstring> -#ifdef LIBYUV_USE_GFLAGS -#include "gflags/gflags.h" +#ifdef LIBYUV_USE_ABSL_FLAGS +#include "absl/flags/flag.h" +#include "absl/flags/parse.h" #endif #include "libyuv/cpu_id.h" unsigned int fastrand_seed = 0xfb; -#ifdef LIBYUV_USE_GFLAGS -DEFINE_int32(libyuv_width, 0, "width of test image."); -DEFINE_int32(libyuv_height, 0, "height of test image."); -DEFINE_int32(libyuv_repeat, 0, "number of times to repeat test."); -DEFINE_int32(libyuv_flags, 0, "cpu flags for reference code. 1 = C, -1 = SIMD"); -DEFINE_int32(libyuv_cpu_info, - 0, - "cpu flags for benchmark code. 1 = C, -1 = SIMD"); +#ifdef LIBYUV_USE_ABSL_FLAGS +ABSL_FLAG(int32_t, libyuv_width, 0, "width of test image."); +ABSL_FLAG(int32_t, libyuv_height, 0, "height of test image."); +ABSL_FLAG(int32_t, libyuv_repeat, 0, "number of times to repeat test."); +ABSL_FLAG(int32_t, + libyuv_flags, + 0, + "cpu flags for reference code. 1 = C, -1 = SIMD"); +ABSL_FLAG(int32_t, + libyuv_cpu_info, + 0, + "cpu flags for benchmark code. 1 = C, -1 = SIMD"); #else -// Disable command line parameters if gflags disabled. +// Disable command line parameters if absl/flags disabled. static const int32_t FLAGS_libyuv_width = 0; static const int32_t FLAGS_libyuv_height = 0; static const int32_t FLAGS_libyuv_repeat = 0; @@ -38,6 +43,12 @@ static const int32_t FLAGS_libyuv_flags = 0; static const int32_t FLAGS_libyuv_cpu_info = 0; #endif +#ifdef LIBYUV_USE_ABSL_FLAGS +#define LIBYUV_GET_FLAG(f) absl::GetFlag(f) +#else +#define LIBYUV_GET_FLAG(f) f +#endif + // Test environment variable for disabling CPU features. Any non-zero value // to disable. Zero ignored to make it easy to set the variable on/off. #if !defined(__native_client__) && !defined(_M_ARM) @@ -66,8 +77,15 @@ int TestCpuEnv(int cpu_info) { if (TestEnv("LIBYUV_DISABLE_MSA")) { cpu_info &= ~libyuv::kCpuHasMSA; } - if (TestEnv("LIBYUV_DISABLE_MMI")) { - cpu_info &= ~libyuv::kCpuHasMMI; +#endif +#if defined(__longarch__) && defined(__linux__) + if (TestEnv("LIBYUV_DISABLE_LSX")) { + cpu_info &= ~libyuv::kCpuHasLSX; + } +#endif +#if defined(__longarch__) && defined(__linux__) + if (TestEnv("LIBYUV_DISABLE_LASX")) { + cpu_info &= ~libyuv::kCpuHasLASX; } #endif #if !defined(__pnacl__) && !defined(__CLR_VER) && \ @@ -109,6 +127,9 @@ int TestCpuEnv(int cpu_info) { if (TestEnv("LIBYUV_DISABLE_AVX512VL")) { cpu_info &= ~libyuv::kCpuHasAVX512VL; } + if (TestEnv("LIBYUV_DISABLE_AVX512VNNI")) { + cpu_info &= ~libyuv::kCpuHasAVX512VNNI; + } if (TestEnv("LIBYUV_DISABLE_AVX512VBMI")) { cpu_info &= ~libyuv::kCpuHasAVX512VBMI; } @@ -145,8 +166,8 @@ LibYUVConvertTest::LibYUVConvertTest() if (repeat) { benchmark_iterations_ = atoi(repeat); // NOLINT } - if (FLAGS_libyuv_repeat) { - benchmark_iterations_ = FLAGS_libyuv_repeat; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_repeat)) { + benchmark_iterations_ = LIBYUV_GET_FLAG(FLAGS_libyuv_repeat); } if (benchmark_iterations_ > 1) { benchmark_width_ = 1280; @@ -156,29 +177,29 @@ LibYUVConvertTest::LibYUVConvertTest() if (width) { benchmark_width_ = atoi(width); // NOLINT } - if (FLAGS_libyuv_width) { - benchmark_width_ = FLAGS_libyuv_width; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_width)) { + benchmark_width_ = LIBYUV_GET_FLAG(FLAGS_libyuv_width); } const char* height = getenv("LIBYUV_HEIGHT"); if (height) { benchmark_height_ = atoi(height); // NOLINT } - if (FLAGS_libyuv_height) { - benchmark_height_ = FLAGS_libyuv_height; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_height)) { + benchmark_height_ = LIBYUV_GET_FLAG(FLAGS_libyuv_height); } const char* cpu_flags = getenv("LIBYUV_FLAGS"); if (cpu_flags) { disable_cpu_flags_ = atoi(cpu_flags); // NOLINT } - if (FLAGS_libyuv_flags) { - disable_cpu_flags_ = FLAGS_libyuv_flags; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_flags)) { + disable_cpu_flags_ = LIBYUV_GET_FLAG(FLAGS_libyuv_flags); } const char* cpu_info = getenv("LIBYUV_CPU_INFO"); if (cpu_info) { benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT } - if (FLAGS_libyuv_cpu_info) { - benchmark_cpu_info_ = FLAGS_libyuv_cpu_info; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info)) { + benchmark_cpu_info_ = LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info); } disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_); benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_); @@ -201,8 +222,8 @@ LibYUVColorTest::LibYUVColorTest() if (repeat) { benchmark_iterations_ = atoi(repeat); // NOLINT } - if (FLAGS_libyuv_repeat) { - benchmark_iterations_ = FLAGS_libyuv_repeat; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_repeat)) { + benchmark_iterations_ = LIBYUV_GET_FLAG(FLAGS_libyuv_repeat); } if (benchmark_iterations_ > 1) { benchmark_width_ = 1280; @@ -212,29 +233,29 @@ LibYUVColorTest::LibYUVColorTest() if (width) { benchmark_width_ = atoi(width); // NOLINT } - if (FLAGS_libyuv_width) { - benchmark_width_ = FLAGS_libyuv_width; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_width)) { + benchmark_width_ = LIBYUV_GET_FLAG(FLAGS_libyuv_width); } const char* height = getenv("LIBYUV_HEIGHT"); if (height) { benchmark_height_ = atoi(height); // NOLINT } - if (FLAGS_libyuv_height) { - benchmark_height_ = FLAGS_libyuv_height; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_height)) { + benchmark_height_ = LIBYUV_GET_FLAG(FLAGS_libyuv_height); } const char* cpu_flags = getenv("LIBYUV_FLAGS"); if (cpu_flags) { disable_cpu_flags_ = atoi(cpu_flags); // NOLINT } - if (FLAGS_libyuv_flags) { - disable_cpu_flags_ = FLAGS_libyuv_flags; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_flags)) { + disable_cpu_flags_ = LIBYUV_GET_FLAG(FLAGS_libyuv_flags); } const char* cpu_info = getenv("LIBYUV_CPU_INFO"); if (cpu_info) { benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT } - if (FLAGS_libyuv_cpu_info) { - benchmark_cpu_info_ = FLAGS_libyuv_cpu_info; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info)) { + benchmark_cpu_info_ = LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info); } disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_); benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_); @@ -257,8 +278,8 @@ LibYUVScaleTest::LibYUVScaleTest() if (repeat) { benchmark_iterations_ = atoi(repeat); // NOLINT } - if (FLAGS_libyuv_repeat) { - benchmark_iterations_ = FLAGS_libyuv_repeat; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_repeat)) { + benchmark_iterations_ = LIBYUV_GET_FLAG(FLAGS_libyuv_repeat); } if (benchmark_iterations_ > 1) { benchmark_width_ = 1280; @@ -268,29 +289,29 @@ LibYUVScaleTest::LibYUVScaleTest() if (width) { benchmark_width_ = atoi(width); // NOLINT } - if (FLAGS_libyuv_width) { - benchmark_width_ = FLAGS_libyuv_width; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_width)) { + benchmark_width_ = LIBYUV_GET_FLAG(FLAGS_libyuv_width); } const char* height = getenv("LIBYUV_HEIGHT"); if (height) { benchmark_height_ = atoi(height); // NOLINT } - if (FLAGS_libyuv_height) { - benchmark_height_ = FLAGS_libyuv_height; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_height)) { + benchmark_height_ = LIBYUV_GET_FLAG(FLAGS_libyuv_height); } const char* cpu_flags = getenv("LIBYUV_FLAGS"); if (cpu_flags) { disable_cpu_flags_ = atoi(cpu_flags); // NOLINT } - if (FLAGS_libyuv_flags) { - disable_cpu_flags_ = FLAGS_libyuv_flags; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_flags)) { + disable_cpu_flags_ = LIBYUV_GET_FLAG(FLAGS_libyuv_flags); } const char* cpu_info = getenv("LIBYUV_CPU_INFO"); if (cpu_info) { benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT } - if (FLAGS_libyuv_cpu_info) { - benchmark_cpu_info_ = FLAGS_libyuv_cpu_info; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info)) { + benchmark_cpu_info_ = LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info); } disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_); benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_); @@ -313,8 +334,8 @@ LibYUVRotateTest::LibYUVRotateTest() if (repeat) { benchmark_iterations_ = atoi(repeat); // NOLINT } - if (FLAGS_libyuv_repeat) { - benchmark_iterations_ = FLAGS_libyuv_repeat; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_repeat)) { + benchmark_iterations_ = LIBYUV_GET_FLAG(FLAGS_libyuv_repeat); } if (benchmark_iterations_ > 1) { benchmark_width_ = 1280; @@ -324,29 +345,29 @@ LibYUVRotateTest::LibYUVRotateTest() if (width) { benchmark_width_ = atoi(width); // NOLINT } - if (FLAGS_libyuv_width) { - benchmark_width_ = FLAGS_libyuv_width; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_width)) { + benchmark_width_ = LIBYUV_GET_FLAG(FLAGS_libyuv_width); } const char* height = getenv("LIBYUV_HEIGHT"); if (height) { benchmark_height_ = atoi(height); // NOLINT } - if (FLAGS_libyuv_height) { - benchmark_height_ = FLAGS_libyuv_height; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_height)) { + benchmark_height_ = LIBYUV_GET_FLAG(FLAGS_libyuv_height); } const char* cpu_flags = getenv("LIBYUV_FLAGS"); if (cpu_flags) { disable_cpu_flags_ = atoi(cpu_flags); // NOLINT } - if (FLAGS_libyuv_flags) { - disable_cpu_flags_ = FLAGS_libyuv_flags; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_flags)) { + disable_cpu_flags_ = LIBYUV_GET_FLAG(FLAGS_libyuv_flags); } const char* cpu_info = getenv("LIBYUV_CPU_INFO"); if (cpu_info) { benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT } - if (FLAGS_libyuv_cpu_info) { - benchmark_cpu_info_ = FLAGS_libyuv_cpu_info; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info)) { + benchmark_cpu_info_ = LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info); } disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_); benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_); @@ -369,8 +390,8 @@ LibYUVPlanarTest::LibYUVPlanarTest() if (repeat) { benchmark_iterations_ = atoi(repeat); // NOLINT } - if (FLAGS_libyuv_repeat) { - benchmark_iterations_ = FLAGS_libyuv_repeat; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_repeat)) { + benchmark_iterations_ = LIBYUV_GET_FLAG(FLAGS_libyuv_repeat); } if (benchmark_iterations_ > 1) { benchmark_width_ = 1280; @@ -380,29 +401,29 @@ LibYUVPlanarTest::LibYUVPlanarTest() if (width) { benchmark_width_ = atoi(width); // NOLINT } - if (FLAGS_libyuv_width) { - benchmark_width_ = FLAGS_libyuv_width; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_width)) { + benchmark_width_ = LIBYUV_GET_FLAG(FLAGS_libyuv_width); } const char* height = getenv("LIBYUV_HEIGHT"); if (height) { benchmark_height_ = atoi(height); // NOLINT } - if (FLAGS_libyuv_height) { - benchmark_height_ = FLAGS_libyuv_height; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_height)) { + benchmark_height_ = LIBYUV_GET_FLAG(FLAGS_libyuv_height); } const char* cpu_flags = getenv("LIBYUV_FLAGS"); if (cpu_flags) { disable_cpu_flags_ = atoi(cpu_flags); // NOLINT } - if (FLAGS_libyuv_flags) { - disable_cpu_flags_ = FLAGS_libyuv_flags; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_flags)) { + disable_cpu_flags_ = LIBYUV_GET_FLAG(FLAGS_libyuv_flags); } const char* cpu_info = getenv("LIBYUV_CPU_INFO"); if (cpu_info) { benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT } - if (FLAGS_libyuv_cpu_info) { - benchmark_cpu_info_ = FLAGS_libyuv_cpu_info; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info)) { + benchmark_cpu_info_ = LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info); } disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_); benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_); @@ -425,8 +446,8 @@ LibYUVBaseTest::LibYUVBaseTest() if (repeat) { benchmark_iterations_ = atoi(repeat); // NOLINT } - if (FLAGS_libyuv_repeat) { - benchmark_iterations_ = FLAGS_libyuv_repeat; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_repeat)) { + benchmark_iterations_ = LIBYUV_GET_FLAG(FLAGS_libyuv_repeat); } if (benchmark_iterations_ > 1) { benchmark_width_ = 1280; @@ -436,29 +457,29 @@ LibYUVBaseTest::LibYUVBaseTest() if (width) { benchmark_width_ = atoi(width); // NOLINT } - if (FLAGS_libyuv_width) { - benchmark_width_ = FLAGS_libyuv_width; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_width)) { + benchmark_width_ = LIBYUV_GET_FLAG(FLAGS_libyuv_width); } const char* height = getenv("LIBYUV_HEIGHT"); if (height) { benchmark_height_ = atoi(height); // NOLINT } - if (FLAGS_libyuv_height) { - benchmark_height_ = FLAGS_libyuv_height; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_height)) { + benchmark_height_ = LIBYUV_GET_FLAG(FLAGS_libyuv_height); } const char* cpu_flags = getenv("LIBYUV_FLAGS"); if (cpu_flags) { disable_cpu_flags_ = atoi(cpu_flags); // NOLINT } - if (FLAGS_libyuv_flags) { - disable_cpu_flags_ = FLAGS_libyuv_flags; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_flags)) { + disable_cpu_flags_ = LIBYUV_GET_FLAG(FLAGS_libyuv_flags); } const char* cpu_info = getenv("LIBYUV_CPU_INFO"); if (cpu_info) { benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT } - if (FLAGS_libyuv_cpu_info) { - benchmark_cpu_info_ = FLAGS_libyuv_cpu_info; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info)) { + benchmark_cpu_info_ = LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info); } disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_); benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_); @@ -481,8 +502,8 @@ LibYUVCompareTest::LibYUVCompareTest() if (repeat) { benchmark_iterations_ = atoi(repeat); // NOLINT } - if (FLAGS_libyuv_repeat) { - benchmark_iterations_ = FLAGS_libyuv_repeat; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_repeat)) { + benchmark_iterations_ = LIBYUV_GET_FLAG(FLAGS_libyuv_repeat); } if (benchmark_iterations_ > 1) { benchmark_width_ = 1280; @@ -492,29 +513,29 @@ LibYUVCompareTest::LibYUVCompareTest() if (width) { benchmark_width_ = atoi(width); // NOLINT } - if (FLAGS_libyuv_width) { - benchmark_width_ = FLAGS_libyuv_width; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_width)) { + benchmark_width_ = LIBYUV_GET_FLAG(FLAGS_libyuv_width); } const char* height = getenv("LIBYUV_HEIGHT"); if (height) { benchmark_height_ = atoi(height); // NOLINT } - if (FLAGS_libyuv_height) { - benchmark_height_ = FLAGS_libyuv_height; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_height)) { + benchmark_height_ = LIBYUV_GET_FLAG(FLAGS_libyuv_height); } const char* cpu_flags = getenv("LIBYUV_FLAGS"); if (cpu_flags) { disable_cpu_flags_ = atoi(cpu_flags); // NOLINT } - if (FLAGS_libyuv_flags) { - disable_cpu_flags_ = FLAGS_libyuv_flags; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_flags)) { + disable_cpu_flags_ = LIBYUV_GET_FLAG(FLAGS_libyuv_flags); } const char* cpu_info = getenv("LIBYUV_CPU_INFO"); if (cpu_info) { benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT } - if (FLAGS_libyuv_cpu_info) { - benchmark_cpu_info_ = FLAGS_libyuv_cpu_info; + if (LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info)) { + benchmark_cpu_info_ = LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info); } disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_); benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_); @@ -529,11 +550,8 @@ LibYUVCompareTest::LibYUVCompareTest() int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); -#ifdef LIBYUV_USE_GFLAGS - // AllowCommandLineParsing allows us to ignore flags passed on to us by - // Chromium build bots without having to explicitly disable them. - google::AllowCommandLineReparsing(); - google::ParseCommandLineFlags(&argc, &argv, true); +#ifdef LIBYUV_USE_ABSL_FLAGS + absl::ParseCommandLine(argc, argv); #endif return RUN_ALL_TESTS(); } |