Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright 2011 The LibYuv Project Authors. All rights reserved. |
michael@0 | 3 | * |
michael@0 | 4 | * Use of this source code is governed by a BSD-style license |
michael@0 | 5 | * that can be found in the LICENSE file in the root of the source |
michael@0 | 6 | * tree. An additional intellectual property rights grant can be found |
michael@0 | 7 | * in the file PATENTS. All contributing project authors may |
michael@0 | 8 | * be found in the AUTHORS file in the root of the source tree. |
michael@0 | 9 | */ |
michael@0 | 10 | |
michael@0 | 11 | #ifndef UNIT_TEST_UNIT_TEST_H_ // NOLINT |
michael@0 | 12 | #define UNIT_TEST_UNIT_TEST_H_ |
michael@0 | 13 | |
michael@0 | 14 | #ifdef WIN32 |
michael@0 | 15 | #include <windows.h> |
michael@0 | 16 | #else |
michael@0 | 17 | #include <sys/time.h> |
michael@0 | 18 | #include <sys/resource.h> |
michael@0 | 19 | #endif |
michael@0 | 20 | |
michael@0 | 21 | #include <gtest/gtest.h> |
michael@0 | 22 | |
michael@0 | 23 | #include "libyuv/basic_types.h" |
michael@0 | 24 | |
michael@0 | 25 | static __inline int Abs(int v) { |
michael@0 | 26 | return v >= 0 ? v : -v; |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | #define align_buffer_page_end(var, size) \ |
michael@0 | 30 | uint8* var; \ |
michael@0 | 31 | uint8* var##_mem; \ |
michael@0 | 32 | var##_mem = reinterpret_cast<uint8*>(malloc(((size) + 4095) & ~4095)); \ |
michael@0 | 33 | var = var##_mem + (-(size) & 4095); |
michael@0 | 34 | |
michael@0 | 35 | #define free_aligned_buffer_page_end(var) \ |
michael@0 | 36 | free(var##_mem); \ |
michael@0 | 37 | var = 0; |
michael@0 | 38 | |
michael@0 | 39 | #ifdef WIN32 |
michael@0 | 40 | static inline double get_time() { |
michael@0 | 41 | LARGE_INTEGER t, f; |
michael@0 | 42 | QueryPerformanceCounter(&t); |
michael@0 | 43 | QueryPerformanceFrequency(&f); |
michael@0 | 44 | return static_cast<double>(t.QuadPart) / static_cast<double>(f.QuadPart); |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | #define random rand |
michael@0 | 48 | #define srandom srand |
michael@0 | 49 | #else |
michael@0 | 50 | static inline double get_time() { |
michael@0 | 51 | struct timeval t; |
michael@0 | 52 | struct timezone tzp; |
michael@0 | 53 | gettimeofday(&t, &tzp); |
michael@0 | 54 | return t.tv_sec + t.tv_usec * 1e-6; |
michael@0 | 55 | } |
michael@0 | 56 | #endif |
michael@0 | 57 | |
michael@0 | 58 | static inline void MemRandomize(uint8* dst, int len) { |
michael@0 | 59 | int i; |
michael@0 | 60 | for (i = 0; i < len - 1; i += 2) { |
michael@0 | 61 | *reinterpret_cast<uint16*>(dst) = random(); |
michael@0 | 62 | dst += 2; |
michael@0 | 63 | } |
michael@0 | 64 | for (; i < len; ++i) { |
michael@0 | 65 | *dst++ = random(); |
michael@0 | 66 | } |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | class libyuvTest : public ::testing::Test { |
michael@0 | 70 | protected: |
michael@0 | 71 | libyuvTest(); |
michael@0 | 72 | |
michael@0 | 73 | const int rotate_max_w_; |
michael@0 | 74 | const int rotate_max_h_; |
michael@0 | 75 | |
michael@0 | 76 | int benchmark_iterations_; // Default 1. Use 1000 for benchmarking. |
michael@0 | 77 | int benchmark_width_; // Default 1280. Use 640 for benchmarking VGA. |
michael@0 | 78 | int benchmark_height_; // Default 720. Use 360 for benchmarking VGA. |
michael@0 | 79 | int benchmark_pixels_div256_; // Total pixels to benchmark / 256. |
michael@0 | 80 | int benchmark_pixels_div1280_; // Total pixels to benchmark / 1280. |
michael@0 | 81 | }; |
michael@0 | 82 | |
michael@0 | 83 | #endif // UNIT_TEST_UNIT_TEST_H_ NOLINT |