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: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Nicolas Pitre committed
Apr 11, 2007 at 13:59 UTC
2dca1af44806924946828e2fdc82ea408353d286
3 files changed
+40
-2
.gitignore
+1
@@ -149,6 +149,7 @@ test-chmtime
149
test-date
150
test-delta
151
test-dump-cache-tree
152
+test-genrandom
153
test-match-trees
154
common-cmds.h
155
*.tar.gz
Makefile
+5
-2
@@ -932,7 +932,7 @@ endif
932
933
export NO_SVN_TESTS
934
935
-test: all test-chmtime$X
935
+test: all test-chmtime$X test-genrandom$X
936
$(MAKE) -C t/ all
937
938
test-date$X: test-date.c date.o ctype.o
@@ -953,6 +953,9 @@ test-match-trees$X: test-match-trees.o $(GITLIBS)
953
test-chmtime$X: test-chmtime.c
954
$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $<
955
956
+test-genrandom$X: test-genrandom.c
957
+ $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $<
958
+
959
check-sha1:: test-sha1$X
960
./test-sha1.sh
961
@@ -1041,7 +1044,7 @@ dist-doc:
1044
1045
clean:
1046
rm -f *.o mozilla-sha1/*.o arm/*.o ppc/*.o compat/*.o xdiff/*.o \
1044
- test-chmtime$X $(LIB_FILE) $(XDIFF_LIB)
1047
+ test-chmtime$X test-genrandom$X $(LIB_FILE) $(XDIFF_LIB)
1048
rm -f $(ALL_PROGRAMS) $(BUILT_INS) git$X
1049
rm -f *.spec *.pyc *.pyo */*.pyc */*.pyo common-cmds.h TAGS tags
1050
rm -rf autom4te.cache
test-genrandom.c
new
+34
@@ -0,0 +1,34 @@
1
+/*
2
+ * Simple random data generator used to create reproducible test files.
3
+ * This is inspired from POSIX.1-2001 implementation example for rand().
4
+ * Copyright (C) 2007 by Nicolas Pitre, licensed under the GPL version 2.
5
+ */
6
+
7
+#include <stdio.h>
8
+#include <stdlib.h>
9
+
10
+int main(int argc, char *argv[])
11
+{
12
+ unsigned long count, next = 0;
13
+ unsigned char *c;
14
+
15
+ if (argc < 2 || argc > 3) {
16
+ fprintf( stderr, "Usage: %s <seed_string> [<size>]", argv[0]);
17
+ return 1;
18
+ }
19
+
20
+ c = (unsigned char *) argv[1];
21
+ do {
22
+ next = next * 11 + *c;
23
+ } while (*c++);
24
+
25
+ count = (argc == 3) ? strtoul(argv[2], NULL, 0) : -1L;
26
+
27
+ while (count--) {
28
+ next = next * 1103515245 + 12345;
29
+ if (putchar((next >> 16) & 0xff) == EOF)
30
+ return -1;
31
+ }
32
+
33
+ return 0;
34
+}