2 * Copyright (c) 2012 The WebM project authors. All Rights Reserved.
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.
16 #include "./vpx_config.h"
17 #if CONFIG_VP9_ENCODER
18 #include "./vp9_rtcd.h"
20 #include "vpx_mem/vpx_mem.h"
22 #include "test/acm_random.h"
23 #include "test/clear_system_state.h"
24 #include "test/register_state_check.h"
25 #include "test/util.h"
26 #include "third_party/googletest/src/include/gtest/gtest.h"
28 using libvpx_test::ACMRandom;
31 class AverageTestBase : public ::testing::Test {
33 AverageTestBase(int width, int height) : width_(width), height_(height) {}
35 static void SetUpTestCase() {
36 source_data_ = reinterpret_cast<uint8_t*>(
37 vpx_memalign(kDataAlignment, kDataBlockSize));
40 static void TearDownTestCase() {
41 vpx_free(source_data_);
45 virtual void TearDown() {
46 libvpx_test::ClearSystemState();
50 // Handle blocks up to 4 blocks 64x64 with stride up to 128
51 static const int kDataAlignment = 16;
52 static const int kDataBlockSize = 64 * 128;
54 virtual void SetUp() {
55 source_stride_ = (width_ + 31) & ~31;
56 rnd_.Reset(ACMRandom::DeterministicSeed());
60 unsigned int ReferenceAverage(const uint8_t* source, int pitch ) {
61 unsigned int average = 0;
62 for (int h = 0; h < 8; ++h)
63 for (int w = 0; w < 8; ++w)
64 average += source[h * source_stride_ + w];
65 return ((average + 32) >> 6);
68 void FillConstant(uint8_t fill_constant) {
69 for (int i = 0; i < width_ * height_; ++i) {
70 source_data_[i] = fill_constant;
75 for (int i = 0; i < width_ * height_; ++i) {
76 source_data_[i] = rnd_.Rand8();
81 static uint8_t* source_data_;
86 typedef unsigned int (*AverageFunction)(const uint8_t* s, int pitch);
88 typedef std::tr1::tuple<int, int, int, AverageFunction> AvgFunc;
91 : public AverageTestBase,
92 public ::testing::WithParamInterface<AvgFunc>{
94 AverageTest() : AverageTestBase(GET_PARAM(0), GET_PARAM(1)) {}
97 void CheckAverages() {
98 unsigned int expected = ReferenceAverage(source_data_+ GET_PARAM(2),
101 ASM_REGISTER_STATE_CHECK(GET_PARAM(3)(source_data_+ GET_PARAM(2),
103 unsigned int actual = GET_PARAM(3)(source_data_+ GET_PARAM(2),
106 EXPECT_EQ(expected, actual);
111 uint8_t* AverageTestBase::source_data_ = NULL;
113 TEST_P(AverageTest, MinValue) {
118 TEST_P(AverageTest, MaxValue) {
123 TEST_P(AverageTest, Random) {
124 // The reference frame, but not the source frame, may be unaligned for
125 // certain types of searches.
126 for (int i = 0; i < 1000; i++) {
132 using std::tr1::make_tuple;
134 INSTANTIATE_TEST_CASE_P(
137 make_tuple(16, 16, 1, &vp9_avg_8x8_c)));
141 INSTANTIATE_TEST_CASE_P(
144 make_tuple(16, 16, 0, &vp9_avg_8x8_sse2),
145 make_tuple(16, 16, 5, &vp9_avg_8x8_sse2),
146 make_tuple(32, 32, 15, &vp9_avg_8x8_sse2)));