Commit 48ab3cf3 authored by fbarchard@google.com's avatar fbarchard@google.com

Over unittest crash on divide overflow.

BUG=299
TESTED=try
R=wuwang@google.com

Review URL: https://webrtc-codereview.appspot.com/6469004

git-svn-id: http://libyuv.googlecode.com/svn/trunk@933 16f28f9a-4ce2-e073-06de-1de4eb20be90
parent 9fd689e5
Name: libyuv
URL: http://code.google.com/p/libyuv/
Version: 932
Version: 933
License: BSD
License File: LICENSE
......
......@@ -11,6 +11,6 @@
#ifndef INCLUDE_LIBYUV_VERSION_H_ // NOLINT
#define INCLUDE_LIBYUV_VERSION_H_
#define LIBYUV_VERSION 932
#define LIBYUV_VERSION 933
#endif // INCLUDE_LIBYUV_VERSION_H_ NOLINT
......@@ -19,10 +19,16 @@
namespace libyuv {
TEST_F(libyuvTest, TestFixedDiv) {
int num[256];
int div[256];
int result_opt[256];
int result_c[256];
int num[1280];
int div[1280];
int result_opt[1280];
int result_c[1280];
EXPECT_EQ(0x10000, libyuv::FixedDiv(1, 1));
EXPECT_EQ(0x7fff0000, libyuv::FixedDiv(0x7fff, 1));
// TODO(fbarchard): Avoid the following that throw exceptions.
// EXPECT_EQ(0x10000, libyuv::FixedDiv(0x10000, 1));
// EXPECT_EQ(0x80000000, libyuv::FixedDiv(0x8000, 1));
EXPECT_EQ(0x20000, libyuv::FixedDiv(640 * 2, 640));
EXPECT_EQ(0x30000, libyuv::FixedDiv(640 * 3, 640));
......@@ -60,32 +66,33 @@ TEST_F(libyuvTest, TestFixedDiv) {
srandom(time(NULL));
MemRandomize(reinterpret_cast<uint8*>(&num[0]), sizeof(num));
MemRandomize(reinterpret_cast<uint8*>(&div[0]), sizeof(div));
for (int j = 0; j < 256; ++j) {
for (int j = 0; j < 1280; ++j) {
if (div[j] == 0) {
div[j] = 1280;
}
num[j] &= 0xffff; // Clamp to avoid divide overflow.
}
for (int i = 0; i < benchmark_pixels_div256_; ++i) {
for (int j = 0; j < 256; ++j) {
for (int i = 0; i < benchmark_pixels_div1280_; ++i) {
for (int j = 0; j < 1280; ++j) {
result_opt[j] = libyuv::FixedDiv(num[j], div[j]);
}
}
for (int j = 0; j < 256; ++j) {
for (int j = 0; j < 1280; ++j) {
result_c[j] = libyuv::FixedDiv_C(num[j], div[j]);
EXPECT_NEAR(result_c[j], result_opt[j], 1);
}
}
TEST_F(libyuvTest, TestFixedDiv_Opt) {
int num[256];
int div[256];
int result_opt[256];
int result_c[256];
int num[1280];
int div[1280];
int result_opt[1280];
int result_c[1280];
srandom(time(NULL));
MemRandomize(reinterpret_cast<uint8*>(&num[0]), sizeof(num));
MemRandomize(reinterpret_cast<uint8*>(&div[0]), sizeof(div));
for (int j = 0; j < 256; ++j) {
for (int j = 0; j < 1280; ++j) {
num[j] &= 4095; // Make numerator smaller.
div[j] &= 4095; // Make divisor smaller.
if (div[j] == 0) {
......@@ -94,18 +101,18 @@ TEST_F(libyuvTest, TestFixedDiv_Opt) {
}
int has_x86 = TestCpuFlag(kCpuHasX86);
for (int i = 0; i < benchmark_pixels_div256_; ++i) {
for (int i = 0; i < benchmark_pixels_div1280_; ++i) {
if (has_x86) {
for (int j = 0; j < 256; ++j) {
for (int j = 0; j < 1280; ++j) {
result_opt[j] = libyuv::FixedDiv(num[j], div[j]);
}
} else {
for (int j = 0; j < 256; ++j) {
for (int j = 0; j < 1280; ++j) {
result_opt[j] = libyuv::FixedDiv_C(num[j], div[j]);
}
}
}
for (int j = 0; j < 256; ++j) {
for (int j = 0; j < 1280; ++j) {
result_c[j] = libyuv::FixedDiv_C(num[j], div[j]);
EXPECT_NEAR(result_c[j], result_opt[j], 1);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment