Commit 2dca1af4 authored by Nicolas Pitre's avatar Nicolas Pitre Committed by Junio C Hamano

simple random data generator for tests

Reliance on /dev/urandom produces test vectors that are, well, random.
This can cause problems impossible to track down when the data is
different from one test invokation to another.

The goal is not to have random data to test, but rather to have a
convenient way to create sets of large files with non compressible and
non deltifiable data in a reproducible way.
Signed-off-by: default avatarNicolas Pitre <[email protected]>
Signed-off-by: default avatarJunio C Hamano <[email protected]>
parent 91ecbeca
......@@ -149,6 +149,7 @@ test-chmtime
......@@ -932,7 +932,7 @@ endif
test: all test-chmtime$X
test: all test-chmtime$X test-genrandom$X
$(MAKE) -C t/ all
test-date$X: test-date.c date.o ctype.o
......@@ -953,6 +953,9 @@ test-match-trees$X: test-match-trees.o $(GITLIBS)
test-chmtime$X: test-chmtime.c
$(CC) $(ALL_CFLAGS) -o [email protected] $(ALL_LDFLAGS) $<
test-genrandom$X: test-genrandom.c
$(CC) $(ALL_CFLAGS) -o [email protected] $(ALL_LDFLAGS) $<
check-sha1:: test-sha1$X
......@@ -1041,7 +1044,7 @@ dist-doc:
rm -f *.o mozilla-sha1/*.o arm/*.o ppc/*.o compat/*.o xdiff/*.o \
test-chmtime$X $(LIB_FILE) $(XDIFF_LIB)
test-chmtime$X test-genrandom$X $(LIB_FILE) $(XDIFF_LIB)
rm -f $(ALL_PROGRAMS) $(BUILT_INS) git$X
rm -f *.spec *.pyc *.pyo */*.pyc */*.pyo common-cmds.h TAGS tags
rm -rf autom4te.cache
* Simple random data generator used to create reproducible test files.
* This is inspired from POSIX.1-2001 implementation example for rand().
* Copyright (C) 2007 by Nicolas Pitre, licensed under the GPL version 2.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
unsigned long count, next = 0;
unsigned char *c;
if (argc < 2 || argc > 3) {
fprintf( stderr, "Usage: %s <seed_string> [<size>]", argv[0]);
return 1;
c = (unsigned char *) argv[1];
do {
next = next * 11 + *c;
} while (*c++);
count = (argc == 3) ? strtoul(argv[2], NULL, 0) : -1L;
while (count--) {
next = next * 1103515245 + 12345;
if (putchar((next >> 16) & 0xff) == EOF)
return -1;
return 0;
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment