media/libyuv/unit_test/unit_test.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/libyuv/unit_test/unit_test.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,83 @@
     1.4 +/*
     1.5 + *  Copyright 2011 The LibYuv Project Authors. All rights reserved.
     1.6 + *
     1.7 + *  Use of this source code is governed by a BSD-style license
     1.8 + *  that can be found in the LICENSE file in the root of the source
     1.9 + *  tree. An additional intellectual property rights grant can be found
    1.10 + *  in the file PATENTS. All contributing project authors may
    1.11 + *  be found in the AUTHORS file in the root of the source tree.
    1.12 + */
    1.13 +
    1.14 +#ifndef UNIT_TEST_UNIT_TEST_H_  // NOLINT
    1.15 +#define UNIT_TEST_UNIT_TEST_H_
    1.16 +
    1.17 +#ifdef WIN32
    1.18 +#include <windows.h>
    1.19 +#else
    1.20 +#include <sys/time.h>
    1.21 +#include <sys/resource.h>
    1.22 +#endif
    1.23 +
    1.24 +#include <gtest/gtest.h>
    1.25 +
    1.26 +#include "libyuv/basic_types.h"
    1.27 +
    1.28 +static __inline int Abs(int v) {
    1.29 +  return v >= 0 ? v : -v;
    1.30 +}
    1.31 +
    1.32 +#define align_buffer_page_end(var, size)                                       \
    1.33 +  uint8* var;                                                                  \
    1.34 +  uint8* var##_mem;                                                            \
    1.35 +  var##_mem = reinterpret_cast<uint8*>(malloc(((size) + 4095) & ~4095));       \
    1.36 +  var = var##_mem + (-(size) & 4095);
    1.37 +
    1.38 +#define free_aligned_buffer_page_end(var) \
    1.39 +  free(var##_mem);  \
    1.40 +  var = 0;
    1.41 +
    1.42 +#ifdef WIN32
    1.43 +static inline double get_time() {
    1.44 +  LARGE_INTEGER t, f;
    1.45 +  QueryPerformanceCounter(&t);
    1.46 +  QueryPerformanceFrequency(&f);
    1.47 +  return static_cast<double>(t.QuadPart) / static_cast<double>(f.QuadPart);
    1.48 +}
    1.49 +
    1.50 +#define random rand
    1.51 +#define srandom srand
    1.52 +#else
    1.53 +static inline double get_time() {
    1.54 +  struct timeval t;
    1.55 +  struct timezone tzp;
    1.56 +  gettimeofday(&t, &tzp);
    1.57 +  return t.tv_sec + t.tv_usec * 1e-6;
    1.58 +}
    1.59 +#endif
    1.60 +
    1.61 +static inline void MemRandomize(uint8* dst, int len) {
    1.62 +  int i;
    1.63 +  for (i = 0; i < len - 1; i += 2) {
    1.64 +    *reinterpret_cast<uint16*>(dst) = random();
    1.65 +    dst += 2;
    1.66 +  }
    1.67 +  for (; i < len; ++i) {
    1.68 +    *dst++ = random();
    1.69 +  }
    1.70 +}
    1.71 +
    1.72 +class libyuvTest : public ::testing::Test {
    1.73 + protected:
    1.74 +  libyuvTest();
    1.75 +
    1.76 +  const int rotate_max_w_;
    1.77 +  const int rotate_max_h_;
    1.78 +
    1.79 +  int benchmark_iterations_;  // Default 1. Use 1000 for benchmarking.
    1.80 +  int benchmark_width_;  // Default 1280.  Use 640 for benchmarking VGA.
    1.81 +  int benchmark_height_;  // Default 720.  Use 360 for benchmarking VGA.
    1.82 +  int benchmark_pixels_div256_;  // Total pixels to benchmark / 256.
    1.83 +  int benchmark_pixels_div1280_;  // Total pixels to benchmark / 1280.
    1.84 +};
    1.85 +
    1.86 +#endif  // UNIT_TEST_UNIT_TEST_H_  NOLINT

mercurial