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

Last change on this file since 2545 was 2545, checked in by Sam Hocevar, 12 years ago
  • Add a bunch of unit tests to check for zzuf basic capabilities: SIGSEGV and SIGFPE detection, memory exhaustion detection.
  • 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    echo " expected ....... $expect"
13    rmax=-1
14    rmin=-1
15    rtot=0
16    for x in 0 1 2 3 4 5 6 7 8 9; do
17        ret=`dd if=/dev/zero bs=1048576 count=$mib 2>/dev/null | "$ZZUF" -s $s2 -r $r | "$ZZERO"`
18        if [ "$rmax" = -1 -o "$ret" -gt "$rmax" ]; then rmax=$ret; fi
19        if [ "$rmin" = -1 -o "$ret" -lt "$rmin" ]; then rmin=$ret; fi
20        rtot=`expr $rtot + $ret || true`
21        echo " try $x .......... $ret"
22        s2=`expr $s2 + 1`
23    done
24    rmean=`expr '(' $rtot + 5 ')' / 10 || true`
25    delta=`expr $rmean - $expect || true`
26    if [ "$delta" -gt -5 -a "$delta" -lt 5 ]; then
27        result="ok"
28    elif [ $(($rmean * 8)) -lt $(($expect * 7)) \
29               -o $(($rmean * 7)) -gt $(($expect * 8)) ]; then
30        result="FAILED"
31        FAILED=$(($FAILED + 1))
32    else
33        result="ok"
34    fi
35    TESTED=$(($TESTED + 1))
36    echo " min/avg/max $rmin/$rmean/$rmax .......... $result"
37}
38
39DIR="$(dirname "$0")"
40ZZUF="$DIR/../src/zzuf"
41ZZERO="$DIR/zzero"
42if [ ! -f "$ZZERO" ]; then
43  echo "error: test/zzero is missing"
44  exit 1
45fi
46FAILED=0
47TESTED=0
48
49if [ -z "$1" ]; then
50  seed=$(date | $ZZUF -m 2>/dev/null | cut -f2 -d' ' | tr -d abcdef | cut -b1-8)
51else
52  seed="$1"
53fi
54
55echo "*** running zzuf RNG test suite with seed $seed ***"
56
57# if X flips are performed on N bits set to 0, the average number of bits
58# set to 1 is: N / 2 * (1 - pow(1 - 2 / N, X)
59checkflip 0.000000001 0
60checkflip 0.00000001  1
61checkflip 0.0000001  16
62checkflip 0.000001  167
63checkflip 0.00001  1677
64checkflip 0.0001  16775
65checkflip 0.001  167604
66checkflip 0.01  1661055
67checkflip 0.1  15205967
68
69echo ""
70if [ "$FAILED" != 0 ]; then
71    echo "*** $FAILED tests failed out of $TESTED ***"
72    exit 1
73fi
74echo "*** all $TESTED tests OK ***"
75
76exit 0
77
Note: See TracBrowser for help on using the repository browser.