{"thread":{"id":"7610","subject":"[PATCH 1/2] simple random data generator for tests","startedAt":"2007-04-11T17:33:50Z","lastAt":"2007-04-11T17:59:51Z","messageCount":4,"participants":["Nicolas Pitre","Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"39124","messageId":"alpine.LFD.0.98.0704111330120.28181@xanadu.home","threadId":"7610","inReplyTo":null,"subject":"[PATCH 1/2] simple random data generator for tests","fromName":"Nicolas Pitre","fromEmail":"nico@cam.org","sentAt":"2007-04-11T17:33:50Z","receivedAt":"2007-04-11T17:33:50Z","isPatch":true,"sender":{"key":"nico@fluxnic.net","avatar":"https://avatars.githubusercontent.com/u/702790?v=4"},"body":"Reliance on /dev/urandom produces test vectors that are, well, random. \nThis can create problems impossible to track down when the data is \ndifferent from one test invokation to another.\n\nThe goal is not to have random data to test, but rather to have a \nconvenient way to create sets of large files with non compressible and \nnon deltifiable data in a reproducible way.\n\nSigned-off-by: Nicolas Pitre <nico@cam.org>\n---\n Makefile         |    7 +++++--\n test-genrandom.c |   34 ++++++++++++++++++++++++++++++++++\n 2 files changed, 39 insertions(+), 2 deletions(-)\n create mode 100644 test-genrandom.c\n\ndiff --git a/Makefile b/Makefile\nindex a77d31d..bd0ba95 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -932,7 +932,7 @@ endif\n \n export NO_SVN_TESTS\n \n-test: all test-chmtime$X\n+test: all test-chmtime$X test-genrandom$X\n \t$(MAKE) -C t/ all\n \n test-date$X: test-date.c date.o ctype.o\n@@ -953,6 +953,9 @@ test-match-trees$X: test-match-trees.o $(GITLIBS)\n test-chmtime$X: test-chmtime.c\n \t$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $<\n \n+test-genrandom$X: test-genrandom.c\n+\t$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $<\n+\n check-sha1:: test-sha1$X\n \t./test-sha1.sh\n \n@@ -1041,7 +1044,7 @@ dist-doc:\n \n clean:\n \trm -f *.o mozilla-sha1/*.o arm/*.o ppc/*.o compat/*.o xdiff/*.o \\\n-\t\ttest-chmtime$X $(LIB_FILE) $(XDIFF_LIB)\n+\t\ttest-chmtime$X test-genrandom$X $(LIB_FILE) $(XDIFF_LIB)\n \trm -f $(ALL_PROGRAMS) $(BUILT_INS) git$X\n \trm -f *.spec *.pyc *.pyo */*.pyc */*.pyo common-cmds.h TAGS tags\n \trm -rf autom4te.cache\ndiff --git a/test-genrandom.c b/test-genrandom.c\nnew file mode 100644\nindex 0000000..6cc4650\n--- /dev/null\n+++ b/test-genrandom.c\n@@ -0,0 +1,34 @@\n+/*\n+ * Simple random data generator used to create reproducible test files.\n+ * This is inspired from POSIX.1-2001 implementation example for rand().\n+ * Copyright (C) 2007 by Nicolas Pitre, licensed under the GPL version 2.\n+ */\n+\n+#include <stdio.h>\n+#include <stdlib.h>\n+\n+int main(int argc, char *argv[])\n+{\n+\tunsigned long count, next = 0;\n+\tunsigned char *c;\n+\n+\tif (argc < 2 || argc > 3) {\n+\t\tfprintf( stderr, \"Usage: %s <seed_string> [<size>]\", argv[0]);\n+\t\treturn 1;\n+\t}\n+\n+\tc = (unsigned char *) argv[1];\n+\tdo {\n+\t\tnext = next * 11 + *c;\n+\t} while (*c++);\n+\t\n+\tcount = (argc == 3) ? strtoul(argv[2], NULL, 0) : -1L;\n+\n+\twhile (count--) {\n+\t\tnext = next * 1103515245 + 12345;\n+\t\tif (putchar((next >> 16) & 0xff) == EOF)\n+\t\t\treturn -1;\n+\t}\n+\n+\treturn 0;\n+}\n-- \n1.5.1.777.gd14d3-dirty\n"},{"id":"39126","messageId":"20070411174205.GQ5436@spearce.org","threadId":"7610","inReplyTo":"alpine.LFD.0.98.0704111330120.28181@xanadu.home","subject":"Re: [PATCH 1/2] simple random data generator for tests","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-04-11T17:42:05Z","receivedAt":"2007-04-11T17:42:05Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Nicolas Pitre <nico@cam.org> wrote:\n> ---\n>  Makefile         |    7 +++++--\n>  test-genrandom.c |   34 ++++++++++++++++++++++++++++++++++\n>  2 files changed, 39 insertions(+), 2 deletions(-)\n>  create mode 100644 test-genrandom.c\n\nA change to .gitignore would also be nice.  ;-)\n \n> +\tunsigned long count, next = 0;\n\nWhat about wraparound?  Could this produce different results on a\n32 bit system and a 64 bit system, due to the difference in size\nof unsigned long?\n\n-- \nShawn.\n"},{"id":"39127","messageId":"alpine.LFD.0.98.0704111348040.28181@xanadu.home","threadId":"7610","inReplyTo":"20070411174205.GQ5436@spearce.org","subject":"Re: [PATCH 1/2] simple random data generator for tests","fromName":"Nicolas Pitre","fromEmail":"nico@cam.org","sentAt":"2007-04-11T17:52:33Z","receivedAt":"2007-04-11T17:52:33Z","isPatch":true,"sender":{"key":"nico@fluxnic.net","avatar":"https://avatars.githubusercontent.com/u/702790?v=4"},"body":"On Wed, 11 Apr 2007, Shawn O. Pearce wrote:\n\n> Nicolas Pitre <nico@cam.org> wrote:\n> > ---\n> >  Makefile         |    7 +++++--\n> >  test-genrandom.c |   34 ++++++++++++++++++++++++++++++++++\n> >  2 files changed, 39 insertions(+), 2 deletions(-)\n> >  create mode 100644 test-genrandom.c\n> \n> A change to .gitignore would also be nice.  ;-)\n\nGah!\n\n> > +\tunsigned long count, next = 0;\n> \n> What about wraparound?  Could this produce different results on a\n> 32 bit system and a 64 bit system, due to the difference in size\n> of unsigned long?\n\nNo, because the bits we extract are below 32 bits, and the multiply \noperation will always provide the same results in the low 32 bits \nregardless.\n\n\nNicolas\n"},{"id":"39128","messageId":"alpine.LFD.0.98.0704111355390.28181@xanadu.home","threadId":"7610","inReplyTo":"alpine.LFD.0.98.0704111330120.28181@xanadu.home","subject":"[PATCH 1/2 (with .gitignore)] simple random data generator for tests","fromName":"Nicolas Pitre","fromEmail":"nico@cam.org","sentAt":"2007-04-11T17:59:51Z","receivedAt":"2007-04-11T17:59:51Z","isPatch":true,"sender":{"key":"nico@fluxnic.net","avatar":"https://avatars.githubusercontent.com/u/702790?v=4"},"body":"Reliance on /dev/urandom produces test vectors that are, well, random. \nThis can cause problems impossible to track down when the data is \ndifferent from one test invokation to another.\n\nThe goal is not to have random data to test, but rather to have a \nconvenient way to create sets of large files with non compressible and \nnon deltifiable data in a reproducible way.\n\nSigned-off-by: Nicolas Pitre <nico@cam.org>\n---\n\ndiff --git a/Makefile b/Makefile\nindex a77d31d..bd0ba95 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -932,7 +932,7 @@ endif\n \n export NO_SVN_TESTS\n \n-test: all test-chmtime$X\n+test: all test-chmtime$X test-genrandom$X\n \t$(MAKE) -C t/ all\n \n test-date$X: test-date.c date.o ctype.o\n@@ -953,6 +953,9 @@ test-match-trees$X: test-match-trees.o $(GITLIBS)\n test-chmtime$X: test-chmtime.c\n \t$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $<\n \n+test-genrandom$X: test-genrandom.c\n+\t$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $<\n+\n check-sha1:: test-sha1$X\n \t./test-sha1.sh\n \n@@ -1041,7 +1044,7 @@ dist-doc:\n \n clean:\n \trm -f *.o mozilla-sha1/*.o arm/*.o ppc/*.o compat/*.o xdiff/*.o \\\n-\t\ttest-chmtime$X $(LIB_FILE) $(XDIFF_LIB)\n+\t\ttest-chmtime$X test-genrandom$X $(LIB_FILE) $(XDIFF_LIB)\n \trm -f $(ALL_PROGRAMS) $(BUILT_INS) git$X\n \trm -f *.spec *.pyc *.pyo */*.pyc */*.pyo common-cmds.h TAGS tags\n \trm -rf autom4te.cache\ndiff --git a/test-genrandom.c b/test-genrandom.c\nnew file mode 100644\nindex 0000000..6cc4650\n--- /dev/null\n+++ b/test-genrandom.c\n@@ -0,0 +1,34 @@\n+/*\n+ * Simple random data generator used to create reproducible test files.\n+ * This is inspired from POSIX.1-2001 implementation example for rand().\n+ * Copyright (C) 2007 by Nicolas Pitre, licensed under the GPL version 2.\n+ */\n+\n+#include <stdio.h>\n+#include <stdlib.h>\n+\n+int main(int argc, char *argv[])\n+{\n+\tunsigned long count, next = 0;\n+\tunsigned char *c;\n+\n+\tif (argc < 2 || argc > 3) {\n+\t\tfprintf( stderr, \"Usage: %s <seed_string> [<size>]\", argv[0]);\n+\t\treturn 1;\n+\t}\n+\n+\tc = (unsigned char *) argv[1];\n+\tdo {\n+\t\tnext = next * 11 + *c;\n+\t} while (*c++);\n+\t\n+\tcount = (argc == 3) ? strtoul(argv[2], NULL, 0) : -1L;\n+\n+\twhile (count--) {\n+\t\tnext = next * 1103515245 + 12345;\n+\t\tif (putchar((next >> 16) & 0xff) == EOF)\n+\t\t\treturn -1;\n+\t}\n+\n+\treturn 0;\n+}\ndiff --git a/.gitignore b/.gitignore\nindex 9229e91..fa7ac93 100644\n--- a/.gitignore\n+++ b/.gitignore\n@@ -149,6 +149,7 @@ test-chmtime\n test-date\n test-delta\n test-dump-cache-tree\n+test-genrandom\n test-match-trees\n common-cmds.h\n *.tar.gz\n"}]}