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
This commit is contained in:
Johann 2017-06-28 14:33:38 -07:00
parent 89d3dc043e
commit ce5b17f9ad
4 changed files with 54 additions and 28 deletions

View File

@ -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"
@ -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); }

View File

@ -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<T> &a);
@ -170,6 +176,24 @@ void Buffer<T>::Set(ACMRandom *rand_class, T (ACMRandom::*rand_func)()) {
}
}
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_;
}
}
template <typename T>
void Buffer<T>::CopyFrom(const Buffer<T> &a) {
if (!raw_buffer_) return;

View File

@ -83,12 +83,7 @@ class PartialFdctTest : public ::testing::TestWithParam<PartialFdctParam> {
} 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(),

View File

@ -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<HtParam> {
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: