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

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