blob: f2c4bef00182a28bd5d4c9b34b6ce95f6d49be71 [file] [log] [blame]
Shri Borde7cd81492011-11-02 13:20:24 -07001/*
Hendrik Dahlkamp33cfdeb2013-01-23 18:27:37 -08002 * Copyright 2011 The LibYuv Project Authors. All rights reserved.
Shri Borde7cd81492011-11-02 13:20:24 -07003 *
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
Hangyu Kuangf047e7c2016-07-06 14:21:45 -07007 * in the file PATENTS. All contributing project authors may
Shri Borde7cd81492011-11-02 13:20:24 -07008 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Hangyu Kuangf047e7c2016-07-06 14:21:45 -070011#ifndef UNIT_TEST_UNIT_TEST_H_ // NOLINT
Hendrik Dahlkamp33cfdeb2013-01-23 18:27:37 -080012#define UNIT_TEST_UNIT_TEST_H_
Shri Borde7cd81492011-11-02 13:20:24 -070013
Hangyu Kuangf047e7c2016-07-06 14:21:45 -070014#ifdef WIN32
15#include <windows.h>
16#else
17#include <sys/time.h>
18#include <sys/resource.h>
19#endif
20
Shri Borde7cd81492011-11-02 13:20:24 -070021#include <gtest/gtest.h>
22
Hangyu Kuangf047e7c2016-07-06 14:21:45 -070023#include "libyuv/basic_types.h"
Hendrik Dahlkamp33cfdeb2013-01-23 18:27:37 -080024
Hangyu Kuangf047e7c2016-07-06 14:21:45 -070025#ifndef SIMD_ALIGNED
26#if defined(_MSC_VER) && !defined(__CLR_VER)
27#define SIMD_ALIGNED(var) __declspec(align(16)) var
28#elif defined(__GNUC__) && !defined(__pnacl__)
29#define SIMD_ALIGNED(var) var __attribute__((aligned(16)))
30#else
31#define SIMD_ALIGNED(var) var
32#endif
33#endif
Hendrik Dahlkamp33cfdeb2013-01-23 18:27:37 -080034
Hangyu Kuangf047e7c2016-07-06 14:21:45 -070035static __inline int Abs(int v) {
36 return v >= 0 ? v : -v;
37}
38
39#define OFFBY 0
40
41// Scaling uses 16.16 fixed point to step thru the source image, so a
42// maximum size of 32767.999 can be expressed. 32768 is valid because
43// the step is 1 beyond the image but not used.
44// Destination size is mainly constrained by valid scale step not the
45// absolute size, so it may be possible to relax the destination size
46// constraint.
47// Source size is unconstrained for most specialized scalers. e.g.
48// An image of 65536 scaled to half size would be valid. The test
49// could be relaxed for special scale factors.
50// If this test is removed, the scaling function should gracefully
51// fail with a return code. The test could be changed to know that
52// libyuv failed in a controlled way.
53
54static const int kMaxWidth = 32768;
55static const int kMaxHeight = 32768;
56
57static inline bool SizeValid(int src_width, int src_height,
58 int dst_width, int dst_height) {
59 if (src_width > kMaxWidth || src_height > kMaxHeight ||
60 dst_width > kMaxWidth || dst_height > kMaxHeight) {
61 printf("Warning - size too large to test. Skipping\n");
62 return false;
63 }
64 return true;
65}
Hendrik Dahlkamp33cfdeb2013-01-23 18:27:37 -080066
67#define align_buffer_page_end(var, size) \
68 uint8* var; \
69 uint8* var##_mem; \
Hangyu Kuangf047e7c2016-07-06 14:21:45 -070070 var##_mem = reinterpret_cast<uint8*>(malloc(((size) + 4095 + 63) & ~4095)); \
71 var = (uint8*)((intptr_t)(var##_mem + (((size) + 4095 + 63) & ~4095) - \
72 (size)) & ~63);
Hendrik Dahlkamp33cfdeb2013-01-23 18:27:37 -080073
74#define free_aligned_buffer_page_end(var) \
75 free(var##_mem); \
76 var = 0;
77
78#ifdef WIN32
Hendrik Dahlkamp33cfdeb2013-01-23 18:27:37 -080079static inline double get_time() {
80 LARGE_INTEGER t, f;
81 QueryPerformanceCounter(&t);
82 QueryPerformanceFrequency(&f);
83 return static_cast<double>(t.QuadPart) / static_cast<double>(f.QuadPart);
84}
Hendrik Dahlkamp33cfdeb2013-01-23 18:27:37 -080085#else
Hendrik Dahlkamp33cfdeb2013-01-23 18:27:37 -080086static inline double get_time() {
87 struct timeval t;
88 struct timezone tzp;
89 gettimeofday(&t, &tzp);
90 return t.tv_sec + t.tv_usec * 1e-6;
91}
92#endif
93
Hangyu Kuangf047e7c2016-07-06 14:21:45 -070094#ifndef SIMD_ALIGNED
95#if defined(_MSC_VER) && !defined(__CLR_VER)
96#define SIMD_ALIGNED(var) __declspec(align(16)) var
97#elif defined(__GNUC__) && !defined(__pnacl__)
98#define SIMD_ALIGNED(var) var __attribute__((aligned(16)))
99#else
100#define SIMD_ALIGNED(var) var
101#endif
102#endif
103
104extern unsigned int fastrand_seed;
105inline int fastrand() {
106 fastrand_seed = fastrand_seed * 214013u + 2531011u;
107 return static_cast<int>((fastrand_seed >> 16) & 0xffff);
108}
109
110static inline void MemRandomize(uint8* dst, int64 len) {
111 int64 i;
112 for (i = 0; i < len - 1; i += 2) {
113 *reinterpret_cast<uint16*>(dst) = fastrand();
114 dst += 2;
115 }
116 for (; i < len; ++i) {
117 *dst++ = fastrand();
118 }
119}
120
121class LibYUVColorTest : public ::testing::Test {
Shri Borde7cd81492011-11-02 13:20:24 -0700122 protected:
Hangyu Kuangf047e7c2016-07-06 14:21:45 -0700123 LibYUVColorTest();
Shri Borde7cd81492011-11-02 13:20:24 -0700124
Hangyu Kuangf047e7c2016-07-06 14:21:45 -0700125 int benchmark_iterations_; // Default 1. Use 1000 for benchmarking.
126 int benchmark_width_; // Default 1280. Use 640 for benchmarking VGA.
127 int benchmark_height_; // Default 720. Use 360 for benchmarking VGA.
128 int benchmark_pixels_div256_; // Total pixels to benchmark / 256.
129 int benchmark_pixels_div1280_; // Total pixels to benchmark / 1280.
130 int disable_cpu_flags_; // Default 1. Use -1 for benchmarking.
131 int benchmark_cpu_info_; // Default -1. Use 1 to disable SIMD.
Shri Borde7cd81492011-11-02 13:20:24 -0700132};
133
Hangyu Kuangf047e7c2016-07-06 14:21:45 -0700134class LibYUVConvertTest : public ::testing::Test {
135 protected:
136 LibYUVConvertTest();
137
138 int benchmark_iterations_; // Default 1. Use 1000 for benchmarking.
139 int benchmark_width_; // Default 1280. Use 640 for benchmarking VGA.
140 int benchmark_height_; // Default 720. Use 360 for benchmarking VGA.
141 int benchmark_pixels_div256_; // Total pixels to benchmark / 256.
142 int benchmark_pixels_div1280_; // Total pixels to benchmark / 1280.
143 int disable_cpu_flags_; // Default 1. Use -1 for benchmarking.
144 int benchmark_cpu_info_; // Default -1. Use 1 to disable SIMD.
145};
146
147class LibYUVScaleTest : public ::testing::Test {
148 protected:
149 LibYUVScaleTest();
150
151 int benchmark_iterations_; // Default 1. Use 1000 for benchmarking.
152 int benchmark_width_; // Default 1280. Use 640 for benchmarking VGA.
153 int benchmark_height_; // Default 720. Use 360 for benchmarking VGA.
154 int benchmark_pixels_div256_; // Total pixels to benchmark / 256.
155 int benchmark_pixels_div1280_; // Total pixels to benchmark / 1280.
156 int disable_cpu_flags_; // Default 1. Use -1 for benchmarking.
157 int benchmark_cpu_info_; // Default -1. Use 1 to disable SIMD.
158};
159
160class LibYUVRotateTest : public ::testing::Test {
161 protected:
162 LibYUVRotateTest();
163
164 int benchmark_iterations_; // Default 1. Use 1000 for benchmarking.
165 int benchmark_width_; // Default 1280. Use 640 for benchmarking VGA.
166 int benchmark_height_; // Default 720. Use 360 for benchmarking VGA.
167 int benchmark_pixels_div256_; // Total pixels to benchmark / 256.
168 int benchmark_pixels_div1280_; // Total pixels to benchmark / 1280.
169 int disable_cpu_flags_; // Default 1. Use -1 for benchmarking.
170 int benchmark_cpu_info_; // Default -1. Use 1 to disable SIMD.
171};
172
173class LibYUVPlanarTest : public ::testing::Test {
174 protected:
175 LibYUVPlanarTest();
176
177 int benchmark_iterations_; // Default 1. Use 1000 for benchmarking.
178 int benchmark_width_; // Default 1280. Use 640 for benchmarking VGA.
179 int benchmark_height_; // Default 720. Use 360 for benchmarking VGA.
180 int benchmark_pixels_div256_; // Total pixels to benchmark / 256.
181 int benchmark_pixels_div1280_; // Total pixels to benchmark / 1280.
182 int disable_cpu_flags_; // Default 1. Use -1 for benchmarking.
183 int benchmark_cpu_info_; // Default -1. Use 1 to disable SIMD.
184};
185
186class LibYUVBaseTest : public ::testing::Test {
187 protected:
188 LibYUVBaseTest();
189
190 int benchmark_iterations_; // Default 1. Use 1000 for benchmarking.
191 int benchmark_width_; // Default 1280. Use 640 for benchmarking VGA.
192 int benchmark_height_; // Default 720. Use 360 for benchmarking VGA.
193 int benchmark_pixels_div256_; // Total pixels to benchmark / 256.
194 int benchmark_pixels_div1280_; // Total pixels to benchmark / 1280.
195 int disable_cpu_flags_; // Default 1. Use -1 for benchmarking.
196 int benchmark_cpu_info_; // Default -1. Use 1 to disable SIMD.
197};
198
199#endif // UNIT_TEST_UNIT_TEST_H_ NOLINT