error_block_test.cc 5.58 KB
Newer Older
1
/*
Yaowu Xu's avatar
Yaowu Xu committed
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3
 *
Yaowu Xu's avatar
Yaowu Xu committed
4 5 6 7 8 9 10
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
*/
11 12 13 14 15

#include <cmath>
#include <cstdlib>
#include <string>

16
#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
17

Yaowu Xu's avatar
Yaowu Xu committed
18 19
#include "./aom_config.h"
#include "./av1_rtcd.h"
20 21 22 23
#include "test/acm_random.h"
#include "test/clear_system_state.h"
#include "test/register_state_check.h"
#include "test/util.h"
24
#include "av1/common/entropy.h"
Yaowu Xu's avatar
Yaowu Xu committed
25 26
#include "aom/aom_codec.h"
#include "aom/aom_integer.h"
27

28
using libaom_test::ACMRandom;
29 30

namespace {
31
#if CONFIG_HIGHBITDEPTH
32 33 34 35
const int kNumIterations = 1000;

typedef int64_t (*ErrorBlockFunc)(const tran_low_t *coeff,
                                  const tran_low_t *dqcoeff,
clang-format's avatar
clang-format committed
36
                                  intptr_t block_size, int64_t *ssz, int bps);
37

Yaowu Xu's avatar
Yaowu Xu committed
38
typedef std::tr1::tuple<ErrorBlockFunc, ErrorBlockFunc, aom_bit_depth_t>
clang-format's avatar
clang-format committed
39
    ErrorBlockParam;
40

clang-format's avatar
clang-format committed
41
class ErrorBlockTest : public ::testing::TestWithParam<ErrorBlockParam> {
42 43 44
 public:
  virtual ~ErrorBlockTest() {}
  virtual void SetUp() {
clang-format's avatar
clang-format committed
45
    error_block_op_ = GET_PARAM(0);
46
    ref_error_block_op_ = GET_PARAM(1);
clang-format's avatar
clang-format committed
47
    bit_depth_ = GET_PARAM(2);
48 49
  }

50
  virtual void TearDown() { libaom_test::ClearSystemState(); }
51 52

 protected:
Yaowu Xu's avatar
Yaowu Xu committed
53
  aom_bit_depth_t bit_depth_;
54 55 56 57 58 59
  ErrorBlockFunc error_block_op_;
  ErrorBlockFunc ref_error_block_op_;
};

TEST_P(ErrorBlockTest, OperationCheck) {
  ACMRandom rnd(ACMRandom::DeterministicSeed());
60 61
  DECLARE_ALIGNED(16, tran_low_t, coeff[4096]);
  DECLARE_ALIGNED(16, tran_low_t, dqcoeff[4096]);
62 63 64 65 66 67 68
  int err_count_total = 0;
  int first_failure = -1;
  intptr_t block_size;
  int64_t ssz;
  int64_t ret;
  int64_t ref_ssz;
  int64_t ref_ret;
69
  const int msb = bit_depth_ + 8 - 1;
70 71 72 73
  for (int i = 0; i < kNumIterations; ++i) {
    int err_count = 0;
    block_size = 16 << (i % 9);  // All block sizes from 4x4, 8x4 ..64x64
    for (int j = 0; j < block_size; j++) {
74 75 76 77
      // coeff and dqcoeff will always have at least the same sign, and this
      // can be used for optimization, so generate test input precisely.
      if (rnd(2)) {
        // Positive number
clang-format's avatar
clang-format committed
78
        coeff[j] = rnd(1 << msb);
79 80 81
        dqcoeff[j] = rnd(1 << msb);
      } else {
        // Negative number
clang-format's avatar
clang-format committed
82
        coeff[j] = -rnd(1 << msb);
83 84
        dqcoeff[j] = -rnd(1 << msb);
      }
85
    }
clang-format's avatar
clang-format committed
86 87 88 89
    ref_ret =
        ref_error_block_op_(coeff, dqcoeff, block_size, &ref_ssz, bit_depth_);
    ASM_REGISTER_STATE_CHECK(
        ret = error_block_op_(coeff, dqcoeff, block_size, &ssz, bit_depth_));
90 91 92 93 94 95 96
    err_count += (ref_ret != ret) | (ref_ssz != ssz);
    if (err_count && !err_count_total) {
      first_failure = i;
    }
    err_count_total += err_count;
  }
  EXPECT_EQ(0, err_count_total)
97
      << "Error: Error Block Test, C output doesn't match optimized output. "
98 99 100 101 102
      << "First failed at test case " << first_failure;
}

TEST_P(ErrorBlockTest, ExtremeValues) {
  ACMRandom rnd(ACMRandom::DeterministicSeed());
103 104
  DECLARE_ALIGNED(16, tran_low_t, coeff[4096]);
  DECLARE_ALIGNED(16, tran_low_t, dqcoeff[4096]);
105 106 107 108 109 110 111
  int err_count_total = 0;
  int first_failure = -1;
  intptr_t block_size;
  int64_t ssz;
  int64_t ret;
  int64_t ref_ssz;
  int64_t ref_ret;
112 113
  const int msb = bit_depth_ + 8 - 1;
  int max_val = ((1 << msb) - 1);
114 115
  for (int i = 0; i < kNumIterations; ++i) {
    int err_count = 0;
116
    int k = (i / 9) % 9;
117 118

    // Change the maximum coeff value, to test different bit boundaries
clang-format's avatar
clang-format committed
119
    if (k == 8 && (i % 9) == 0) {
120 121 122 123
      max_val >>= 1;
    }
    block_size = 16 << (i % 9);  // All block sizes from 4x4, 8x4 ..64x64
    for (int j = 0; j < block_size; j++) {
124 125
      if (k < 4) {
        // Test at positive maximum values
clang-format's avatar
clang-format committed
126
        coeff[j] = k % 2 ? max_val : 0;
127 128 129
        dqcoeff[j] = (k >> 1) % 2 ? max_val : 0;
      } else if (k < 8) {
        // Test at negative maximum values
clang-format's avatar
clang-format committed
130
        coeff[j] = k % 2 ? -max_val : 0;
131
        dqcoeff[j] = (k >> 1) % 2 ? -max_val : 0;
132
      } else {
133 134
        if (rnd(2)) {
          // Positive number
clang-format's avatar
clang-format committed
135
          coeff[j] = rnd(1 << 14);
136 137 138
          dqcoeff[j] = rnd(1 << 14);
        } else {
          // Negative number
clang-format's avatar
clang-format committed
139
          coeff[j] = -rnd(1 << 14);
140 141
          dqcoeff[j] = -rnd(1 << 14);
        }
142 143
      }
    }
clang-format's avatar
clang-format committed
144 145 146 147
    ref_ret =
        ref_error_block_op_(coeff, dqcoeff, block_size, &ref_ssz, bit_depth_);
    ASM_REGISTER_STATE_CHECK(
        ret = error_block_op_(coeff, dqcoeff, block_size, &ssz, bit_depth_));
148 149 150 151 152 153 154
    err_count += (ref_ret != ret) | (ref_ssz != ssz);
    if (err_count && !err_count_total) {
      first_failure = i;
    }
    err_count_total += err_count;
  }
  EXPECT_EQ(0, err_count_total)
155
      << "Error: Error Block Test, C output doesn't match optimized output. "
156 157 158
      << "First failed at test case " << first_failure;
}

159
#if (HAVE_SSE2 || HAVE_AVX) && !CONFIG_DAALA_TX
160 161 162 163
using std::tr1::make_tuple;

INSTANTIATE_TEST_CASE_P(
    SSE2, ErrorBlockTest,
Yaowu Xu's avatar
Yaowu Xu committed
164 165 166 167 168 169
    ::testing::Values(make_tuple(&av1_highbd_block_error_sse2,
                                 &av1_highbd_block_error_c, AOM_BITS_10),
                      make_tuple(&av1_highbd_block_error_sse2,
                                 &av1_highbd_block_error_c, AOM_BITS_12),
                      make_tuple(&av1_highbd_block_error_sse2,
                                 &av1_highbd_block_error_c, AOM_BITS_8)));
170
#endif  // HAVE_SSE2
171

172
#endif  // CONFIG_HIGHBITDEPTH
173
}  // namespace