* [PATCH 1/2] simple random data generator for tests
@ 2007-04-11 17:33 Nicolas Pitre
2007-04-11 17:42 ` Shawn O. Pearce
2007-04-11 17:59 ` [PATCH 1/2 (with .gitignore)] " Nicolas Pitre
0 siblings, 2 replies; 4+ messages in thread
From: Nicolas Pitre @ 2007-04-11 17:33 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
Reliance on /dev/urandom produces test vectors that are, well, random.
This can create 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>
---
Makefile | 7 +++++--
test-genrandom.c | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 39 insertions(+), 2 deletions(-)
create mode 100644 test-genrandom.c
diff --git a/Makefile b/Makefile
index a77d31d..bd0ba95 100644
--- a/Makefile
+++ b/Makefile
@@ -932,7 +932,7 @@ endif
export NO_SVN_TESTS
-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 $@ $(ALL_LDFLAGS) $<
+test-genrandom$X: test-genrandom.c
+ $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $<
+
check-sha1:: test-sha1$X
./test-sha1.sh
@@ -1041,7 +1044,7 @@ dist-doc:
clean:
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
diff --git a/test-genrandom.c b/test-genrandom.c
new file mode 100644
index 0000000..6cc4650
--- /dev/null
+++ b/test-genrandom.c
@@ -0,0 +1,34 @@
+/*
+ * 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;
+}
--
1.5.1.777.gd14d3-dirty
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH 1/2] simple random data generator for tests
2007-04-11 17:33 [PATCH 1/2] simple random data generator for tests Nicolas Pitre
@ 2007-04-11 17:42 ` Shawn O. Pearce
2007-04-11 17:52 ` Nicolas Pitre
2007-04-11 17:59 ` [PATCH 1/2 (with .gitignore)] " Nicolas Pitre
1 sibling, 1 reply; 4+ messages in thread
From: Shawn O. Pearce @ 2007-04-11 17:42 UTC (permalink / raw)
To: Nicolas Pitre; +Cc: Junio C Hamano, git
Nicolas Pitre <nico@cam.org> wrote:
> ---
> Makefile | 7 +++++--
> test-genrandom.c | 34 ++++++++++++++++++++++++++++++++++
> 2 files changed, 39 insertions(+), 2 deletions(-)
> create mode 100644 test-genrandom.c
A change to .gitignore would also be nice. ;-)
> + unsigned long count, next = 0;
What about wraparound? Could this produce different results on a
32 bit system and a 64 bit system, due to the difference in size
of unsigned long?
--
Shawn.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] simple random data generator for tests
2007-04-11 17:42 ` Shawn O. Pearce
@ 2007-04-11 17:52 ` Nicolas Pitre
0 siblings, 0 replies; 4+ messages in thread
From: Nicolas Pitre @ 2007-04-11 17:52 UTC (permalink / raw)
To: Shawn O. Pearce; +Cc: Junio C Hamano, git
On Wed, 11 Apr 2007, Shawn O. Pearce wrote:
> Nicolas Pitre <nico@cam.org> wrote:
> > ---
> > Makefile | 7 +++++--
> > test-genrandom.c | 34 ++++++++++++++++++++++++++++++++++
> > 2 files changed, 39 insertions(+), 2 deletions(-)
> > create mode 100644 test-genrandom.c
>
> A change to .gitignore would also be nice. ;-)
Gah!
> > + unsigned long count, next = 0;
>
> What about wraparound? Could this produce different results on a
> 32 bit system and a 64 bit system, due to the difference in size
> of unsigned long?
No, because the bits we extract are below 32 bits, and the multiply
operation will always provide the same results in the low 32 bits
regardless.
Nicolas
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2 (with .gitignore)] simple random data generator for tests
2007-04-11 17:33 [PATCH 1/2] simple random data generator for tests Nicolas Pitre
2007-04-11 17:42 ` Shawn O. Pearce
@ 2007-04-11 17:59 ` Nicolas Pitre
1 sibling, 0 replies; 4+ messages in thread
From: Nicolas Pitre @ 2007-04-11 17:59 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
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>
---
diff --git a/Makefile b/Makefile
index a77d31d..bd0ba95 100644
--- a/Makefile
+++ b/Makefile
@@ -932,7 +932,7 @@ endif
export NO_SVN_TESTS
-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 $@ $(ALL_LDFLAGS) $<
+test-genrandom$X: test-genrandom.c
+ $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $<
+
check-sha1:: test-sha1$X
./test-sha1.sh
@@ -1041,7 +1044,7 @@ dist-doc:
clean:
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
diff --git a/test-genrandom.c b/test-genrandom.c
new file mode 100644
index 0000000..6cc4650
--- /dev/null
+++ b/test-genrandom.c
@@ -0,0 +1,34 @@
+/*
+ * 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;
+}
diff --git a/.gitignore b/.gitignore
index 9229e91..fa7ac93 100644
--- a/.gitignore
+++ b/.gitignore
@@ -149,6 +149,7 @@ test-chmtime
test-date
test-delta
test-dump-cache-tree
+test-genrandom
test-match-trees
common-cmds.h
*.tar.gz
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-04-11 17:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-11 17:33 [PATCH 1/2] simple random data generator for tests Nicolas Pitre
2007-04-11 17:42 ` Shawn O. Pearce
2007-04-11 17:52 ` Nicolas Pitre
2007-04-11 17:59 ` [PATCH 1/2 (with .gitignore)] " Nicolas Pitre
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.