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