Changeset 2325


Ignore:
Timestamp:
May 17, 2008, 12:01:11 AM (12 years ago)
Author:
Sam Hocevar
Message:
  • Add statistical analysis to the testsuite to check our random number generator.
Location:
zzuf/trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • zzuf/trunk/.gitignore

    r2320 r2325  
    2121src/zzuf
    2222test/zzcat
     23test/zzero
  • zzuf/trunk/test/Makefile.am

    r1725 r2325  
    22EXTRA_DIST = testsuite.sh file-00 file-ff file-random file-text
    33
    4 noinst_PROGRAMS = zzcat
     4noinst_PROGRAMS = zzcat zzero
     5
    56zzcat_SOURCES = zzcat.c
    67
     8zzero_SOURCES = zzero.c
     9
  • zzuf/trunk/test/testsuite.sh

    r1745 r2325  
    33set -e
    44
    5 check()
     5checkflip()
    66{
    7     ZZOPTS="$1"
    8     CMD="$2"
    9     ALIAS="$3"
    10     CHECK="$4"
    11     echo -n " $(echo "$ALIAS .............." | cut -b1-18) "
    12     MD5="$(eval "$ZZUF -m $ZZOPTS $CMD" 2>/dev/null | cut -f2 -d' ')"
    13     if [ -n "$CHECK" ]; then
    14         REFMD5="$CHECK"
     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"
    1534    fi
    16     if [ -z "$REFMD5" ]; then
    17         REFMD5="$MD5"
    18         echo "$MD5"
    19     else
    20         TESTED=$(($TESTED + 1))
    21         if [ "$MD5" != "$REFMD5" ]; then
    22             FAILED=$(($FAILED + 1))
    23             echo "$MD5 FAILED"
    24         else
    25             echo 'ok'
    26         fi
    27     fi
     35    TESTED=$(($TESTED + 1))
     36    echo " min/avg/max $rmin/$rmean/$rmax .......... $result"
    2837}
    2938
    30 seed=$((0+0$1))
    31 DIR="$(dirname "$0")"
    32 ZZUF="$DIR/../src/zzuf"
    33 ZZCAT="$DIR/zzcat"
    34 if [ ! -f "$ZZCAT" ]; then
    35   echo "error: test/zzcat is missing"
    36   exit 1
    37 fi
    38 if file /bin/cat | grep -q 'statically linked'; then
    39   STATIC_CAT=1
    40 fi
    41 if file /bin/dd | grep -q 'statically linked'; then
    42   STATIC_DD=1
    43 fi
    44 FAILED=0
    45 TESTED=0
    46 
    47 echo "*** running zzuf test suite ***"
    48 echo "*** using seed $seed ***"
    49 
    50 for r in 0.0 0.00001 0.001 0.1 10.0; do
     39checkutils()
     40{
     41    r=$1
    5142    for type in 00 ff text random; do
    5243        file="$DIR/file-$type"
     
    9788        esac
    9889    done
    99 done
     90}
    10091
     92check()
     93{
     94    ZZOPTS="$1"
     95    CMD="$2"
     96    ALIAS="$3"
     97    CHECK="$4"
     98    echo -n " $(echo "$ALIAS .............." | cut -b1-18) "
     99    MD5="$(eval "$ZZUF -m $ZZOPTS $CMD" 2>/dev/null | cut -f2 -d' ')"
     100    if [ -n "$CHECK" ]; then
     101        REFMD5="$CHECK"
     102    fi
     103    if [ -z "$REFMD5" ]; then
     104        REFMD5="$MD5"
     105        echo "$MD5"
     106    else
     107        TESTED=$(($TESTED + 1))
     108        if [ "$MD5" != "$REFMD5" ]; then
     109            FAILED=$(($FAILED + 1))
     110            echo "$MD5 FAILED"
     111        else
     112            echo 'ok'
     113        fi
     114    fi
     115}
     116
     117DIR="$(dirname "$0")"
     118ZZUF="$DIR/../src/zzuf"
     119ZZCAT="$DIR/zzcat"
     120if [ ! -f "$ZZCAT" ]; then
     121  echo "error: test/zzcat is missing"
     122  exit 1
     123fi
     124ZZERO="$DIR/zzero"
     125if [ ! -f "$ZZERO" ]; then
     126  echo "error: test/zzero is missing"
     127  exit 1
     128fi
     129if file /bin/cat | grep -q 'statically linked'; then
     130  STATIC_CAT=1
     131fi
     132if file /bin/dd | grep -q 'statically linked'; then
     133  STATIC_DD=1
     134fi
     135FAILED=0
     136TESTED=0
     137
     138if [ -z "$1" ]; then
     139  seed=$(date | $ZZUF -m 2>/dev/null | cut -f2 -d' ' | tr -d abcdef | cut -b1-8)
     140else
     141  seed="$1"
     142fi
     143
     144echo "*** running zzuf test suite with seed $seed ***"
     145
     146echo ""
     147echo "*** check #1: random number generator ***"
     148# if X flips are performed on N bits set to 0, the average number of bits
     149# set to 1 is: N / 2 * (1 - pow(1 - 2 / N, X)
     150checkflip 0.000000001 0
     151checkflip 0.00000001  1
     152checkflip 0.0000001  16
     153checkflip 0.000001  167
     154checkflip 0.00001  1677
     155checkflip 0.0001  16775
     156checkflip 0.001  167604
     157checkflip 0.01  1661055
     158checkflip 0.1  15205967
     159
     160echo ""
     161echo "*** check #2: libc functions coverage ***"
     162checkutils 0.0
     163checkutils 0.000000001
     164checkutils 0.0000001
     165checkutils 0.00001
     166checkutils 0.001
     167checkutils 0.1
     168checkutils 10.0
     169
     170echo ""
    101171if [ "$FAILED" != 0 ]; then
    102172    echo "*** $FAILED tests failed out of $TESTED ***"
Note: See TracChangeset for help on using the changeset viewer.