Add a check-zzuf-s-seed that tests whether all bits in a sequence have a

chance of being toggled.
This commit is contained in:
Sam Hocevar 2010-01-18 02:02:12 +00:00 committed by sam
parent 36058474dc
commit 254eeacc6d
4 changed files with 130 additions and 1 deletions

1
.gitignore vendored
View File

@ -27,6 +27,7 @@ src/zzuf
src/zzcat
test/zzero
test/zznop
test/zzone
test/bug-div0
test/bug-memory
test/bug-overflow

View File

@ -1,7 +1,7 @@
EXTRA_DIST = $(TESTS) functions.inc file-00 file-ff file-random file-text
noinst_PROGRAMS = zzero zznop bug-overflow bug-memory bug-div0
noinst_PROGRAMS = zzero zznop zzone bug-overflow bug-memory bug-div0
TESTS = check-zzuf-A-autoinc \
check-zzuf-f-fuzzing \

43
test/check-zzuf-s-seed Executable file
View File

@ -0,0 +1,43 @@
#!/bin/sh
#
# check-zzuf-s-seed - zzuf seed efficiency statistic tests
# Copyright (c) 2008-2010 Sam Hocevar <sam@hocevar.net>
# All Rights Reserved
#
# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# http://sam.zoy.org/wtfpl/COPYING for more details.
#
. "$(dirname "$0")/functions.inc"
start_test "zzuf -s test"
for ratio in 1 0.1 0.01 0.001 0.0001; do
if test $ratio = 0.0001; then
bytes=1024
elif test $ratio = 0.001; then
bytes=8192
else
bytes=32768
fi
new_test "$bytes B of zeroes, ratio $ratio"
zeroes=$(expr $bytes '*' 4)
passes=10
while test $zeroes -gt 0 -a $passes -lt 200000; do
printf " doing $passes passes..."
zeroes=$($ZZUF -r $ratio -s $seed -A $ZZCAT -r $passes -x "fread(1,$bytes)" /dev/zero | $DIR/zzone $bytes $passes)
echo " $zeroes"
passes=$(expr '(' $passes '*' 7 + 3 ')' / 4)
done
if test $passes -lt 2000000; then
pass_test " ok"
else
pass_test " FAILED"
fi
done
stop_test

85
test/zzone.c Normal file
View File

@ -0,0 +1,85 @@
/*
* zzone - check that all bits are set to one after some time
* Copyright (c) 2010 Sam Hocevar <sam@hocevar.net>
* All Rights Reserved
*
* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#if defined HAVE_STDINT_H
# include <stdint.h>
#elif defined HAVE_INTTYPES_H
# include <inttypes.h>
#endif
#include <string.h>
int zero[16] =
{
4, 3, 3, 2, 3, 2, 2, 1, 3, 2, 2, 1, 2, 1, 1, 0
};
int main(int argc, char *argv[])
{
uint8_t *buf, *tmp;
size_t i, last, size, count;
if (argc != 3)
{
fprintf(stderr, "usage: zzone <size> <count>\n");
return EXIT_FAILURE;
}
size = atoi(argv[1]);
count = atoi(argv[2]);
last = 0;
buf = malloc(size);
tmp = malloc(size);
if (!buf || !tmp)
{
fprintf(stderr, "zzone: cannot alloc memory\n");
return EXIT_FAILURE;
}
memset(buf, 0x00, size);
while (count--)
{
fread(tmp, size, 1, stdin);
for (i = last; i < size; i++)
{
buf[i] |= tmp[i];
}
while (last < size && buf[last] == 0xff)
last++;
}
free(buf);
free(tmp);
if (last != size)
{
size_t zeros = 0;
for (i = last; i < size; i++)
{
zeros += zero[buf[i] & 0xf];
zeros += zero[buf[i] >> 4];
}
printf("%li\n", (long)zeros);
}
else
{
puts("0");
}
return EXIT_SUCCESS;
}