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

Last change on this file since 1684 was 1684, checked in by Sam Hocevar, 14 years ago
  • Allow -r 0.0 again. Fixed the testsuite accordingly.
  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 4.1 KB
Line 
1#!/bin/sh
2
3set -e
4
5create()
6{
7    rm -f /tmp/zzuf-zero-$$
8    dd if=/dev/zero of=/tmp/zzuf-zero-$$ bs=1024 count=32 2>/dev/null
9    rm -f /tmp/zzuf-random-$$
10    dd if=/dev/urandom of=/tmp/zzuf-random-$$ bs=1024 count=32 2>/dev/null
11    rm -f /tmp/zzuf-text-$$
12    strings </dev/urandom | dd bs=1024 count=32 of=/tmp/zzuf-text-$$ 2>/dev/null
13    echo "" >> /tmp/zzuf-text-$$ # Make sure we have a newline at EOF
14}
15
16check()
17{
18    ZZOPTS="$1"
19    CMD="$2"
20    ALIAS="$3"
21    CHECK="$4"
22    echo -n " $(echo "$ALIAS .............." | cut -b1-18) "
23    MD5="$(eval "$ZZUF -m $ZZOPTS $CMD" 2>/dev/null | cut -f2 -d' ')"
24    if [ -n "$CHECK" ]; then
25        REFMD5="$CHECK"
26    fi
27    if [ -z "$REFMD5" ]; then
28        REFMD5="$MD5"
29        echo "$MD5"
30    else
31        TESTED=$(($TESTED + 1))
32        if [ "$MD5" != "$REFMD5" ]; then
33            FAILED=$(($FAILED + 1))
34            echo "$MD5 FAILED"
35        else
36            echo 'ok'
37        fi
38    fi
39}
40
41cleanup() {
42    if [ "$FAILED" = 0 ]; then
43        rm -f /tmp/zzuf-zero-$$
44        rm -f /tmp/zzuf-random-$$
45        rm -f /tmp/zzuf-text-$$
46        echo "*** temporary files removed ***"
47    else
48        echo "*** files preserved ***"
49        echo " /tmp/zzuf-zero-$$"
50        echo " /tmp/zzuf-random-$$"
51        echo " /tmp/zzuf-text-$$"
52    fi
53}
54
55trap "echo ''; echo '*** ABORTED ***'; cleanup; exit 0" 1 2 15
56
57seed=$((0+0$1))
58ZZUF="$(dirname "$0")/../src/zzuf"
59FDCAT="$(dirname "$0")/fdcat"
60STREAMCAT="$(dirname "$0")/streamcat"
61if [ ! -f "$FDCAT" -o ! -f "$STREAMCAT" ]; then
62  echo "error: test/fdcat or test/streamcat are missing"
63  exit 1
64fi
65if file /bin/cat | grep -q 'statically linked'; then
66  STATIC_CAT=1
67fi
68if file /bin/dd | grep -q 'statically linked'; then
69  STATIC_DD=1
70fi
71FAILED=0
72TESTED=0
73
74echo "*** running zzuf test suite ***"
75echo "*** creating test files ***"
76create
77echo "*** using seed $seed ***"
78
79for r in 0.0 0.00001 0.001 0.1 10.0; do
80    for type in zero text random; do
81        file=/tmp/zzuf-$type-$$
82        ZZOPTS="-s $seed -r $r"
83        case $file in
84          *text*) ZZOPTS="$ZZOPTS -P '\n'" ;;
85        esac
86        echo "*** file $file, ratio $r ***"
87        REFMD5=""
88        if [ $r = 0.0 -a $type = zero ]; then
89            check="bb7df04e1b0a2570657527a7e108ae23"
90            echo "*** should be $check ***"
91            check "$ZZOPTS" "< $file" "zzuf" "$check"
92        else
93            check "$ZZOPTS" "< $file" "zzuf"
94        fi
95        check "$ZZOPTS" "$FDCAT $file" "fdcat"
96        check "$ZZOPTS" "$STREAMCAT $file" "streamcat"
97        if [ "$STATIC_CAT" = "" ]; then
98            check "$ZZOPTS" "cat $file" "cat"
99            check "$ZZOPTS" "-i cat < $file" "|cat"
100        fi
101        if [ "$STATIC_DD" = "" ]; then
102            check "$ZZOPTS" "dd bs=65536 if=$file" "dd(bs=65536)"
103            check "$ZZOPTS" "dd bs=1111 if=$file" "dd(bs=1111)"
104            check "$ZZOPTS" "dd bs=1024 if=$file" "dd(bs=1024)"
105            check "$ZZOPTS" "dd bs=1 if=$file" "dd(bs=1)"
106        fi
107        case $file in
108          *text*)
109            # We don't include grep or sed when the input is not text, because
110            # they put a newline at the end of their input if it was not there
111            # initially. (Linux sed doesn't, but OS X sed does.)
112            check "$ZZOPTS" "head -- -n 9999 $file" "head -n 9999"
113            check "$ZZOPTS" "tail -- -n 9999 $file" "tail -n 9999"
114            check "$ZZOPTS" "tail -- -n +1 $file" "tail -n +1"
115            check "$ZZOPTS" "grep -- -a '' $file" "grep -a ''"
116            check "$ZZOPTS" "sed -- -e n $file" "sed -e n"
117            #check "$ZZOPTS" "cut -- -b1- $file" "cut -b1-"
118            check "$ZZOPTS" "-i head -- -n 9999 < $file" "|head -n 9999"
119            check "$ZZOPTS" "-i tail -- -n 9999 < $file" "|tail -n 9999"
120            check "$ZZOPTS" "-i tail -- -n +1 < $file" "|tail -n +1"
121            check "$ZZOPTS" "-i grep -- -a '' < $file" "|grep -a ''"
122            check "$ZZOPTS" "-i sed -- -e n < $file" "|sed -e n"
123            #check "$ZZOPTS" "-i cut -- -b1- < $file" "|cut -b1-"
124            ;;
125        esac
126    done
127done
128
129if [ "$FAILED" != 0 ]; then
130    echo "*** $FAILED tests failed out of $TESTED ***"
131    cleanup
132    exit 1
133fi
134echo "*** all $TESTED tests OK ***"
135
136cleanup
137exit 0
138
Note: See TracBrowser for help on using the repository browser.