Ignore:
Timestamp:
Jul 20, 2008, 11:57:58 AM (12 years ago)
Author:
Sam Hocevar
Message:
  • Factored the test suite to avoid excessive code duplication.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • zzuf/trunk/test/check-rng

    r2564 r2573  
    11#!/bin/sh
    22
    3 set -e
     3. "$(dirname "$0")/functions.inc"
    44
    55checkflip()
     
    99    s2=$seed
    1010    mib=20
    11     echo "*** $mib MiB of zeroes, ratio $r ***"
    1211    rmax=-1
    1312    rmin=-1
    1413    rtot=0
     14    new_test "$mib MiB of zeroes, ratio $r"
    1515    for x in 0 1 2 3 4; do
    1616        ret=`dd if=/dev/zero bs=1048576 count=$mib 2>/dev/null | "$ZZUF" -s $s2 -r $r | "$ZZERO"`
     
    2323    rmean=`expr '(' $rtot + 2 ')' / 5 || true`
    2424    delta=`expr $rmean - $expect || true`
     25    printf " expected $expect min/avg/max $rmin/$rmean/$rmax .........."
    2526    if [ "$delta" -gt -5 -a "$delta" -lt 5 ]; then
    26         result="ok"
     27        pass_test " ok"
    2728    elif [ $(($rmean * 8)) -lt $(($expect * 7)) \
    2829               -o $(($rmean * 7)) -gt $(($expect * 8)) ]; then
    29         result="FAILED"
    30         FAILED=$(($FAILED + 1))
     30        fail_test " FAILED"
    3131    else
    32         result="ok"
     32        pass_test " ok"
    3333    fi
    34     TESTED=$(($TESTED + 1))
    35     echo " expected $expect min/avg/max $rmin/$rmean/$rmax .......... $result"
    3634}
    3735
    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 ***"
     36start_test "zzuf RNG test suite"
    5537
    5638# if X flips are performed on N bits set to 0, the average number of bits
     
    6648checkflip 0.1  15205967
    6749
    68 if [ "$FAILED" != 0 ]; then
    69     echo "*** $FAILED tests failed out of $TESTED ***"
    70     exit 1
    71 fi
    72 echo "*** all $TESTED tests OK ***"
     50stop_test
    7351
    74 exit 0
    75 
Note: See TracChangeset for help on using the changeset viewer.