123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- #ifndef UNIT_TEST_UNIT_TEST_H_
- #define UNIT_TEST_UNIT_TEST_H_
- #ifdef WIN32
- #include <windows.h>
- #else
- #include <sys/resource.h>
- #include <sys/time.h>
- #endif
- #include <gtest/gtest.h>
- #include "libyuv/basic_types.h"
- #ifndef SIMD_ALIGNED
- #if defined(_MSC_VER) && !defined(__CLR_VER)
- #define SIMD_ALIGNED(var) __declspec(align(16)) var
- #elif defined(__GNUC__) && !defined(__pnacl__)
- #define SIMD_ALIGNED(var) var __attribute__((aligned(16)))
- #else
- #define SIMD_ALIGNED(var) var
- #endif
- #endif
- static __inline int Abs(int v) {
- return v >= 0 ? v : -v;
- }
- static __inline float FAbs(float v) {
- return v >= 0 ? v : -v;
- }
- #define OFFBY 0
- static const int kMaxWidth = 32768;
- static const int kMaxHeight = 32768;
- static inline bool SizeValid(int src_width,
- int src_height,
- int dst_width,
- int dst_height) {
- if (src_width > kMaxWidth || src_height > kMaxHeight ||
- dst_width > kMaxWidth || dst_height > kMaxHeight) {
- printf("Warning - size too large to test. Skipping\n");
- return false;
- }
- return true;
- }
- #define align_buffer_page_end(var, size) \
- uint8_t* var##_mem = \
- reinterpret_cast<uint8_t*>(malloc(((size) + 4095 + 63) & ~4095)); \
- uint8_t* var = reinterpret_cast<uint8_t*>( \
- (intptr_t)(var##_mem + (((size) + 4095 + 63) & ~4095) - (size)) & ~63)
- #define free_aligned_buffer_page_end(var) \
- free(var##_mem); \
- var = 0
- #ifdef WIN32
- static inline double get_time() {
- LARGE_INTEGER t, f;
- QueryPerformanceCounter(&t);
- QueryPerformanceFrequency(&f);
- return static_cast<double>(t.QuadPart) / static_cast<double>(f.QuadPart);
- }
- #else
- static inline double get_time() {
- struct timeval t;
- struct timezone tzp;
- gettimeofday(&t, &tzp);
- return t.tv_sec + t.tv_usec * 1e-6;
- }
- #endif
- #ifndef SIMD_ALIGNED
- #if defined(_MSC_VER) && !defined(__CLR_VER)
- #define SIMD_ALIGNED(var) __declspec(align(16)) var
- #elif defined(__GNUC__) && !defined(__pnacl__)
- #define SIMD_ALIGNED(var) var __attribute__((aligned(16)))
- #else
- #define SIMD_ALIGNED(var) var
- #endif
- #endif
- extern unsigned int fastrand_seed;
- inline int fastrand() {
- fastrand_seed = fastrand_seed * 214013u + 2531011u;
- return static_cast<int>((fastrand_seed >> 16) & 0xffff);
- }
- static inline void MemRandomize(uint8_t* dst, int64_t len) {
- int64_t i;
- for (i = 0; i < len - 1; i += 2) {
- *reinterpret_cast<uint16_t*>(dst) = fastrand();
- dst += 2;
- }
- for (; i < len; ++i) {
- *dst++ = fastrand();
- }
- }
- class LibYUVColorTest : public ::testing::Test {
- protected:
- LibYUVColorTest();
- int benchmark_iterations_;
- int benchmark_width_;
- int benchmark_height_;
- int benchmark_pixels_div1280_;
- int disable_cpu_flags_;
- int benchmark_cpu_info_;
- };
- class LibYUVConvertTest : public ::testing::Test {
- protected:
- LibYUVConvertTest();
- int benchmark_iterations_;
- int benchmark_width_;
- int benchmark_height_;
- int benchmark_pixels_div1280_;
- int disable_cpu_flags_;
- int benchmark_cpu_info_;
- };
- class LibYUVScaleTest : public ::testing::Test {
- protected:
- LibYUVScaleTest();
- int benchmark_iterations_;
- int benchmark_width_;
- int benchmark_height_;
- int benchmark_pixels_div1280_;
- int disable_cpu_flags_;
- int benchmark_cpu_info_;
- };
- class LibYUVRotateTest : public ::testing::Test {
- protected:
- LibYUVRotateTest();
- int benchmark_iterations_;
- int benchmark_width_;
- int benchmark_height_;
- int benchmark_pixels_div1280_;
- int disable_cpu_flags_;
- int benchmark_cpu_info_;
- };
- class LibYUVPlanarTest : public ::testing::Test {
- protected:
- LibYUVPlanarTest();
- int benchmark_iterations_;
- int benchmark_width_;
- int benchmark_height_;
- int benchmark_pixels_div1280_;
- int disable_cpu_flags_;
- int benchmark_cpu_info_;
- };
- class LibYUVBaseTest : public ::testing::Test {
- protected:
- LibYUVBaseTest();
- int benchmark_iterations_;
- int benchmark_width_;
- int benchmark_height_;
- int benchmark_pixels_div1280_;
- int disable_cpu_flags_;
- int benchmark_cpu_info_;
- };
- class LibYUVCompareTest : public ::testing::Test {
- protected:
- LibYUVCompareTest();
- int benchmark_iterations_;
- int benchmark_width_;
- int benchmark_height_;
- int benchmark_pixels_div1280_;
- int disable_cpu_flags_;
- int benchmark_cpu_info_;
- };
- #endif
|