From: David Barker Date: Thu, 13 Oct 2016 14:10:14 +0000 (+0100) Subject: Enable test system to detect transforms misusing 'stride' parameter X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7825022daa1790ec4e73909e5d88afaa8ef56432;p=libvpx Enable test system to detect transforms misusing 'stride' parameter This would have caught the bug introduced in patch set 1 of https://chromium-review.googlesource.com/#/c/397378/ Change-Id: I9c6d5d9c4c98aed5ac48c4fb1c4ff4131b0df1d5 --- diff --git a/test/av1_fht16x16_test.cc b/test/av1_fht16x16_test.cc index 51fead7bd..4a44e16d7 100644 --- a/test/av1_fht16x16_test.cc +++ b/test/av1_fht16x16_test.cc @@ -68,6 +68,7 @@ class AV1Trans16x16HT : public libaom_test::TransformTestBase, inv_txfm_ = GET_PARAM(1); tx_type_ = GET_PARAM(2); pitch_ = 16; + height_ = 16; fwd_txfm_ref = fht16x16_ref; bit_depth_ = GET_PARAM(3); mask_ = (1 << bit_depth_) - 1; diff --git a/test/av1_fht16x32_test.cc b/test/av1_fht16x32_test.cc index 9a55f3d59..8ff96b39b 100644 --- a/test/av1_fht16x32_test.cc +++ b/test/av1_fht16x32_test.cc @@ -47,6 +47,7 @@ class AV1Trans16x32HT : public libaom_test::TransformTestBase, inv_txfm_ = GET_PARAM(1); tx_type_ = GET_PARAM(2); pitch_ = 16; + height_ = 32; fwd_txfm_ref = fht16x32_ref; inv_txfm_ref = iht16x32_ref; bit_depth_ = GET_PARAM(3); diff --git a/test/av1_fht16x8_test.cc b/test/av1_fht16x8_test.cc index 3917bf59a..df429e156 100644 --- a/test/av1_fht16x8_test.cc +++ b/test/av1_fht16x8_test.cc @@ -43,6 +43,7 @@ class AV1Trans16x8HT : public libaom_test::TransformTestBase, inv_txfm_ = GET_PARAM(1); tx_type_ = GET_PARAM(2); pitch_ = 16; + height_ = 8; fwd_txfm_ref = fht16x8_ref; bit_depth_ = GET_PARAM(3); mask_ = (1 << bit_depth_) - 1; diff --git a/test/av1_fht32x16_test.cc b/test/av1_fht32x16_test.cc index 3a7ca9b6d..41c0b1cad 100644 --- a/test/av1_fht32x16_test.cc +++ b/test/av1_fht32x16_test.cc @@ -47,6 +47,7 @@ class AV1Trans32x16HT : public libaom_test::TransformTestBase, inv_txfm_ = GET_PARAM(1); tx_type_ = GET_PARAM(2); pitch_ = 32; + height_ = 16; fwd_txfm_ref = fht32x16_ref; inv_txfm_ref = iht32x16_ref; bit_depth_ = GET_PARAM(3); diff --git a/test/av1_fht4x4_test.cc b/test/av1_fht4x4_test.cc index 104b86527..075646c71 100644 --- a/test/av1_fht4x4_test.cc +++ b/test/av1_fht4x4_test.cc @@ -59,6 +59,7 @@ class AV1Trans4x4HT : public libaom_test::TransformTestBase, inv_txfm_ = GET_PARAM(1); tx_type_ = GET_PARAM(2); pitch_ = 4; + height_ = 4; fwd_txfm_ref = fht4x4_ref; bit_depth_ = GET_PARAM(3); mask_ = (1 << bit_depth_) - 1; diff --git a/test/av1_fht4x8_test.cc b/test/av1_fht4x8_test.cc index a34453258..4a5f3ff1a 100644 --- a/test/av1_fht4x8_test.cc +++ b/test/av1_fht4x8_test.cc @@ -47,6 +47,7 @@ class AV1Trans4x8HT : public libaom_test::TransformTestBase, inv_txfm_ = GET_PARAM(1); tx_type_ = GET_PARAM(2); pitch_ = 4; + height_ = 8; fwd_txfm_ref = fht4x8_ref; inv_txfm_ref = iht4x8_ref; bit_depth_ = GET_PARAM(3); diff --git a/test/av1_fht8x16_test.cc b/test/av1_fht8x16_test.cc index be50d7cbf..40390e5b2 100644 --- a/test/av1_fht8x16_test.cc +++ b/test/av1_fht8x16_test.cc @@ -43,6 +43,7 @@ class AV1Trans8x16HT : public libaom_test::TransformTestBase, inv_txfm_ = GET_PARAM(1); tx_type_ = GET_PARAM(2); pitch_ = 8; + height_ = 16; fwd_txfm_ref = fht8x16_ref; bit_depth_ = GET_PARAM(3); mask_ = (1 << bit_depth_) - 1; diff --git a/test/av1_fht8x4_test.cc b/test/av1_fht8x4_test.cc index ee89e9648..46e8c624a 100644 --- a/test/av1_fht8x4_test.cc +++ b/test/av1_fht8x4_test.cc @@ -47,6 +47,7 @@ class AV1Trans8x4HT : public libaom_test::TransformTestBase, inv_txfm_ = GET_PARAM(1); tx_type_ = GET_PARAM(2); pitch_ = 8; + height_ = 4; fwd_txfm_ref = fht8x4_ref; inv_txfm_ref = iht8x4_ref; bit_depth_ = GET_PARAM(3); diff --git a/test/av1_fht8x8_test.cc b/test/av1_fht8x8_test.cc index 3e8a4c829..54cb405e2 100644 --- a/test/av1_fht8x8_test.cc +++ b/test/av1_fht8x8_test.cc @@ -58,6 +58,7 @@ class AV1Trans8x8HT : public libaom_test::TransformTestBase, inv_txfm_ = GET_PARAM(1); tx_type_ = GET_PARAM(2); pitch_ = 8; + height_ = 8; fwd_txfm_ref = fht8x8_ref; bit_depth_ = GET_PARAM(3); mask_ = (1 << bit_depth_) - 1; diff --git a/test/av1_iht16x8_test.cc b/test/av1_iht16x8_test.cc index 0d4406d4b..60adb333f 100644 --- a/test/av1_iht16x8_test.cc +++ b/test/av1_iht16x8_test.cc @@ -44,7 +44,8 @@ class AV1Trans16x8IHT : public libaom_test::TransformTestBase, virtual void SetUp() { inv_txfm_ = GET_PARAM(0); tx_type_ = GET_PARAM(1); - pitch_ = 8; + pitch_ = 16; + height_ = 8; inv_txfm_ref = iht16x8_ref; fwd_txfm_ref = fht16x8_ref; bit_depth_ = GET_PARAM(2); diff --git a/test/av1_iht8x16_test.cc b/test/av1_iht8x16_test.cc index 21fdc6b6d..feb573577 100644 --- a/test/av1_iht8x16_test.cc +++ b/test/av1_iht8x16_test.cc @@ -45,6 +45,7 @@ class AV1Trans8x16IHT : public libaom_test::TransformTestBase, inv_txfm_ = GET_PARAM(0); tx_type_ = GET_PARAM(1); pitch_ = 8; + height_ = 16; inv_txfm_ref = iht8x16_ref; fwd_txfm_ref = fht8x16_ref; bit_depth_ = GET_PARAM(2); diff --git a/test/fdct4x4_test.cc b/test/fdct4x4_test.cc index 471f5b433..f7b093256 100644 --- a/test/fdct4x4_test.cc +++ b/test/fdct4x4_test.cc @@ -100,6 +100,7 @@ class Trans4x4DCT : public libaom_test::TransformTestBase, inv_txfm_ = GET_PARAM(1); tx_type_ = GET_PARAM(2); pitch_ = 4; + height_ = 4; fwd_txfm_ref = fdct4x4_ref; bit_depth_ = GET_PARAM(3); mask_ = (1 << bit_depth_) - 1; @@ -137,6 +138,7 @@ class Trans4x4HT : public libaom_test::TransformTestBase, inv_txfm_ = GET_PARAM(1); tx_type_ = GET_PARAM(2); pitch_ = 4; + height_ = 4; fwd_txfm_ref = fht4x4_ref; bit_depth_ = GET_PARAM(3); mask_ = (1 << bit_depth_) - 1; @@ -175,6 +177,7 @@ class Trans4x4WHT : public libaom_test::TransformTestBase, inv_txfm_ = GET_PARAM(1); tx_type_ = GET_PARAM(2); pitch_ = 4; + height_ = 4; fwd_txfm_ref = fwht4x4_ref; bit_depth_ = GET_PARAM(3); mask_ = (1 << bit_depth_) - 1; diff --git a/test/transform_test_base.h b/test/transform_test_base.h index fd39d338a..195058ee9 100644 --- a/test/transform_test_base.h +++ b/test/transform_test_base.h @@ -123,33 +123,46 @@ class TransformTestBase { ACMRandom rnd(ACMRandom::DeterministicSeed()); const int count_test_block = 5000; + // Use a stride value which is not the width of any transform, to catch + // cases where the transforms use the stride incorrectly. + int stride = 96; + int16_t *input_block = reinterpret_cast( - aom_memalign(16, sizeof(int16_t) * num_coeffs_)); + aom_memalign(16, sizeof(int16_t) * stride * height_)); tran_low_t *output_ref_block = reinterpret_cast( aom_memalign(16, sizeof(tran_low_t) * num_coeffs_)); tran_low_t *output_block = reinterpret_cast( aom_memalign(16, sizeof(tran_low_t) * num_coeffs_)); for (int i = 0; i < count_test_block; ++i) { - for (int j = 0; j < num_coeffs_; ++j) { - input_block[j] = (rnd.Rand16() & mask_) - (rnd.Rand16() & mask_); - if (bit_depth_ == AOM_BITS_8) { - output_block[j] = output_ref_block[j] = rnd.Rand8(); + int j, k; + for (j = 0; j < height_; ++j) { + for (k = 0; k < pitch_; ++k) { + int in_idx = j * stride + k; + int out_idx = j * pitch_ + k; + input_block[in_idx] = (rnd.Rand16() & mask_) - (rnd.Rand16() & mask_); + if (bit_depth_ == AOM_BITS_8) { + output_block[out_idx] = output_ref_block[out_idx] = rnd.Rand8(); #if CONFIG_AOM_HIGHBITDEPTH - } else { - output_block[j] = output_ref_block[j] = rnd.Rand16() & mask_; + } else { + output_block[out_idx] = output_ref_block[out_idx] = + rnd.Rand16() & mask_; #endif + } } } - fwd_txfm_ref(input_block, output_ref_block, pitch_, tx_type_); - ASM_REGISTER_STATE_CHECK(RunFwdTxfm(input_block, output_block, pitch_)); + fwd_txfm_ref(input_block, output_ref_block, stride, tx_type_); + ASM_REGISTER_STATE_CHECK(RunFwdTxfm(input_block, output_block, stride)); // The minimum quant value is 4. - for (int j = 0; j < num_coeffs_; ++j) { - ASSERT_EQ(output_block[j], output_ref_block[j]) - << "Error: not bit-exact result at index: " << j - << " at test block: " << i; + for (j = 0; j < height_; ++j) { + for (k = 0; k < pitch_; ++k) { + int out_idx = j * pitch_ + k; + ASSERT_EQ(output_block[out_idx], output_ref_block[out_idx]) + << "Error: not bit-exact result at index: " << out_idx + << " at test block: " << i; + } } } aom_free(input_block); @@ -161,32 +174,44 @@ class TransformTestBase { ACMRandom rnd(ACMRandom::DeterministicSeed()); const int count_test_block = 5000; + // Use a stride value which is not the width of any transform, to catch + // cases where the transforms use the stride incorrectly. + int stride = 96; + int16_t *input_block = reinterpret_cast( aom_memalign(16, sizeof(int16_t) * num_coeffs_)); tran_low_t *trans_block = reinterpret_cast( aom_memalign(16, sizeof(tran_low_t) * num_coeffs_)); uint8_t *output_block = reinterpret_cast( - aom_memalign(16, sizeof(uint8_t) * num_coeffs_)); + aom_memalign(16, sizeof(uint8_t) * stride * height_)); uint8_t *output_ref_block = reinterpret_cast( - aom_memalign(16, sizeof(uint8_t) * num_coeffs_)); + aom_memalign(16, sizeof(uint8_t) * stride * height_)); for (int i = 0; i < count_test_block; ++i) { // Initialize a test block with input range [-mask_, mask_]. - for (int j = 0; j < num_coeffs_; ++j) { - input_block[j] = (rnd.Rand16() & mask_) - (rnd.Rand16() & mask_); - output_ref_block[j] = rnd.Rand16() & mask_; - output_block[j] = output_ref_block[j]; + int j, k; + for (j = 0; j < height_; ++j) { + for (k = 0; k < pitch_; ++k) { + int in_idx = j * pitch_ + k; + int out_idx = j * stride + k; + input_block[in_idx] = (rnd.Rand16() & mask_) - (rnd.Rand16() & mask_); + output_ref_block[out_idx] = rnd.Rand16() & mask_; + output_block[out_idx] = output_ref_block[out_idx]; + } } fwd_txfm_ref(input_block, trans_block, pitch_, tx_type_); - inv_txfm_ref(trans_block, output_ref_block, pitch_, tx_type_); - ASM_REGISTER_STATE_CHECK(RunInvTxfm(trans_block, output_block, pitch_)); + inv_txfm_ref(trans_block, output_ref_block, stride, tx_type_); + ASM_REGISTER_STATE_CHECK(RunInvTxfm(trans_block, output_block, stride)); - for (int j = 0; j < num_coeffs_; ++j) { - ASSERT_EQ(output_block[j], output_ref_block[j]) - << "Error: not bit-exact result at index: " << j - << " at test block: " << i; + for (j = 0; j < height_; ++j) { + for (k = 0; k < pitch_; ++k) { + int out_idx = j * stride + k; + ASSERT_EQ(output_block[out_idx], output_ref_block[out_idx]) + << "Error: not bit-exact result at index: " << out_idx + << " at test block: " << i; + } } } aom_free(input_block); @@ -305,6 +330,7 @@ class TransformTestBase { } int pitch_; + int height_; int tx_type_; FhtFunc fwd_txfm_ref; IhtFunc inv_txfm_ref;