diff --git a/test/acm_random.h b/test/acm_random.h index c2f6b0e41..d915cf913 100644 --- a/test/acm_random.h +++ b/test/acm_random.h @@ -11,6 +11,10 @@ #ifndef TEST_ACM_RANDOM_H_ #define TEST_ACM_RANDOM_H_ +#include + +#include + #include "third_party/googletest/src/include/gtest/gtest.h" #include "vpx/vpx_integer.h" @@ -50,6 +54,13 @@ class ACMRandom { return r < 128 ? r << 4 : r >> 4; } + uint32_t RandRange(const uint32_t range) { + // testing::internal::Random::Generate provides values in the range + // testing::internal::Random::kMaxRange. + assert(range <= testing::internal::Random::kMaxRange); + return random_.Generate(range); + } + int PseudoUniform(int range) { return random_.Generate(range); } int operator()(int n) { return PseudoUniform(n); } diff --git a/test/buffer.h b/test/buffer.h index ec4dfbe7b..b31d5ea1a 100644 --- a/test/buffer.h +++ b/test/buffer.h @@ -68,9 +68,15 @@ class Buffer { // Set the buffer (excluding padding) to 'value'. void Set(const T value); - // Set the buffer (excluding padding) to the output of ACMRandom function 'b'. + // Set the buffer (excluding padding) to the output of ACMRandom function + // 'rand_func'. void Set(ACMRandom *rand_class, T (ACMRandom::*rand_func)()); + // Set the buffer (excluding padding) to the output of ACMRandom function + // 'RandRange' with range 'low' to 'high' which must be within + // testing::internal::Random::kMaxRange (1u << 31). + void Set(ACMRandom *rand_class, const int32_t low, const int32_t high); + // Copy the contents of Buffer 'a' (excluding padding). void CopyFrom(const Buffer &a); @@ -170,6 +176,24 @@ void Buffer::Set(ACMRandom *rand_class, T (ACMRandom::*rand_func)()) { } } +template +void Buffer::Set(ACMRandom *rand_class, const int32_t low, + const int32_t high) { + if (!raw_buffer_) return; + + EXPECT_LE(low, high); + EXPECT_GE(low, std::numeric_limits::min()); + EXPECT_LE(high, std::numeric_limits::max()); + + T *src = TopLeftPixel(); + for (int height = 0; height < height_; ++height) { + for (int width = 0; width < width_; ++width) { + src[width] = static_cast((*rand_class).RandRange(high - low) + low); + } + src += stride_; + } +} + template void Buffer::CopyFrom(const Buffer &a) { if (!raw_buffer_) return; diff --git a/test/dct_partial_test.cc b/test/dct_partial_test.cc index f5c75a4ad..5863ce776 100644 --- a/test/dct_partial_test.cc +++ b/test/dct_partial_test.cc @@ -83,12 +83,7 @@ class PartialFdctTest : public ::testing::TestWithParam { } else if (i == 1) { input_block.Set(minvalue); } else { - for (int y = 0; y < size_; ++y) { - for (int x = 0; x < size_; ++x) { - input_block.TopLeftPixel()[y * input_block.stride() + x] = - clamp((rnd.Rand16() - rnd.Rand16()), minvalue, maxvalue); - } - } + input_block.Set(&rnd, minvalue, maxvalue); } ASM_REGISTER_STATE_CHECK(fwd_txfm_(input_block.TopLeftPixel(), diff --git a/test/dct_test.cc b/test/dct_test.cc index f7078f078..0610de600 100644 --- a/test/dct_test.cc +++ b/test/dct_test.cc @@ -166,11 +166,10 @@ class TransTestBase { } #if CONFIG_VP9_HIGHBITDEPTH } else { + src16.Set(&rnd, 0, max_pixel_value_); + dst16.Set(&rnd, 0, max_pixel_value_); for (int h = 0; h < size_; ++h) { for (int w = 0; w < size_; ++w) { - src16.TopLeftPixel()[h * src16.stride() + w] = rnd.Rand16() & mask_; - dst16.TopLeftPixel()[h * dst16.stride() + w] = rnd.Rand16() & mask_; - test_input_block.TopLeftPixel()[h * test_input_block.stride() + w] = src16.TopLeftPixel()[h * src16.stride() + w] - dst16.TopLeftPixel()[h * dst16.stride() + w]; @@ -231,13 +230,9 @@ class TransTestBase { ASSERT_TRUE(output_block.Init()); for (int i = 0; i < count_test_block; ++i) { - // Initialize a test block with input range [-mask_, mask_]. - for (int h = 0; h < size_; ++h) { - for (int w = 0; w < size_; ++w) { - input_block.TopLeftPixel()[h * input_block.stride() + w] = - (rnd.Rand16() & mask_) - (rnd.Rand16() & mask_); - } - } + // Initialize a test block with input range [-max_pixel_value_, + // max_pixel_value_]. + input_block.Set(&rnd, -max_pixel_value_, max_pixel_value_); fwd_txfm_ref(input_block, &output_ref_block, size_, tx_type_); ASM_REGISTER_STATE_CHECK(RunFwdTxfm(input_block, &output_block)); @@ -264,17 +259,17 @@ class TransTestBase { ASSERT_TRUE(output_block.Init()); for (int i = 0; i < count_test_block; ++i) { - // Initialize a test block with -mask_ or mask_. + // Initialize a test block with -max_pixel_value_ or max_pixel_value_. if (i == 0) { - input_extreme_block.Set(mask_); + input_extreme_block.Set(max_pixel_value_); } else if (i == 1) { - input_extreme_block.Set(-mask_); + input_extreme_block.Set(-max_pixel_value_); } else { for (int h = 0; h < size_; ++h) { for (int w = 0; w < size_; ++w) { input_extreme_block .TopLeftPixel()[h * input_extreme_block.stride() + w] = - rnd.Rand8() % 2 ? mask_ : -mask_; + rnd.Rand8() % 2 ? max_pixel_value_ : -max_pixel_value_; } } } @@ -319,7 +314,8 @@ class TransTestBase { ASSERT_TRUE(src16.Init()); for (int i = 0; i < count_test_block; ++i) { - // Initialize a test block with input range [-mask_, mask_]. + // Initialize a test block with input range [-max_pixel_value_, + // max_pixel_value_]. if (bit_depth_ == VPX_BITS_8) { src.Set(&rnd, &ACMRandom::Rand8); dst.Set(&rnd, &ACMRandom::Rand8); @@ -332,10 +328,10 @@ class TransTestBase { } #if CONFIG_VP9_HIGHBITDEPTH } else { + src16.Set(&rnd, 0, max_pixel_value_); + dst16.Set(&rnd, 0, max_pixel_value_); for (int h = 0; h < size_; ++h) { for (int w = 0; w < size_; ++w) { - src16.TopLeftPixel()[h * src16.stride() + w] = rnd.Rand16() & mask_; - dst16.TopLeftPixel()[h * dst16.stride() + w] = rnd.Rand16() & mask_; in.TopLeftPixel()[h * in.stride() + w] = src16.TopLeftPixel()[h * src16.stride() + w] - dst16.TopLeftPixel()[h * dst16.stride() + w]; @@ -381,7 +377,7 @@ class TransTestBase { FhtFuncRef fwd_txfm_ref; vpx_bit_depth_t bit_depth_; int tx_type_; - int mask_; + int max_pixel_value_; int size_; }; @@ -395,7 +391,7 @@ class TransDCT : public TransTestBase, size_ = GET_PARAM(2); tx_type_ = GET_PARAM(3); bit_depth_ = GET_PARAM(4); - mask_ = (1 << bit_depth_) - 1; + max_pixel_value_ = (1 << bit_depth_) - 1; } protected: @@ -566,7 +562,7 @@ class TransHT : public TransTestBase, public ::testing::TestWithParam { size_ = GET_PARAM(2); tx_type_ = GET_PARAM(3); bit_depth_ = GET_PARAM(4); - mask_ = (1 << bit_depth_) - 1; + max_pixel_value_ = (1 << bit_depth_) - 1; } protected: @@ -687,7 +683,7 @@ class TransWHT : public TransTestBase, size_ = GET_PARAM(2); tx_type_ = GET_PARAM(3); bit_depth_ = GET_PARAM(4); - mask_ = (1 << bit_depth_) - 1; + max_pixel_value_ = (1 << bit_depth_) - 1; } protected: