ref: ce5b17f9ad936941eee61dfc5b3daebc02f0a5b6
parent: 89d3dc043e3e6c2a3a93b7162bd333802919e3c8
author: Johann <johannkoenig@google.com>
date: Wed Jun 28 10:33:38 EDT 2017
testing: ranges for random values Add a method to acm_random.h to generate ranges of values Add a way to call that method to buffer.h Adjust dct_[partial_]test.cc to use it. Change-Id: I8c23ae9d27612c28f050b0e44c41cb4ad2494086
--- 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 <assert.h>
+
+#include <limits>
+
#include "third_party/googletest/src/include/gtest/gtest.h"
#include "vpx/vpx_integer.h"
@@ -48,6 +52,13 @@
// saturation behavior.
const uint8_t r = Rand8();
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); }
--- a/test/buffer.h
+++ b/test/buffer.h
@@ -68,9 +68,15 @@
// 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<T> &a);
@@ -167,6 +173,24 @@
src[width] = (*rand_class.*rand_func)();
}
src += stride();
+ }
+}
+
+template <typename T>
+void Buffer<T>::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<T>::min());
+ EXPECT_LE(high, std::numeric_limits<T>::max());
+
+ T *src = TopLeftPixel();
+ for (int height = 0; height < height_; ++height) {
+ for (int width = 0; width < width_; ++width) {
+ src[width] = static_cast<T>((*rand_class).RandRange(high - low) + low);
+ }
+ src += stride_;
}
}
--- a/test/dct_partial_test.cc
+++ b/test/dct_partial_test.cc
@@ -83,12 +83,7 @@
} 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(),
--- a/test/dct_test.cc
+++ b/test/dct_test.cc
@@ -166,11 +166,10 @@
}
#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 @@
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 @@
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 @@
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 @@
}
#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 @@
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 @@
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 @@
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 @@
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: