Changeset 2573 for zzuf


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.
Location:
zzuf/trunk/test
Files:
1 added
6 edited

Legend:

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

    r2548 r2573  
    11#!/bin/sh
    22
    3 set -e
     3. "$(dirname "$0")/functions.inc"
    44
    5 DIR="$(dirname "$0")"
    6 ZZUF="$DIR/../src/zzuf"
    75PROGRAM="$DIR/bug-div0"
    86if [ ! -f "$PROGRAM" ]; then
     
    108  exit 1
    119fi
    12 FAILED=0
    13 TESTED=0
    1410
    15 if [ -z "$1" ]; then
    16   seed=$(date | $ZZUF -m 2>/dev/null | cut -f2 -d' ' | tr -d abcdef | cut -b1-8)
     11start_test "zzuf division-by-zero test"
     12
     13new_test "bug-div0 < /file-00"
     14if ! $PROGRAM < "$DIR/file-00"; then
     15    fail_test " unexpected exit status $?"
    1716else
    18   seed="$1"
     17    pass_test " OK"
    1918fi
    2019
    21 echo "*** running zzuf division-by-zero test with seed $seed ***"
     20new_test "zzuf -qi -r0 bug-div0 < /file-00"
     21if ! "$ZZUF" -r0 -qi "$PROGRAM" < "$DIR/file-00"; then
     22    fail_test " unexpected exit status $?"
     23else
     24    pass_test " OK"
     25fi
    2226
    23 echo "*** bug-div0 < /file-00"
    24 if ! $PROGRAM < "$DIR/file-00"; then
    25     echo " unexpected exit status $?"
    26     FAILED="$(($FAILED + 1))"
     27new_test "zzuf -qi bug-div0 < file-00"
     28if "$ZZUF" -qi "$PROGRAM" < "$DIR/file-00"; then
     29    fail_test " unexpected exit status $?"
    2730else
    28     echo " OK"
     31    pass_test " OK"
    2932fi
    30 TESTED="$(($TESTED + 1))"
    3133
    32 echo "*** zzuf -qi -r0 bug-div0 < /file-00"
    33 if ! "$ZZUF" -r0 -qi "$PROGRAM" < "$DIR/file-00"; then
    34     echo " unexpected exit status $?"
    35     FAILED="$(($FAILED + 1))"
    36 else
    37     echo " OK"
    38 fi
    39 TESTED="$(($TESTED + 1))"
    40 
    41 echo "*** zzuf -qi bug-div0 < file-00"
    42 if "$ZZUF" -qi "$PROGRAM" < "$DIR/file-00"; then
    43     echo " unexpected exit status $?"
    44     FAILED="$(($FAILED + 1))"
    45 else
    46     echo " OK"
    47 fi
    48 TESTED="$(($TESTED + 1))"
    49 
    50 if [ "$FAILED" != 0 ]; then
    51     echo "*** $FAILED tests failed out of $TESTED ***"
    52     exit 1
    53 fi
    54 echo "*** all $TESTED tests OK ***"
     34stop_test
    5535
    5636exit 0
  • zzuf/trunk/test/check-md5

    r2549 r2573  
    11#!/bin/sh
    22
    3 set -e
     3. "$(dirname "$0")/functions.inc"
    44
    55checkmd5()
     
    99    printf " $(echo "$CMD .............................." | cut -b1-30) "
    1010    MD5="$(eval "$CMD | $ZZUF -m -r0" 2>/dev/null | cut -f2 -d' ')"
    11     TESTED=$(($TESTED + 1))
    1211    if [ "$MD5" != "$REFMD5" ]; then
    13         FAILED=$(($FAILED + 1))
    14         echo "$MD5 FAILED"
     12        fail_test "$MD5 FAILED"
    1513    else
    16         echo 'ok'
     14        pass_test 'ok'
    1715    fi
    1816}
    1917
    20 DIR="$(dirname "$0")"
    21 ZZUF="$DIR/../src/zzuf"
    22 FAILED=0
    23 TESTED=0
    24 
    25 echo "*** running zzuf MD5 test ***"
     18start_test "zzuf MD5 test"
    2619
    2720checkmd5 "printf ''" d41d8cd98f00b204e9800998ecf8427e
     
    2922checkmd5 "printf 'hello world'" 5eb63bbbe01eeed093cb22bb8f5acdc3
    3023
    31 if [ "$FAILED" != 0 ]; then
    32     echo "*** $FAILED tests failed out of $TESTED ***"
    33     exit 1
    34 fi
    35 echo "*** all $TESTED tests OK ***"
     24stop_test
    3625
    37 exit 0
    38 
  • zzuf/trunk/test/check-memory

    r2548 r2573  
    11#!/bin/sh
    22
    3 set -e
     3. "$(dirname "$0")/functions.inc"
    44
    5 DIR="$(dirname "$0")"
    6 ZZUF="$DIR/../src/zzuf"
    75PROGRAM="$DIR/bug-memory"
    86if [ ! -f "$PROGRAM" ]; then
     
    108  exit 1
    119fi
    12 FAILED=0
    13 TESTED=0
    1410
    15 if [ -z "$1" ]; then
    16   seed=$(date | $ZZUF -m 2>/dev/null | cut -f2 -d' ' | tr -d abcdef | cut -b1-8)
     11start_test "zzuf memory exhaustion test"
     12
     13new_test "bug-memory < /file-00"
     14if ! $PROGRAM < "$DIR/file-00"; then
     15    fail_test " unexpected exit status $?"
    1716else
    18   seed="$1"
     17    pass_test " OK"
    1918fi
    2019
    21 echo "*** running zzuf buffer memory test with seed $seed ***"
     20new_test "zzuf -qi -r0 bug-memory < /file-00"
     21if ! "$ZZUF" -r0 -qi "$PROGRAM" < "$DIR/file-00"; then
     22    fail_test " unexpected exit status $?"
     23else
     24    pass_test " OK"
     25fi
    2226
    23 echo "*** bug-memory < /file-00"
    24 if ! $PROGRAM < "$DIR/file-00"; then
    25     echo " unexpected exit status $?"
    26     FAILED="$(($FAILED + 1))"
     27new_test "zzuf -qi bug-memory < file-00"
     28if "$ZZUF" -M 256 -qi "$PROGRAM" < "$DIR/file-00"; then
     29    fail_test " unexpected exit status $?"
    2730else
    28     echo " OK"
     31    pass_test " OK"
    2932fi
    30 TESTED="$(($TESTED + 1))"
    3133
    32 echo "*** zzuf -qi -r0 bug-memory < /file-00"
    33 if ! "$ZZUF" -r0 -qi "$PROGRAM" < "$DIR/file-00"; then
    34     echo " unexpected exit status $?"
    35     FAILED="$(($FAILED + 1))"
    36 else
    37     echo " OK"
    38 fi
    39 TESTED="$(($TESTED + 1))"
     34stop_test
    4035
    41 echo "*** zzuf -qi bug-memory < file-00"
    42 if "$ZZUF" -M 256 -qi "$PROGRAM" < "$DIR/file-00"; then
    43     echo " unexpected exit status $?"
    44     FAILED="$(($FAILED + 1))"
    45 else
    46     echo " OK"
    47 fi
    48 TESTED="$(($TESTED + 1))"
    49 
    50 if [ "$FAILED" != 0 ]; then
    51     echo "*** $FAILED tests failed out of $TESTED ***"
    52     exit 1
    53 fi
    54 echo "*** all $TESTED tests OK ***"
    55 
    56 exit 0
    57 
  • zzuf/trunk/test/check-overflow

    r2548 r2573  
    11#!/bin/sh
    22
    3 set -e
     3. "$(dirname "$0")/functions.inc"
    44
    5 DIR="$(dirname "$0")"
    6 ZZUF="$DIR/../src/zzuf"
    75PROGRAM="$DIR/bug-overflow"
    86if [ ! -f "$PROGRAM" ]; then
     
    108  exit 1
    119fi
    12 FAILED=0
    13 TESTED=0
    1410
    15 if [ -z "$1" ]; then
    16   seed=$(date | $ZZUF -m 2>/dev/null | cut -f2 -d' ' | tr -d abcdef | cut -b1-8)
     11start_test "zzuf buffer overflow test"
     12
     13new_test "bug-overflow < /file-00"
     14if ! $PROGRAM < "$DIR/file-00"; then
     15    fail_test " unexpected exit status $?"
    1716else
    18   seed="$1"
     17    pass_test " OK"
    1918fi
    2019
    21 echo "*** running zzuf buffer overflow test with seed $seed ***"
     20new_test "zzuf -qi -r0 bug-overflow < /file-00"
     21if ! "$ZZUF" -r0 -qi "$PROGRAM" < "$DIR/file-00"; then
     22    fail_test " unexpected exit status $?"
     23else
     24    pass_test " OK"
     25fi
    2226
    23 echo "*** bug-overflow < /file-00"
    24 if ! $PROGRAM < "$DIR/file-00"; then
    25     echo " unexpected exit status $?"
    26     FAILED="$(($FAILED + 1))"
     27new_test "zzuf -qi bug-overflow < file-00"
     28if "$ZZUF" -qi "$PROGRAM" < "$DIR/file-00"; then
     29    fail_test " unexpected exit status $?"
    2730else
    28     echo " OK"
     31    pass_test " OK"
    2932fi
    30 TESTED="$(($TESTED + 1))"
    3133
    32 echo "*** zzuf -qi -r0 bug-overflow < /file-00"
    33 if ! "$ZZUF" -r0 -qi "$PROGRAM" < "$DIR/file-00"; then
    34     echo " unexpected exit status $?"
    35     FAILED="$(($FAILED + 1))"
    36 else
    37     echo " OK"
    38 fi
    39 TESTED="$(($TESTED + 1))"
     34stop_test
    4035
    41 echo "*** zzuf -qi bug-overflow < file-00"
    42 if "$ZZUF" -qi "$PROGRAM" < "$DIR/file-00"; then
    43     echo " unexpected exit status $?"
    44     FAILED="$(($FAILED + 1))"
    45 else
    46     echo " OK"
    47 fi
    48 TESTED="$(($TESTED + 1))"
    49 
    50 if [ "$FAILED" != 0 ]; then
    51     echo "*** $FAILED tests failed out of $TESTED ***"
    52     exit 1
    53 fi
    54 echo "*** all $TESTED tests OK ***"
    55 
    56 exit 0
    57 
  • 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 
  • zzuf/trunk/test/check-utils

    r2567 r2573  
    11#!/bin/sh
    22
    3 set -e
     3. "$(dirname "$0")/functions.inc"
    44
    55checkutils()
     
    7474        REFMD5="$MD5"
    7575        echo "$MD5"
     76    elif [ "$MD5" != "$REFMD5" ]; then
     77        fail_test "$MD5 FAILED"
    7678    else
    77         TESTED=$(($TESTED + 1))
    78         if [ "$MD5" != "$REFMD5" ]; then
    79             FAILED=$(($FAILED + 1))
    80             echo "$MD5 FAILED"
    81         else
    82             echo 'ok'
    83         fi
     79        pass_test 'ok'
    8480    fi
    8581}
    8682
    87 DIR="$(dirname "$0")"
    88 ZZUF="$DIR/../src/zzuf"
    89 ZZCAT="$DIR/zzcat"
    90 if [ ! -f "$ZZCAT" ]; then
    91   echo "error: test/zzcat is missing"
    92   exit 1
    93 fi
    94 if file /bin/cat | grep 'statically linked' >/dev/null 2>&1; then
    95   STATIC_CAT=1
    96 fi
    97 if file /bin/dd | grep 'statically linked' >/dev/null 2>&1; then
    98   STATIC_DD=1
    99 fi
    100 if tail -n 1 /dev/null >/dev/null 2>&1; then
    101   TAILN="tail -n "
    102   TAILP="tail -n +"
    103 else
    104   TAILN="tail -"
    105   TAILP="tail +"
    106 fi
    107 FAILED=0
    108 TESTED=0
    109 
    110 if [ -z "$1" ]; then
    111   seed=$(date | $ZZUF -m 2>/dev/null | cut -f2 -d' ' | tr -d abcdef | cut -b1-8)
    112 else
    113   seed="$1"
    114 fi
    115 
    116 echo "*** running zzuf utils test suite with seed $seed ***"
     83start_test "zzuf utils test suite"
    11784
    11885checkutils 0.0
     
    12087checkutils 1.0
    12188
    122 if [ "$FAILED" != 0 ]; then
    123     echo "*** $FAILED tests failed out of $TESTED ***"
    124     exit 1
    125 fi
    126 echo "*** all $TESTED tests OK ***"
     89stop_test
    12790
    128 exit 0
    129 
Note: See TracChangeset for help on using the changeset viewer.