source: zzuf/trunk/test/check-rng @ 2564

Last change on this file since 2564 was 2564, checked in by Sam Hocevar, 14 years ago
  • Make the RNG test shorter... it should not vary across platforms anyway.
  • Property svn:executable set to *
File size: 1.8 KB
Line 
1#!/bin/sh
2
3set -e
4
5checkflip()
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
38DIR="$(dirname "$0")"
39ZZUF="$DIR/../src/zzuf"
40ZZERO="$DIR/zzero"
41if [ ! -f "$ZZERO" ]; then
42  echo "error: test/zzero is missing"
43  exit 1
44fi
45FAILED=0
46TESTED=0
47
48if [ -z "$1" ]; then
49  seed=$(date | $ZZUF -m 2>/dev/null | cut -f2 -d' ' | tr -d abcdef | cut -b1-8)
50else
51  seed="$1"
52fi
53
54echo "*** 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)
58checkflip 0.000000001 0
59checkflip 0.00000001  1
60checkflip 0.0000001  16
61checkflip 0.000001  167
62checkflip 0.00001  1677
63checkflip 0.0001  16775
64checkflip 0.001  167604
65checkflip 0.01  1661055
66checkflip 0.1  15205967
67
68if [ "$FAILED" != 0 ]; then
69    echo "*** $FAILED tests failed out of $TESTED ***"
70    exit 1
71fi
72echo "*** all $TESTED tests OK ***"
73
74exit 0
75
Note: See TracBrowser for help on using the repository browser.