From 05a12ea97f37350c258eb2a9db4ab8eb738b557a Mon Sep 17 00:00:00 2001 From: Sean Purser-Haskell Date: Thu, 30 Mar 2017 14:56:50 -0700 Subject: [PATCH] Refactored warp_filter_test to allow reuse by external tests. Change-Id: Id32a6a21ffda48ef16b027b55f9082614f389003 --- test/test.cmake | 1 + test/test.mk | 3 +- test/warp_filter_test.cc | 127 ++-------------------------------- test/warp_filter_test_util.cc | 123 ++++++++++++++++++++++++++++++++ test/warp_filter_test_util.h | 61 ++++++++++++++++ 5 files changed, 192 insertions(+), 123 deletions(-) create mode 100644 test/warp_filter_test_util.cc create mode 100644 test/warp_filter_test_util.h diff --git a/test/test.cmake b/test/test.cmake index 4e9ef5483..3973d2d28 100644 --- a/test/test.cmake +++ b/test/test.cmake @@ -44,6 +44,7 @@ if (CONFIG_GLOBAL_MOTION OR CONFIG_WARPED_MOTION) set(AOM_UNIT_TEST_COMMON_SOURCES ${AOM_UNIT_TEST_COMMON_SOURCES} "${AOM_ROOT}/test/warp_filter_test.cc") + "${AOM_ROOT}/test/warp_filter_test_util.cc") endif () endif () diff --git a/test/test.mk b/test/test.mk index 7096d2302..8582235f5 100644 --- a/test/test.mk +++ b/test/test.mk @@ -20,6 +20,7 @@ LIBAOM_TEST_SRCS-yes += util.h LIBAOM_TEST_SRCS-yes += video_source.h LIBAOM_TEST_SRCS-yes += transform_test_base.h LIBAOM_TEST_SRCS-yes += function_equivalence_test.h +LIBAOM_TEST_SRCS-yes += warp_filter_test_util.h ## ## BLACK BOX TESTS @@ -224,7 +225,7 @@ LIBAOM_TEST_SRCS-$(CONFIG_AV1_ENCODER) += av1_inv_txfm2d_test.cc LIBAOM_TEST_SRCS-$(CONFIG_AV1) += av1_convolve_test.cc LIBAOM_TEST_SRCS-$(CONFIG_AV1) += av1_convolve_optimz_test.cc ifneq ($(findstring yes,$(CONFIG_GLOBAL_MOTION) $(CONFIG_WARPED_MOTION)),) -LIBAOM_TEST_SRCS-$(HAVE_SSE2) += warp_filter_test.cc +LIBAOM_TEST_SRCS-$(HAVE_SSE2) += warp_filter_test.cc warp_filter_test_util.cc endif ifeq ($(CONFIG_LOOP_RESTORATION),yes) LIBAOM_TEST_SRCS-$(HAVE_SSE4_1) += selfguided_filter_test.cc diff --git a/test/warp_filter_test.cc b/test/warp_filter_test.cc index 73d9fcb60..1d36a3f0c 100644 --- a/test/warp_filter_test.cc +++ b/test/warp_filter_test.cc @@ -10,135 +10,18 @@ */ #include "third_party/googletest/src/googletest/include/gtest/gtest.h" - -#include "./av1_rtcd.h" -#include "./aom_dsp_rtcd.h" -#include "test/acm_random.h" -#include "test/clear_system_state.h" -#include "test/register_state_check.h" -#include "test/util.h" - -#include "av1/common/mv.h" +#include "test/warp_filter_test_util.h" using std::tr1::tuple; using std::tr1::make_tuple; using libaom_test::ACMRandom; - -typedef tuple WarpTestParam; +using libaom_test::AV1WarpFilter::AV1WarpFilterTest; namespace { -class AV1WarpFilterTest : public ::testing::TestWithParam { - public: - virtual ~AV1WarpFilterTest() {} - virtual void SetUp() { rnd_.Reset(ACMRandom::DeterministicSeed()); } +TEST_P(AV1WarpFilterTest, CheckOutput) { RunCheckOutput(av1_warp_affine_sse2); } - virtual void TearDown() { libaom_test::ClearSystemState(); } - - protected: - int32_t random_param(int bits) { - // 1 in 8 chance of generating zero (arbitrarily chosen) - if (((rnd_.Rand8()) & 7) == 0) return 0; - // Otherwise, enerate uniform values in the range - // [-(1 << bits), 1] U [1, 1< (1 << WARPEDMODEL_PREC_BITS)) || - (4 * abs(*gamma) + 7 * abs(*delta) > (1 << WARPEDMODEL_PREC_BITS))) - continue; - - // We have a valid model, so finish - return; - } - } - - void RunCheckOutput() { - const int w = 128, h = 128; - const int border = 16; - const int stride = w + 2 * border; - const int out_w = GET_PARAM(0), out_h = GET_PARAM(1); - const int num_iters = GET_PARAM(2); - int i, j, sub_x, sub_y; - - uint8_t *input_ = new uint8_t[h * stride]; - uint8_t *input = input_ + border; - uint8_t *output = new uint8_t[out_w * out_h]; - uint8_t *output2 = new uint8_t[out_w * out_h]; - int32_t mat[8], alpha, beta, gamma, delta; - - // Generate an input block and extend its borders horizontally - for (i = 0; i < h; ++i) - for (j = 0; j < w; ++j) input[i * stride + j] = rnd_.Rand8(); - for (i = 0; i < h; ++i) { - memset(input + i * stride - border, input[i * stride], border); - memset(input + i * stride + w, input[i * stride + (w - 1)], border); - } - - /* Try different sizes of prediction block */ - for (i = 0; i < num_iters; ++i) { - for (sub_x = 0; sub_x < 2; ++sub_x) - for (sub_y = 0; sub_y < 2; ++sub_y) { - generate_model(mat, &alpha, &beta, &gamma, &delta); - av1_warp_affine_c(mat, input, w, h, stride, output, 32, 32, out_w, - out_h, out_w, sub_x, sub_y, 0, alpha, beta, gamma, - delta); - av1_warp_affine_sse2(mat, input, w, h, stride, output2, 32, 32, out_w, - out_h, out_w, sub_x, sub_y, 0, alpha, beta, - gamma, delta); - - for (j = 0; j < out_w * out_h; ++j) - ASSERT_EQ(output[j], output2[j]) - << "Pixel mismatch at index " << j << " = (" << (j % out_w) - << ", " << (j / out_w) << ") on iteration " << i; - } - } - - delete[] input_; - delete[] output; - delete[] output2; - } - - ACMRandom rnd_; -}; - -TEST_P(AV1WarpFilterTest, CheckOutput) { RunCheckOutput(); } - -const WarpTestParam params[] = { - make_tuple(4, 4, 50000), make_tuple(8, 8, 50000), make_tuple(64, 64, 1000), - make_tuple(4, 16, 20000), make_tuple(32, 8, 10000), -}; - -INSTANTIATE_TEST_CASE_P(SSE2, AV1WarpFilterTest, ::testing::ValuesIn(params)); +INSTANTIATE_TEST_CASE_P(SSE2, AV1WarpFilterTest, + libaom_test::AV1WarpFilter::GetDefaultParams()); } // namespace diff --git a/test/warp_filter_test_util.cc b/test/warp_filter_test_util.cc new file mode 100644 index 000000000..d0966b9cb --- /dev/null +++ b/test/warp_filter_test_util.cc @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2016, Alliance for Open Media. All rights reserved + * + * 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. + */ + +#include "test/warp_filter_test_util.h" + +using std::tr1::tuple; +using std::tr1::make_tuple; +using std::vector; +using libaom_test::ACMRandom; +using libaom_test::AV1WarpFilter::AV1WarpFilterTest; +using libaom_test::AV1WarpFilter::WarpTestParam; + +::testing::internal::ParamGenerator +libaom_test::AV1WarpFilter::GetDefaultParams() { + const WarpTestParam defaultParams[] = { + make_tuple(4, 4, 50000), make_tuple(8, 8, 50000), + make_tuple(64, 64, 1000), make_tuple(4, 16, 20000), + make_tuple(32, 8, 10000), + }; + return ::testing::ValuesIn(defaultParams); +} + +AV1WarpFilterTest::~AV1WarpFilterTest() {} +void AV1WarpFilterTest::SetUp() { rnd_.Reset(ACMRandom::DeterministicSeed()); } + +void AV1WarpFilterTest::TearDown() { libaom_test::ClearSystemState(); } + +int32_t AV1WarpFilterTest::random_param(int bits) { + // 1 in 8 chance of generating zero (arbitrarily chosen) + if (((rnd_.Rand8()) & 7) == 0) return 0; + // Otherwise, enerate uniform values in the range + // [-(1 << bits), 1] U [1, 1< (1 << WARPEDMODEL_PREC_BITS)) || + (4 * abs(*gamma) + 7 * abs(*delta) > (1 << WARPEDMODEL_PREC_BITS))) + continue; + + // We have a valid model, so finish + return; + } +} + +void AV1WarpFilterTest::RunCheckOutput(warp_affine_func test_impl) { + const int w = 128, h = 128; + const int border = 16; + const int stride = w + 2 * border; + const int out_w = GET_PARAM(0), out_h = GET_PARAM(1); + const int num_iters = GET_PARAM(2); + int i, j, sub_x, sub_y; + + uint8_t *input_ = new uint8_t[h * stride]; + uint8_t *input = input_ + border; + uint8_t *output = new uint8_t[out_w * out_h]; + uint8_t *output2 = new uint8_t[out_w * out_h]; + int32_t mat[8], alpha, beta, gamma, delta; + + // Generate an input block and extend its borders horizontally + for (i = 0; i < h; ++i) + for (j = 0; j < w; ++j) input[i * stride + j] = rnd_.Rand8(); + for (i = 0; i < h; ++i) { + memset(input + i * stride - border, input[i * stride], border); + memset(input + i * stride + w, input[i * stride + (w - 1)], border); + } + + /* Try different sizes of prediction block */ + for (i = 0; i < num_iters; ++i) { + for (sub_x = 0; sub_x < 2; ++sub_x) + for (sub_y = 0; sub_y < 2; ++sub_y) { + generate_model(mat, &alpha, &beta, &gamma, &delta); + av1_warp_affine_c(mat, input, w, h, stride, output, 32, 32, out_w, + out_h, out_w, sub_x, sub_y, 0, alpha, beta, gamma, + delta); + test_impl(mat, input, w, h, stride, output2, 32, 32, out_w, out_h, + out_w, sub_x, sub_y, 0, alpha, beta, gamma, delta); + + for (j = 0; j < out_w * out_h; ++j) + ASSERT_EQ(output[j], output2[j]) + << "Pixel mismatch at index " << j << " = (" << (j % out_w) + << ", " << (j / out_w) << ") on iteration " << i; + } + } +} diff --git a/test/warp_filter_test_util.h b/test/warp_filter_test_util.h new file mode 100644 index 000000000..69dd14b77 --- /dev/null +++ b/test/warp_filter_test_util.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2016, Alliance for Open Media. All rights reserved + * + * 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. + */ + +#ifndef TEST_WARP_FILTER_TEST_UTIL_H_ +#define TEST_WARP_FILTER_TEST_UTIL_H_ + +#include "third_party/googletest/src/googletest/include/gtest/gtest.h" +#include "test/acm_random.h" +#include "test/util.h" +#include "./av1_rtcd.h" +#include "./aom_dsp_rtcd.h" +#include "test/clear_system_state.h" +#include "test/register_state_check.h" + +#include "av1/common/mv.h" + +namespace libaom_test { + +namespace AV1WarpFilter { + +typedef void (*warp_affine_func)(int32_t *mat, uint8_t *ref, int width, + int height, int stride, uint8_t *pred, + int p_col, int p_row, int p_width, + int p_height, int p_stride, int subsampling_x, + int subsampling_y, int ref_frm, int32_t alpha, + int32_t beta, int32_t gamma, int32_t delta); + +typedef std::tr1::tuple WarpTestParam; + +::testing::internal::ParamGenerator GetDefaultParams(); + +class AV1WarpFilterTest : public ::testing::TestWithParam { + public: + virtual ~AV1WarpFilterTest(); + virtual void SetUp(); + + virtual void TearDown(); + + protected: + int32_t random_param(int bits); + void generate_model(int32_t *mat, int32_t *alpha, int32_t *beta, + int32_t *gamma, int32_t *delta); + + void RunCheckOutput(warp_affine_func test_impl); + + libaom_test::ACMRandom rnd_; +}; + +} // namespace AV1WarpFilter + +} // namespace libaom_test + +#endif // TEST_WARP_FILTER_TEST_UTIL_H_