[FFmpeg-devel] [PATCH 1/2] random_seed: add selftest

Michael Niedermayer michaelni at gmx.at
Wed Feb 22 22:35:02 CET 2012


Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
---
 libavutil/Makefile      |    2 +-
 libavutil/random_seed.c |   26 ++++++++++++++++++++++++++
 2 files changed, 27 insertions(+), 1 deletions(-)

diff --git a/libavutil/Makefile b/libavutil/Makefile
index 6d78bd5..23049f6 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -83,7 +83,7 @@ OBJS-$(ARCH_X86) += x86/cpu.o
 
 
 TESTPROGS = adler32 aes avstring base64 cpu crc des eval file fifo lfg lls \
-            md5 opt pca parseutils rational sha tree
+            md5 opt pca parseutils random_seed rational sha tree
 TESTPROGS-$(HAVE_LZO1X_999_COMPRESS) += lzo
 
 TOOLS = ffeval
diff --git a/libavutil/random_seed.c b/libavutil/random_seed.c
index 235028b..92b4907 100644
--- a/libavutil/random_seed.c
+++ b/libavutil/random_seed.c
@@ -80,3 +80,29 @@ uint32_t av_get_random_seed(void)
         return seed;
     return get_generic_seed();
 }
+
+#ifdef TEST
+#undef printf
+#define N 256
+#include <stdio.h>
+
+int main(int argc, char **argv)
+{
+    int i, j, retry;
+    uint32_t seeds[N];
+
+    for (retry=0; retry<3; retry++){
+        for (i=0; i<N; i++){
+            seeds[i] = av_get_random_seed();
+            for (j=0; j<i; j++)
+                if (seeds[j] == seeds[i])
+                    goto retry;
+        }
+        printf("seeds OK\n");
+        return 0;
+        retry:;
+    }
+    printf("FAIL at %d with %X\n", j, seeds[j]);
+    return 1;
+}
+#endif
-- 
1.7.5.4



More information about the ffmpeg-devel mailing list