mirror of
https://chromium.googlesource.com/libyuv/libyuv
synced 2026-02-08 18:56:43 +08:00
cpuid sandbox friendlier avoiding getenv()
Move getenv to unittest.cc to allow libyuv to be run in sandbox for x86, x64 and aarch64 Bug: libyuv:767 Test: unittests still run and respect environment variables Change-Id: I84cb1717977828776142b51c029774b3e6b142a3 Reviewed-on: https://chromium-review.googlesource.com/969645 Reviewed-by: richard winterton <rrwinterton@gmail.com>
This commit is contained in:
parent
83aa7512c1
commit
9d70f13c8f
@ -1,6 +1,6 @@
|
|||||||
Name: libyuv
|
Name: libyuv
|
||||||
URL: http://code.google.com/p/libyuv/
|
URL: http://code.google.com/p/libyuv/
|
||||||
Version: 1704
|
Version: 1705
|
||||||
License: BSD
|
License: BSD
|
||||||
License File: LICENSE
|
License File: LICENSE
|
||||||
|
|
||||||
|
|||||||
@ -11,6 +11,6 @@
|
|||||||
#ifndef INCLUDE_LIBYUV_VERSION_H_
|
#ifndef INCLUDE_LIBYUV_VERSION_H_
|
||||||
#define INCLUDE_LIBYUV_VERSION_H_
|
#define INCLUDE_LIBYUV_VERSION_H_
|
||||||
|
|
||||||
#define LIBYUV_VERSION 1704
|
#define LIBYUV_VERSION 1705
|
||||||
|
|
||||||
#endif // INCLUDE_LIBYUV_VERSION_H_
|
#endif // INCLUDE_LIBYUV_VERSION_H_
|
||||||
|
|||||||
@ -19,10 +19,6 @@
|
|||||||
#include <immintrin.h> // For _xgetbv()
|
#include <immintrin.h> // For _xgetbv()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(__native_client__)
|
|
||||||
#include <stdlib.h> // For getenv()
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// For ArmCpuCaps() but unittested on all platforms
|
// For ArmCpuCaps() but unittested on all platforms
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -195,25 +191,6 @@ LIBYUV_API SAFEBUFFERS int MipsCpuCaps(const char* cpuinfo_name,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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)
|
|
||||||
|
|
||||||
static LIBYUV_BOOL TestEnv(const char* name) {
|
|
||||||
const char* var = getenv(name);
|
|
||||||
if (var) {
|
|
||||||
if (var[0] != '0') {
|
|
||||||
return LIBYUV_TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return LIBYUV_FALSE;
|
|
||||||
}
|
|
||||||
#else // nacl does not support getenv().
|
|
||||||
static LIBYUV_BOOL TestEnv(const char*) {
|
|
||||||
return LIBYUV_FALSE;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static SAFEBUFFERS int GetCpuFlags(void) {
|
static SAFEBUFFERS int GetCpuFlags(void) {
|
||||||
int cpu_info = 0;
|
int cpu_info = 0;
|
||||||
#if !defined(__pnacl__) && !defined(__CLR_VER) && \
|
#if !defined(__pnacl__) && !defined(__CLR_VER) && \
|
||||||
@ -251,69 +228,12 @@ static SAFEBUFFERS int GetCpuFlags(void) {
|
|||||||
cpu_info |= (cpu_info7[2] & 0x00000100) ? kCpuHasGFNI : 0;
|
cpu_info |= (cpu_info7[2] & 0x00000100) ? kCpuHasGFNI : 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(fbarchard): Consider moving these to gtest
|
|
||||||
// Environment variable overrides for testing.
|
|
||||||
if (TestEnv("LIBYUV_DISABLE_X86")) {
|
|
||||||
cpu_info &= ~kCpuHasX86;
|
|
||||||
}
|
|
||||||
if (TestEnv("LIBYUV_DISABLE_SSE2")) {
|
|
||||||
cpu_info &= ~kCpuHasSSE2;
|
|
||||||
}
|
|
||||||
if (TestEnv("LIBYUV_DISABLE_SSSE3")) {
|
|
||||||
cpu_info &= ~kCpuHasSSSE3;
|
|
||||||
}
|
|
||||||
if (TestEnv("LIBYUV_DISABLE_SSE41")) {
|
|
||||||
cpu_info &= ~kCpuHasSSE41;
|
|
||||||
}
|
|
||||||
if (TestEnv("LIBYUV_DISABLE_SSE42")) {
|
|
||||||
cpu_info &= ~kCpuHasSSE42;
|
|
||||||
}
|
|
||||||
if (TestEnv("LIBYUV_DISABLE_AVX")) {
|
|
||||||
cpu_info &= ~kCpuHasAVX;
|
|
||||||
}
|
|
||||||
if (TestEnv("LIBYUV_DISABLE_AVX2")) {
|
|
||||||
cpu_info &= ~kCpuHasAVX2;
|
|
||||||
}
|
|
||||||
if (TestEnv("LIBYUV_DISABLE_ERMS")) {
|
|
||||||
cpu_info &= ~kCpuHasERMS;
|
|
||||||
}
|
|
||||||
if (TestEnv("LIBYUV_DISABLE_FMA3")) {
|
|
||||||
cpu_info &= ~kCpuHasFMA3;
|
|
||||||
}
|
|
||||||
if (TestEnv("LIBYUV_DISABLE_F16C")) {
|
|
||||||
cpu_info &= ~kCpuHasF16C;
|
|
||||||
}
|
|
||||||
if (TestEnv("LIBYUV_DISABLE_AVX512BW")) {
|
|
||||||
cpu_info &= ~kCpuHasAVX512BW;
|
|
||||||
}
|
|
||||||
if (TestEnv("LIBYUV_DISABLE_AVX512VL")) {
|
|
||||||
cpu_info &= ~kCpuHasAVX512VL;
|
|
||||||
}
|
|
||||||
if (TestEnv("LIBYUV_DISABLE_AVX512VBMI")) {
|
|
||||||
cpu_info &= ~kCpuHasAVX512VBMI;
|
|
||||||
}
|
|
||||||
if (TestEnv("LIBYUV_DISABLE_AVX512VBMI2")) {
|
|
||||||
cpu_info &= ~kCpuHasAVX512VBMI2;
|
|
||||||
}
|
|
||||||
if (TestEnv("LIBYUV_DISABLE_AVX512VBITALG")) {
|
|
||||||
cpu_info &= ~kCpuHasAVX512VBITALG;
|
|
||||||
}
|
|
||||||
if (TestEnv("LIBYUV_DISABLE_AVX512VPOPCNTDQ")) {
|
|
||||||
cpu_info &= ~kCpuHasAVX512VPOPCNTDQ;
|
|
||||||
}
|
|
||||||
if (TestEnv("LIBYUV_DISABLE_GFNI")) {
|
|
||||||
cpu_info &= ~kCpuHasGFNI;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
#if defined(__mips__) && defined(__linux__)
|
#if defined(__mips__) && defined(__linux__)
|
||||||
#if defined(__mips_msa)
|
#if defined(__mips_msa)
|
||||||
cpu_info = MipsCpuCaps("/proc/cpuinfo", " msa");
|
cpu_info = MipsCpuCaps("/proc/cpuinfo", " msa");
|
||||||
#endif
|
#endif
|
||||||
cpu_info |= kCpuHasMIPS;
|
cpu_info |= kCpuHasMIPS;
|
||||||
if (getenv("LIBYUV_DISABLE_MSA")) {
|
|
||||||
cpu_info &= ~kCpuHasMSA;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
#if defined(__arm__) || defined(__aarch64__)
|
#if defined(__arm__) || defined(__aarch64__)
|
||||||
// gcc -mfpu=neon defines __ARM_NEON__
|
// gcc -mfpu=neon defines __ARM_NEON__
|
||||||
@ -332,13 +252,7 @@ static SAFEBUFFERS int GetCpuFlags(void) {
|
|||||||
cpu_info = ArmCpuCaps("/proc/cpuinfo");
|
cpu_info = ArmCpuCaps("/proc/cpuinfo");
|
||||||
#endif
|
#endif
|
||||||
cpu_info |= kCpuHasARM;
|
cpu_info |= kCpuHasARM;
|
||||||
if (TestEnv("LIBYUV_DISABLE_NEON")) {
|
|
||||||
cpu_info &= ~kCpuHasNEON;
|
|
||||||
}
|
|
||||||
#endif // __arm__
|
#endif // __arm__
|
||||||
if (TestEnv("LIBYUV_DISABLE_ASM")) {
|
|
||||||
cpu_info = 0;
|
|
||||||
}
|
|
||||||
cpu_info |= kCpuInitialized;
|
cpu_info |= kCpuInitialized;
|
||||||
return cpu_info;
|
return cpu_info;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -38,6 +38,96 @@ static const int32_t FLAGS_libyuv_flags = 0;
|
|||||||
static const int32_t FLAGS_libyuv_cpu_info = 0;
|
static const int32_t FLAGS_libyuv_cpu_info = 0;
|
||||||
#endif
|
#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)
|
||||||
|
static LIBYUV_BOOL TestEnv(const char* name) {
|
||||||
|
const char* var = getenv(name);
|
||||||
|
if (var) {
|
||||||
|
if (var[0] != '0') {
|
||||||
|
return LIBYUV_TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return LIBYUV_FALSE;
|
||||||
|
}
|
||||||
|
#else // nacl does not support getenv().
|
||||||
|
static LIBYUV_BOOL TestEnv(const char*) {
|
||||||
|
return LIBYUV_FALSE;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int TestCpuEnv(int cpu_info) {
|
||||||
|
#if defined(__arm__) || defined(__aarch64__)
|
||||||
|
if (TestEnv("LIBYUV_DISABLE_NEON")) {
|
||||||
|
cpu_info &= ~libyuv::kCpuHasNEON;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#if defined(__mips__) && defined(__linux__)
|
||||||
|
if (TestEnv("LIBYUV_DISABLE_MSA")) {
|
||||||
|
cpu_info &= ~libyuv::kCpuHasMSA;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#if !defined(__pnacl__) && !defined(__CLR_VER) && \
|
||||||
|
(defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || \
|
||||||
|
defined(_M_IX86))
|
||||||
|
if (TestEnv("LIBYUV_DISABLE_X86")) {
|
||||||
|
cpu_info &= ~libyuv::kCpuHasX86;
|
||||||
|
}
|
||||||
|
if (TestEnv("LIBYUV_DISABLE_SSE2")) {
|
||||||
|
cpu_info &= ~libyuv::kCpuHasSSE2;
|
||||||
|
}
|
||||||
|
if (TestEnv("LIBYUV_DISABLE_SSSE3")) {
|
||||||
|
cpu_info &= ~libyuv::kCpuHasSSSE3;
|
||||||
|
}
|
||||||
|
if (TestEnv("LIBYUV_DISABLE_SSE41")) {
|
||||||
|
cpu_info &= ~libyuv::kCpuHasSSE41;
|
||||||
|
}
|
||||||
|
if (TestEnv("LIBYUV_DISABLE_SSE42")) {
|
||||||
|
cpu_info &= ~libyuv::kCpuHasSSE42;
|
||||||
|
}
|
||||||
|
if (TestEnv("LIBYUV_DISABLE_AVX")) {
|
||||||
|
cpu_info &= ~libyuv::kCpuHasAVX;
|
||||||
|
}
|
||||||
|
if (TestEnv("LIBYUV_DISABLE_AVX2")) {
|
||||||
|
cpu_info &= ~libyuv::kCpuHasAVX2;
|
||||||
|
}
|
||||||
|
if (TestEnv("LIBYUV_DISABLE_ERMS")) {
|
||||||
|
cpu_info &= ~libyuv::kCpuHasERMS;
|
||||||
|
}
|
||||||
|
if (TestEnv("LIBYUV_DISABLE_FMA3")) {
|
||||||
|
cpu_info &= ~libyuv::kCpuHasFMA3;
|
||||||
|
}
|
||||||
|
if (TestEnv("LIBYUV_DISABLE_F16C")) {
|
||||||
|
cpu_info &= ~libyuv::kCpuHasF16C;
|
||||||
|
}
|
||||||
|
if (TestEnv("LIBYUV_DISABLE_AVX512BW")) {
|
||||||
|
cpu_info &= ~libyuv::kCpuHasAVX512BW;
|
||||||
|
}
|
||||||
|
if (TestEnv("LIBYUV_DISABLE_AVX512VL")) {
|
||||||
|
cpu_info &= ~libyuv::kCpuHasAVX512VL;
|
||||||
|
}
|
||||||
|
if (TestEnv("LIBYUV_DISABLE_AVX512VBMI")) {
|
||||||
|
cpu_info &= ~libyuv::kCpuHasAVX512VBMI;
|
||||||
|
}
|
||||||
|
if (TestEnv("LIBYUV_DISABLE_AVX512VBMI2")) {
|
||||||
|
cpu_info &= ~libyuv::kCpuHasAVX512VBMI2;
|
||||||
|
}
|
||||||
|
if (TestEnv("LIBYUV_DISABLE_AVX512VBITALG")) {
|
||||||
|
cpu_info &= ~libyuv::kCpuHasAVX512VBITALG;
|
||||||
|
}
|
||||||
|
if (TestEnv("LIBYUV_DISABLE_AVX512VPOPCNTDQ")) {
|
||||||
|
cpu_info &= ~libyuv::kCpuHasAVX512VPOPCNTDQ;
|
||||||
|
}
|
||||||
|
if (TestEnv("LIBYUV_DISABLE_GFNI")) {
|
||||||
|
cpu_info &= ~libyuv::kCpuHasGFNI;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (TestEnv("LIBYUV_DISABLE_ASM")) {
|
||||||
|
cpu_info = libyuv::kCpuInitialized;
|
||||||
|
}
|
||||||
|
return cpu_info;
|
||||||
|
}
|
||||||
|
|
||||||
// For quicker unittests, default is 128 x 72. But when benchmarking,
|
// For quicker unittests, default is 128 x 72. But when benchmarking,
|
||||||
// default to 720p. Allow size to specify.
|
// default to 720p. Allow size to specify.
|
||||||
// Set flags to -1 for benchmarking to avoid slower C code.
|
// Set flags to -1 for benchmarking to avoid slower C code.
|
||||||
@ -87,6 +177,8 @@ LibYUVConvertTest::LibYUVConvertTest()
|
|||||||
if (FLAGS_libyuv_cpu_info) {
|
if (FLAGS_libyuv_cpu_info) {
|
||||||
benchmark_cpu_info_ = FLAGS_libyuv_cpu_info;
|
benchmark_cpu_info_ = FLAGS_libyuv_cpu_info;
|
||||||
}
|
}
|
||||||
|
disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_);
|
||||||
|
benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_);
|
||||||
libyuv::MaskCpuFlags(benchmark_cpu_info_);
|
libyuv::MaskCpuFlags(benchmark_cpu_info_);
|
||||||
benchmark_pixels_div1280_ =
|
benchmark_pixels_div1280_ =
|
||||||
static_cast<int>((static_cast<double>(Abs(benchmark_width_)) *
|
static_cast<int>((static_cast<double>(Abs(benchmark_width_)) *
|
||||||
@ -141,6 +233,8 @@ LibYUVColorTest::LibYUVColorTest()
|
|||||||
if (FLAGS_libyuv_cpu_info) {
|
if (FLAGS_libyuv_cpu_info) {
|
||||||
benchmark_cpu_info_ = FLAGS_libyuv_cpu_info;
|
benchmark_cpu_info_ = FLAGS_libyuv_cpu_info;
|
||||||
}
|
}
|
||||||
|
disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_);
|
||||||
|
benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_);
|
||||||
libyuv::MaskCpuFlags(benchmark_cpu_info_);
|
libyuv::MaskCpuFlags(benchmark_cpu_info_);
|
||||||
benchmark_pixels_div1280_ =
|
benchmark_pixels_div1280_ =
|
||||||
static_cast<int>((static_cast<double>(Abs(benchmark_width_)) *
|
static_cast<int>((static_cast<double>(Abs(benchmark_width_)) *
|
||||||
@ -195,6 +289,8 @@ LibYUVScaleTest::LibYUVScaleTest()
|
|||||||
if (FLAGS_libyuv_cpu_info) {
|
if (FLAGS_libyuv_cpu_info) {
|
||||||
benchmark_cpu_info_ = FLAGS_libyuv_cpu_info;
|
benchmark_cpu_info_ = FLAGS_libyuv_cpu_info;
|
||||||
}
|
}
|
||||||
|
disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_);
|
||||||
|
benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_);
|
||||||
libyuv::MaskCpuFlags(benchmark_cpu_info_);
|
libyuv::MaskCpuFlags(benchmark_cpu_info_);
|
||||||
benchmark_pixels_div1280_ =
|
benchmark_pixels_div1280_ =
|
||||||
static_cast<int>((static_cast<double>(Abs(benchmark_width_)) *
|
static_cast<int>((static_cast<double>(Abs(benchmark_width_)) *
|
||||||
@ -249,6 +345,8 @@ LibYUVRotateTest::LibYUVRotateTest()
|
|||||||
if (FLAGS_libyuv_cpu_info) {
|
if (FLAGS_libyuv_cpu_info) {
|
||||||
benchmark_cpu_info_ = FLAGS_libyuv_cpu_info;
|
benchmark_cpu_info_ = FLAGS_libyuv_cpu_info;
|
||||||
}
|
}
|
||||||
|
disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_);
|
||||||
|
benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_);
|
||||||
libyuv::MaskCpuFlags(benchmark_cpu_info_);
|
libyuv::MaskCpuFlags(benchmark_cpu_info_);
|
||||||
benchmark_pixels_div1280_ =
|
benchmark_pixels_div1280_ =
|
||||||
static_cast<int>((static_cast<double>(Abs(benchmark_width_)) *
|
static_cast<int>((static_cast<double>(Abs(benchmark_width_)) *
|
||||||
@ -303,6 +401,8 @@ LibYUVPlanarTest::LibYUVPlanarTest()
|
|||||||
if (FLAGS_libyuv_cpu_info) {
|
if (FLAGS_libyuv_cpu_info) {
|
||||||
benchmark_cpu_info_ = FLAGS_libyuv_cpu_info;
|
benchmark_cpu_info_ = FLAGS_libyuv_cpu_info;
|
||||||
}
|
}
|
||||||
|
disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_);
|
||||||
|
benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_);
|
||||||
libyuv::MaskCpuFlags(benchmark_cpu_info_);
|
libyuv::MaskCpuFlags(benchmark_cpu_info_);
|
||||||
benchmark_pixels_div1280_ =
|
benchmark_pixels_div1280_ =
|
||||||
static_cast<int>((static_cast<double>(Abs(benchmark_width_)) *
|
static_cast<int>((static_cast<double>(Abs(benchmark_width_)) *
|
||||||
@ -357,6 +457,8 @@ LibYUVBaseTest::LibYUVBaseTest()
|
|||||||
if (FLAGS_libyuv_cpu_info) {
|
if (FLAGS_libyuv_cpu_info) {
|
||||||
benchmark_cpu_info_ = FLAGS_libyuv_cpu_info;
|
benchmark_cpu_info_ = FLAGS_libyuv_cpu_info;
|
||||||
}
|
}
|
||||||
|
disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_);
|
||||||
|
benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_);
|
||||||
libyuv::MaskCpuFlags(benchmark_cpu_info_);
|
libyuv::MaskCpuFlags(benchmark_cpu_info_);
|
||||||
benchmark_pixels_div1280_ =
|
benchmark_pixels_div1280_ =
|
||||||
static_cast<int>((static_cast<double>(Abs(benchmark_width_)) *
|
static_cast<int>((static_cast<double>(Abs(benchmark_width_)) *
|
||||||
@ -411,6 +513,8 @@ LibYUVCompareTest::LibYUVCompareTest()
|
|||||||
if (FLAGS_libyuv_cpu_info) {
|
if (FLAGS_libyuv_cpu_info) {
|
||||||
benchmark_cpu_info_ = FLAGS_libyuv_cpu_info;
|
benchmark_cpu_info_ = FLAGS_libyuv_cpu_info;
|
||||||
}
|
}
|
||||||
|
disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_);
|
||||||
|
benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_);
|
||||||
libyuv::MaskCpuFlags(benchmark_cpu_info_);
|
libyuv::MaskCpuFlags(benchmark_cpu_info_);
|
||||||
benchmark_pixels_div1280_ =
|
benchmark_pixels_div1280_ =
|
||||||
static_cast<int>((static_cast<double>(Abs(benchmark_width_)) *
|
static_cast<int>((static_cast<double>(Abs(benchmark_width_)) *
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user