From a69b8cc7ed8f28b530d3d5087be03220b27fad18 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Wed, 3 Jan 2007 21:51:11 +0000 Subject: [PATCH] * Added a stupid PRNG to streamcat and fdcat. * Do not use sed in the testsuite, because of OS X. --- test/fdcat.c | 20 ++++++++++++++------ test/streamcat.c | 18 +++++++++++++----- test/testsuite.sh | 4 +++- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/test/fdcat.c b/test/fdcat.c index 8b4c9d3..669dd2d 100644 --- a/test/fdcat.c +++ b/test/fdcat.c @@ -24,14 +24,22 @@ #include #include +static inline int myrand(void) +{ + static int seed = 1; + int x, y; + x = (seed + 0x12345678) << 11; + y = (seed + 0xfedcba98) >> 21; + seed = x * 1010101 + y * 343434; + return seed; +} + int main(int argc, char *argv[]) { long int pos; unsigned char *data; int i, j, fd; - srand(0); - if(argc != 2) return EXIT_FAILURE; @@ -51,13 +59,13 @@ int main(int argc, char *argv[]) /* Read shit here and there */ for(i = 0; i < 128; i++) { - lseek(fd, rand() % pos, SEEK_SET); + lseek(fd, myrand() % pos, SEEK_SET); for(j = 0; j < 16; j++) - read(fd, data + lseek(fd, 0, SEEK_CUR), rand() % 4096); + read(fd, data + lseek(fd, 0, SEEK_CUR), myrand() % 4096); #ifdef HAVE_LSEEK64 - lseek64(fd, rand() % pos, SEEK_SET); + lseek64(fd, myrand() % pos, SEEK_SET); for(j = 0; j < 16; j++) - read(fd, data + lseek(fd, 0, SEEK_CUR), rand() % 4096); + read(fd, data + lseek(fd, 0, SEEK_CUR), myrand() % 4096); #endif } diff --git a/test/streamcat.c b/test/streamcat.c index 4b2977b..ce87ff6 100644 --- a/test/streamcat.c +++ b/test/streamcat.c @@ -18,6 +18,16 @@ #include #include +static inline int myrand(void) +{ + static int seed = 1; + int x, y; + x = (seed + 0x12345678) << 11; + y = (seed + 0xfedcba98) >> 21; + seed = x * 1010101 + y * 343434; + return seed; +} + int main(int argc, char *argv[]) { long int pos; @@ -25,8 +35,6 @@ int main(int argc, char *argv[]) int i, j; FILE *stream; - srand(0); - if(argc != 2) return EXIT_FAILURE; @@ -48,10 +56,10 @@ int main(int argc, char *argv[]) for(i = 0; i < 128; i++) { long int now; - fseek(stream, rand() % pos, SEEK_SET); + fseek(stream, myrand() % pos, SEEK_SET); for(j = 0; j < 16; j++) - fread(data + ftell(stream), rand() % 4096, 1, stream); - fseek(stream, rand() % pos, SEEK_SET); + fread(data + ftell(stream), myrand() % 4096, 1, stream); + fseek(stream, myrand() % pos, SEEK_SET); now = ftell(stream); for(j = 0; j < 16; j++) data[now + j] = getc(stream); diff --git a/test/testsuite.sh b/test/testsuite.sh index 5bd0dfc..2c59706 100755 --- a/test/testsuite.sh +++ b/test/testsuite.sh @@ -69,7 +69,9 @@ for file in /tmp/zzuf-zero-$$ /tmp/zzuf-text-$$ /tmp/zzuf-random-$$; do # We don't include grep in the testsuite because it puts a newline # at the end of its input if it was not there initially. #check $seed $r "grep -- -a \\'\\' $file" "grep -a" - check $seed $r "-- sed -e n $file" "sed n" + # We don't include sed in the testsuite because on OS X in also + # puts a newline. Crap. + #check $seed $r "-- sed -e n $file" "sed n" check $seed $r "dd bs=65536 if=$file" "dd(bs=65536)" check $seed $r "dd bs=1111 if=$file" "dd(bs=1111)" check $seed $r "dd bs=1024 if=$file" "dd(bs=1024)"