]> granicus.if.org Git - libvpx/commitdiff
tests: use a portable rand() implementation
authorJames Zern <jzern@google.com>
Fri, 5 Apr 2013 02:00:31 +0000 (19:00 -0700)
committerJames Zern <jzern@google.com>
Fri, 5 Apr 2013 02:29:33 +0000 (19:29 -0700)
the one from gtest in this case: testing::internal::Random.
this will make the tests deterministic between platforms. addresses
issue #568.

Change-Id: I5a8a92f5c33f52cb0a219c1dd3d02335acbbf163

test/acm_random.h
test/fdct8x8_test.cc

index 514894edaf7758289c42925a28d09f85e92b10aa..13903c66ae67da778ff2dc9c88a85f7c200ba0b8 100644 (file)
@@ -11,7 +11,7 @@
 #ifndef LIBVPX_TEST_ACM_RANDOM_H_
 #define LIBVPX_TEST_ACM_RANDOM_H_
 
-#include <stdlib.h>
+#include "third_party/googletest/src/include/gtest/gtest.h"
 
 #include "vpx/vpx_integer.h"
 
@@ -19,24 +19,23 @@ namespace libvpx_test {
 
 class ACMRandom {
  public:
-  ACMRandom() {
-    Reset(DeterministicSeed());
-  }
+  ACMRandom() : random_(DeterministicSeed()) {}
 
-  explicit ACMRandom(int seed) {
-    Reset(seed);
-  }
+  explicit ACMRandom(int seed) : random_(seed) {}
 
   void Reset(int seed) {
-    srand(seed);
+    random_.Reseed(seed);
   }
 
   uint8_t Rand8(void) {
-    return (rand() >> 8) & 0xff;
+    const uint32_t value =
+        random_.Generate(testing::internal::Random::kMaxRange);
+    // There's a bit more entropy in the upper bits of this implementation.
+    return (value >> 24) & 0xff;
   }
 
   int PseudoUniform(int range) {
-    return (rand() >> 8) % range;
+    return random_.Generate(range);
   }
 
   int operator()(int n) {
@@ -46,6 +45,9 @@ class ACMRandom {
   static int DeterministicSeed(void) {
     return 0xbaba;
   }
+
+ private:
+  testing::internal::Random random_;
 };
 
 }  // namespace libvpx_test
index d82f7c3bdcbe8976a34deea604d7ee2ce1a5a8f7..5967d36c4a597c1bda5856785d3eec21cd64370e 100644 (file)
@@ -51,11 +51,15 @@ TEST(VP9Fdct8x8Test, SignBiasCheck) {
   }
 
   for (int j = 0; j < 64; ++j) {
-    const bool bias_acceptable = (abs(count_sign_block[j][0] -
-                                      count_sign_block[j][1]) < 1000);
-    EXPECT_TRUE(bias_acceptable)
-        << "Error: 8x8 FDCT has a sign bias > 1%"
-        << " for input range [-255, 255] at index " << j;
+    const int diff = abs(count_sign_block[j][0] - count_sign_block[j][1]);
+    const int max_diff = 1125;
+    EXPECT_LT(diff, max_diff)
+        << "Error: 8x8 FDCT has a sign bias > "
+        << 1. * max_diff / count_test_block * 100 << "%"
+        << " for input range [-255, 255] at index " << j
+        << " count0: " << count_sign_block[j][0]
+        << " count1: " << count_sign_block[j][1]
+        << " diff: " << diff;
   }
 
   memset(count_sign_block, 0, sizeof(count_sign_block));
@@ -76,11 +80,15 @@ TEST(VP9Fdct8x8Test, SignBiasCheck) {
   }
 
   for (int j = 0; j < 64; ++j) {
-    const bool bias_acceptable = (abs(count_sign_block[j][0] -
-                                      count_sign_block[j][1]) < 10000);
-    EXPECT_TRUE(bias_acceptable)
-        << "Error: 8x8 FDCT has a sign bias > 10%"
-        << " for input range [-15, 15] at index " << j;
+    const int diff = abs(count_sign_block[j][0] - count_sign_block[j][1]);
+    const int max_diff = 10000;
+    EXPECT_LT(diff, max_diff)
+        << "Error: 4x4 FDCT has a sign bias > "
+        << 1. * max_diff / count_test_block * 100 << "%"
+        << " for input range [-15, 15] at index " << j
+        << " count0: " << count_sign_block[j][0]
+        << " count1: " << count_sign_block[j][1]
+        << " diff: " << diff;
   }
 };