source: zzuf/trunk/test/testsuite.sh @ 2531

Last change on this file since 2531 was 2531, checked in by Sam Hocevar, 12 years ago
  • testsuite.h: do not test for grep -a if the option is unknown.
  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 5.1 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
39checkutils()
40{
41    r=$1
42    for type in 00 ff text random; do
43        file="$DIR/file-$type"
44        ZZOPTS="-s $seed -r $r"
45        case $file in
46          *text*) ZZOPTS="$ZZOPTS -P '\\n' -R '\\000'" ;;
47        esac
48        echo "*** file $file, ratio $r ***"
49        REFMD5=""
50        if [ $r = 0.0 -a $type = 00 ]; then
51            check="bb7df04e1b0a2570657527a7e108ae23"
52            echo "*** should be $check ***"
53            check "$ZZOPTS" "< $file" "zzuf" "$check"
54        else
55            check "$ZZOPTS" "< $file" "zzuf"
56        fi
57        for n in 1 2 3; do
58            check "$ZZOPTS" "$ZZCAT $n $file" "zzcat $n"
59        done
60        if [ "$STATIC_CAT" = "" ]; then
61            check "$ZZOPTS" "cat $file" "cat"
62            check "$ZZOPTS" "-i cat < $file" "|cat"
63        fi
64        if [ "$STATIC_DD" = "" ]; then
65            check "$ZZOPTS" "dd bs=65536 if=$file" "dd(bs=65536)"
66            check "$ZZOPTS" "dd bs=1111 if=$file" "dd(bs=1111)"
67            check "$ZZOPTS" "dd bs=1024 if=$file" "dd(bs=1024)"
68            check "$ZZOPTS" "dd bs=1 if=$file" "dd(bs=1)"
69        fi
70        case $file in
71          *text*)
72            # We don't include grep or sed when the input is not text, because
73            # they put a newline at the end of their input if it was not there
74            # initially. (Linux sed doesn't, but OS X sed does.)
75            check "$ZZOPTS" "head -n 9999 $file" "head -n 9999"
76            check "$ZZOPTS" "tail -n 9999 $file" "tail -n 9999"
77            check "$ZZOPTS" "tail -n +1 $file" "tail -n +1"
78            if grep -a '' /dev/null >/dev/null 2>&1; then
79                check "$ZZOPTS" "grep -a '' $file" "grep -a ''"
80            fi
81            check "$ZZOPTS" "sed -e n $file" "sed -e n"
82            #check "$ZZOPTS" "cut -b1- $file" "cut -b1-"
83            check "$ZZOPTS" "-i head -n 9999 < $file" "|head -n 9999"
84            check "$ZZOPTS" "-i tail -n 9999 < $file" "|tail -n 9999"
85            check "$ZZOPTS" "-i tail -n +1 < $file" "|tail -n +1"
86            if grep -a '' /dev/null >/dev/null 2>&1; then
87                check "$ZZOPTS" "-i grep -a '' < $file" "|grep -a ''"
88            fi
89            check "$ZZOPTS" "-i sed -e n < $file" "|sed -e n"
90            #check "$ZZOPTS" "-i cut -b1- < $file" "|cut -b1-"
91            ;;
92        esac
93    done
94}
95
96check()
97{
98    ZZOPTS="$1"
99    CMD="$2"
100    ALIAS="$3"
101    CHECK="$4"
102    printf " $(echo "$ALIAS .............." | cut -b1-18) "
103    MD5="$(eval "$ZZUF -m $ZZOPTS $CMD" 2>/dev/null | cut -f2 -d' ')"
104    if [ -n "$CHECK" ]; then
105        REFMD5="$CHECK"
106    fi
107    if [ -z "$REFMD5" ]; then
108        REFMD5="$MD5"
109        echo "$MD5"
110    else
111        TESTED=$(($TESTED + 1))
112        if [ "$MD5" != "$REFMD5" ]; then
113            FAILED=$(($FAILED + 1))
114            echo "$MD5 FAILED"
115        else
116            echo 'ok'
117        fi
118    fi
119}
120
121DIR="$(dirname "$0")"
122ZZUF="$DIR/../src/zzuf"
123ZZCAT="$DIR/zzcat"
124if [ ! -f "$ZZCAT" ]; then
125  echo "error: test/zzcat is missing"
126  exit 1
127fi
128ZZERO="$DIR/zzero"
129if [ ! -f "$ZZERO" ]; then
130  echo "error: test/zzero is missing"
131  exit 1
132fi
133if file /bin/cat | grep -q 'statically linked'; then
134  STATIC_CAT=1
135fi
136if file /bin/dd | grep -q 'statically linked'; then
137  STATIC_DD=1
138fi
139FAILED=0
140TESTED=0
141
142if [ -z "$1" ]; then
143  seed=$(date | $ZZUF -m 2>/dev/null | cut -f2 -d' ' | tr -d abcdef | cut -b1-8)
144else
145  seed="$1"
146fi
147
148echo "*** running zzuf test suite with seed $seed ***"
149
150echo ""
151echo "*** check #1: random number generator ***"
152# if X flips are performed on N bits set to 0, the average number of bits
153# set to 1 is: N / 2 * (1 - pow(1 - 2 / N, X)
154checkflip 0.000000001 0
155checkflip 0.00000001  1
156checkflip 0.0000001  16
157checkflip 0.000001  167
158checkflip 0.00001  1677
159checkflip 0.0001  16775
160checkflip 0.001  167604
161checkflip 0.01  1661055
162checkflip 0.1  15205967
163
164echo ""
165echo "*** check #2: libc functions coverage ***"
166checkutils 0.0
167checkutils 0.000000001
168checkutils 0.0000001
169checkutils 0.00001
170checkutils 0.001
171checkutils 0.1
172checkutils 10.0
173
174echo ""
175if [ "$FAILED" != 0 ]; then
176    echo "*** $FAILED tests failed out of $TESTED ***"
177    exit 1
178fi
179echo "*** all $TESTED tests OK ***"
180
181exit 0
182
Note: See TracBrowser for help on using the repository browser.