unit_test.h 2.78 KB
Newer Older
frkoenig@google.com's avatar
frkoenig@google.com committed
1
/*
2
 *  Copyright 2011 The LibYuv Project Authors. All rights reserved.
frkoenig@google.com's avatar
frkoenig@google.com committed
3 4 5 6
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
7
 *  in the file PATENTS. All contributing project authors may
frkoenig@google.com's avatar
frkoenig@google.com committed
8 9 10
 *  be found in the AUTHORS file in the root of the source tree.
 */

11
#ifndef UNIT_TEST_UNIT_TEST_H_  // NOLINT
12
#define UNIT_TEST_UNIT_TEST_H_
frkoenig@google.com's avatar
frkoenig@google.com committed
13

14 15 16 17 18 19 20
#ifdef WIN32
#include <windows.h>
#else
#include <sys/time.h>
#include <sys/resource.h>
#endif

frkoenig@google.com's avatar
frkoenig@google.com committed
21 22
#include <gtest/gtest.h>

23 24
#include "libyuv/basic_types.h"

25 26 27 28
static __inline int Abs(int v) {
  return v >= 0 ? v : -v;
}

29
#define align_buffer_64(var, size)                                             \
30 31
  uint8* var;                                                                  \
  uint8* var##_mem;                                                            \
32
  var##_mem = reinterpret_cast<uint8*>(malloc((size) + 63));                   \
33
  var = reinterpret_cast<uint8*>                                               \
34
        ((reinterpret_cast<intptr_t>(var##_mem) + 63) & ~63);
35

36
#define free_aligned_buffer_64(var) \
37 38 39 40
  free(var##_mem);  \
  var = 0;


41 42 43 44
#define align_buffer_page_end(var, size)                                       \
  uint8* var;                                                                  \
  uint8* var##_mem;                                                            \
  var##_mem = reinterpret_cast<uint8*>(malloc(((size) + 4095) & ~4095));       \
45
  var = var##_mem + (-(size) & 4095);
46 47 48 49 50 51

#define free_aligned_buffer_page_end(var) \
  free(var##_mem);  \
  var = 0;

#ifdef WIN32
52
static inline double get_time() {
53 54 55 56
  LARGE_INTEGER t, f;
  QueryPerformanceCounter(&t);
  QueryPerformanceFrequency(&f);
  return static_cast<double>(t.QuadPart) / static_cast<double>(f.QuadPart);
57 58
}

59 60
#define random rand
#define srandom srand
61
#else
62
static inline double get_time() {
mikhal@webrtc.org's avatar
mikhal@webrtc.org committed
63 64 65
  struct timeval t;
  struct timezone tzp;
  gettimeofday(&t, &tzp);
66
  return t.tv_sec + t.tv_usec * 1e-6;
67 68 69
}
#endif

70 71
static inline void MemRandomize(uint8* dst, int len) {
  int i;
72 73 74
  for (i = 0; i < len - 1; i += 2) {
    *reinterpret_cast<uint16*>(dst) = random();
    dst += 2;
75 76 77 78 79 80
  }
  for (; i < len; ++i) {
    *dst++ = random();
  }
}

frkoenig@google.com's avatar
frkoenig@google.com committed
81 82 83
class libyuvTest : public ::testing::Test {
 protected:
  libyuvTest();
84

85 86
  const int rotate_max_w_;
  const int rotate_max_h_;
87

88 89 90
  int benchmark_iterations_;  // Default 1. Use 1000 for benchmarking.
  int benchmark_width_;  // Default 1280.  Use 640 for benchmarking VGA.
  int benchmark_height_;  // Default 720.  Use 360 for benchmarking VGA.
91
  int benchmark_pixels_div256_;  // Total pixels to benchmark / 256.
92
  int benchmark_pixels_div1280_;  // Total pixels to benchmark / 1280.
frkoenig@google.com's avatar
frkoenig@google.com committed
93 94
};

95
#endif  // UNIT_TEST_UNIT_TEST_H_  NOLINT