OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2014 The WebM 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 #include <cmath> |
| 12 #include <cstdlib> |
| 13 #include <string> |
| 14 |
| 15 #include "third_party/googletest/src/include/gtest/gtest.h" |
| 16 |
| 17 #include "test/acm_random.h" |
| 18 #include "test/clear_system_state.h" |
| 19 #include "test/register_state_check.h" |
| 20 #include "test/util.h" |
| 21 #include "./vpx_config.h" |
| 22 #include "./vp9_rtcd.h" |
| 23 #include "vp9/common/vp9_entropy.h" |
| 24 #include "vpx/vpx_integer.h" |
| 25 |
| 26 using libvpx_test::ACMRandom; |
| 27 |
| 28 namespace { |
| 29 #if CONFIG_VP9_HIGHBITDEPTH |
| 30 const int kNumIterations = 1000; |
| 31 |
| 32 typedef int64_t (*ErrorBlockFunc)(const tran_low_t *coeff, |
| 33 const tran_low_t *dqcoeff, |
| 34 intptr_t block_size, |
| 35 int64_t *ssz, int bps); |
| 36 |
| 37 typedef std::tr1::tuple<ErrorBlockFunc, ErrorBlockFunc, vpx_bit_depth_t> |
| 38 ErrorBlockParam; |
| 39 |
| 40 class ErrorBlockTest |
| 41 : public ::testing::TestWithParam<ErrorBlockParam> { |
| 42 public: |
| 43 virtual ~ErrorBlockTest() {} |
| 44 virtual void SetUp() { |
| 45 error_block_op_ = GET_PARAM(0); |
| 46 ref_error_block_op_ = GET_PARAM(1); |
| 47 bit_depth_ = GET_PARAM(2); |
| 48 } |
| 49 |
| 50 virtual void TearDown() { libvpx_test::ClearSystemState(); } |
| 51 |
| 52 protected: |
| 53 vpx_bit_depth_t bit_depth_; |
| 54 ErrorBlockFunc error_block_op_; |
| 55 ErrorBlockFunc ref_error_block_op_; |
| 56 }; |
| 57 |
| 58 TEST_P(ErrorBlockTest, OperationCheck) { |
| 59 ACMRandom rnd(ACMRandom::DeterministicSeed()); |
| 60 DECLARE_ALIGNED_ARRAY(16, tran_low_t, coeff, 4096); |
| 61 DECLARE_ALIGNED_ARRAY(16, tran_low_t, dqcoeff, 4096); |
| 62 int err_count_total = 0; |
| 63 int first_failure = -1; |
| 64 intptr_t block_size; |
| 65 int64_t ssz; |
| 66 int64_t ret; |
| 67 int64_t ref_ssz; |
| 68 int64_t ref_ret; |
| 69 for (int i = 0; i < kNumIterations; ++i) { |
| 70 int err_count = 0; |
| 71 block_size = 16 << (i % 9); // All block sizes from 4x4, 8x4 ..64x64 |
| 72 for (int j = 0; j < block_size; j++) { |
| 73 coeff[j] = rnd(2 << 20) - (1 << 20); |
| 74 dqcoeff[j] = rnd(2 << 20) - (1 << 20); |
| 75 } |
| 76 ref_ret = ref_error_block_op_(coeff, dqcoeff, block_size, &ref_ssz, |
| 77 bit_depth_); |
| 78 ASM_REGISTER_STATE_CHECK(ret = error_block_op_(coeff, dqcoeff, block_size, |
| 79 &ssz, bit_depth_)); |
| 80 err_count += (ref_ret != ret) | (ref_ssz != ssz); |
| 81 if (err_count && !err_count_total) { |
| 82 first_failure = i; |
| 83 } |
| 84 err_count_total += err_count; |
| 85 } |
| 86 EXPECT_EQ(0, err_count_total) |
| 87 << "Error: Error Block Test, C output doesn't match SSE2 output. " |
| 88 << "First failed at test case " << first_failure; |
| 89 } |
| 90 |
| 91 TEST_P(ErrorBlockTest, ExtremeValues) { |
| 92 ACMRandom rnd(ACMRandom::DeterministicSeed()); |
| 93 DECLARE_ALIGNED_ARRAY(16, tran_low_t, coeff, 4096); |
| 94 DECLARE_ALIGNED_ARRAY(16, tran_low_t, dqcoeff, 4096); |
| 95 int err_count_total = 0; |
| 96 int first_failure = -1; |
| 97 intptr_t block_size; |
| 98 int64_t ssz; |
| 99 int64_t ret; |
| 100 int64_t ref_ssz; |
| 101 int64_t ref_ret; |
| 102 int max_val = ((1 << 20) - 1); |
| 103 for (int i = 0; i < kNumIterations; ++i) { |
| 104 int err_count = 0; |
| 105 int k = (i / 9) % 5; |
| 106 |
| 107 // Change the maximum coeff value, to test different bit boundaries |
| 108 if ( k == 4 && (i % 9) == 0 ) { |
| 109 max_val >>= 1; |
| 110 } |
| 111 block_size = 16 << (i % 9); // All block sizes from 4x4, 8x4 ..64x64 |
| 112 for (int j = 0; j < block_size; j++) { |
| 113 if (k < 4) { // Test at maximum values |
| 114 coeff[j] = k % 2 ? max_val : -max_val; |
| 115 dqcoeff[j] = (k >> 1) % 2 ? max_val : -max_val; |
| 116 } else { |
| 117 coeff[j] = rnd(2 << 14) - (1 << 14); |
| 118 dqcoeff[j] = rnd(2 << 14) - (1 << 14); |
| 119 } |
| 120 } |
| 121 ref_ret = ref_error_block_op_(coeff, dqcoeff, block_size, &ref_ssz, |
| 122 bit_depth_); |
| 123 ASM_REGISTER_STATE_CHECK(ret = error_block_op_(coeff, dqcoeff, block_size, |
| 124 &ssz, bit_depth_)); |
| 125 err_count += (ref_ret != ret) | (ref_ssz != ssz); |
| 126 if (err_count && !err_count_total) { |
| 127 first_failure = i; |
| 128 } |
| 129 err_count_total += err_count; |
| 130 } |
| 131 EXPECT_EQ(0, err_count_total) |
| 132 << "Error: Error Block Test, C output doesn't match SSE2 output. " |
| 133 << "First failed at test case " << first_failure; |
| 134 } |
| 135 |
| 136 using std::tr1::make_tuple; |
| 137 |
| 138 #if HAVE_SSE2 |
| 139 INSTANTIATE_TEST_CASE_P( |
| 140 SSE2, ErrorBlockTest, |
| 141 ::testing::Values( |
| 142 make_tuple(&vp9_highbd_block_error_sse2, |
| 143 &vp9_highbd_block_error_c, VPX_BITS_10), |
| 144 make_tuple(&vp9_highbd_block_error_sse2, |
| 145 &vp9_highbd_block_error_c, VPX_BITS_12), |
| 146 make_tuple(&vp9_highbd_block_error_sse2, |
| 147 &vp9_highbd_block_error_c, VPX_BITS_8))); |
| 148 #endif // HAVE_SSE2 |
| 149 #endif // CONFIG_VP9_HIGHBITDEPTH |
| 150 } // namespace |
OLD | NEW |