| Revision 2564,
1.8 KB
checked in by sam, 5 years ago
(diff) |
- Make the RNG test shorter... it should not vary across platforms anyway.
|
-
Property svn:executable set to
*
|
| Line | |
|---|
| 1 | #!/bin/sh |
|---|
| 2 | |
|---|
| 3 | set -e |
|---|
| 4 | |
|---|
| 5 | checkflip() |
|---|
| 6 | { |
|---|
| 7 | r=$1 |
|---|
| 8 | expect=$2 |
|---|
| 9 | s2=$seed |
|---|
| 10 | mib=20 |
|---|
| 11 | echo "*** $mib MiB of zeroes, ratio $r ***" |
|---|
| 12 | rmax=-1 |
|---|
| 13 | rmin=-1 |
|---|
| 14 | rtot=0 |
|---|
| 15 | for x in 0 1 2 3 4; do |
|---|
| 16 | ret=`dd if=/dev/zero bs=1048576 count=$mib 2>/dev/null | "$ZZUF" -s $s2 -r $r | "$ZZERO"` |
|---|
| 17 | if [ "$rmax" = -1 -o "$ret" -gt "$rmax" ]; then rmax=$ret; fi |
|---|
| 18 | if [ "$rmin" = -1 -o "$ret" -lt "$rmin" ]; then rmin=$ret; fi |
|---|
| 19 | rtot=`expr $rtot + $ret || true` |
|---|
| 20 | echo " try $x .......... $ret" |
|---|
| 21 | s2=`expr $s2 + 1` |
|---|
| 22 | done |
|---|
| 23 | rmean=`expr '(' $rtot + 2 ')' / 5 || true` |
|---|
| 24 | delta=`expr $rmean - $expect || true` |
|---|
| 25 | if [ "$delta" -gt -5 -a "$delta" -lt 5 ]; then |
|---|
| 26 | result="ok" |
|---|
| 27 | elif [ $(($rmean * 8)) -lt $(($expect * 7)) \ |
|---|
| 28 | -o $(($rmean * 7)) -gt $(($expect * 8)) ]; then |
|---|
| 29 | result="FAILED" |
|---|
| 30 | FAILED=$(($FAILED + 1)) |
|---|
| 31 | else |
|---|
| 32 | result="ok" |
|---|
| 33 | fi |
|---|
| 34 | TESTED=$(($TESTED + 1)) |
|---|
| 35 | echo " expected $expect min/avg/max $rmin/$rmean/$rmax .......... $result" |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | DIR="$(dirname "$0")" |
|---|
| 39 | ZZUF="$DIR/../src/zzuf" |
|---|
| 40 | ZZERO="$DIR/zzero" |
|---|
| 41 | if [ ! -f "$ZZERO" ]; then |
|---|
| 42 | echo "error: test/zzero is missing" |
|---|
| 43 | exit 1 |
|---|
| 44 | fi |
|---|
| 45 | FAILED=0 |
|---|
| 46 | TESTED=0 |
|---|
| 47 | |
|---|
| 48 | if [ -z "$1" ]; then |
|---|
| 49 | seed=$(date | $ZZUF -m 2>/dev/null | cut -f2 -d' ' | tr -d abcdef | cut -b1-8) |
|---|
| 50 | else |
|---|
| 51 | seed="$1" |
|---|
| 52 | fi |
|---|
| 53 | |
|---|
| 54 | echo "*** running zzuf RNG test suite with seed $seed ***" |
|---|
| 55 | |
|---|
| 56 | # if X flips are performed on N bits set to 0, the average number of bits |
|---|
| 57 | # set to 1 is: N / 2 * (1 - pow(1 - 2 / N, X) |
|---|
| 58 | checkflip 0.000000001 0 |
|---|
| 59 | checkflip 0.00000001 1 |
|---|
| 60 | checkflip 0.0000001 16 |
|---|
| 61 | checkflip 0.000001 167 |
|---|
| 62 | checkflip 0.00001 1677 |
|---|
| 63 | checkflip 0.0001 16775 |
|---|
| 64 | checkflip 0.001 167604 |
|---|
| 65 | checkflip 0.01 1661055 |
|---|
| 66 | checkflip 0.1 15205967 |
|---|
| 67 | |
|---|
| 68 | if [ "$FAILED" != 0 ]; then |
|---|
| 69 | echo "*** $FAILED tests failed out of $TESTED ***" |
|---|
| 70 | exit 1 |
|---|
| 71 | fi |
|---|
| 72 | echo "*** all $TESTED tests OK ***" |
|---|
| 73 | |
|---|
| 74 | exit 0 |
|---|
| 75 | |
|---|
Note: See
TracBrowser
for help on using the repository browser.