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

Last change on this file since 1521 was 1521, checked in by Sam Hocevar, 14 years ago
  • Added cat reimplementations to the testsuite.
  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 2.2 KB
Line 
1#!/bin/sh
2
3create()
4{
5    rm -f /tmp/zzuf-zero-$$
6    dd if=/dev/zero of=/tmp/zzuf-zero-$$ bs=1024 count=32 2>/dev/null
7    rm -f /tmp/zzuf-random-$$
8    dd if=/dev/urandom of=/tmp/zzuf-random-$$ bs=1024 count=32 2>/dev/null
9    rm -f /tmp/zzuf-text-$$
10    strings /dev/urandom | dd bs=1024 count=32 of=/tmp/zzuf-text-$$ 2>/dev/null
11}
12
13check()
14{
15    SEED="$1"
16    RATIO="$2"
17    CMD="$3"
18    ALIAS="$4"
19    echo -n " $(echo "$ALIAS:              " | cut -b1-15)"
20    NEWMD5="$($ZZUF -s $SEED -r $RATIO $CMD 2>/dev/null | md5sum | cut -b1-32)"
21    if [ -z "$MD5" ]; then
22        MD5="$NEWMD5"
23        echo "$NEWMD5"
24    elif [ "$NEWMD5" != "$MD5" ]; then
25        OK=0
26        echo "$NEWMD5"
27    else
28        echo ' ...'
29    fi
30}
31
32cleanup() {
33    if [ "$FAILED" = 0 ]; then
34        rm -f /tmp/zzuf-zero-$$
35        rm -f /tmp/zzuf-random-$$
36        rm -f /tmp/zzuf-text-$$
37    fi
38}
39
40trap "echo ''; echo 'Aborted.'; cleanup; exit 0" 1 2 15
41
42seed=$(($RANDOM * $$))
43ZZUF="$(dirname "$0")/../src/zzuf"
44FDCAT="$(dirname "$0")/fdcat"
45STRAMCAT="$(dirname "$0")/streamcat"
46FAILED=0
47TESTED=0
48
49echo "Creating test files"
50create
51echo "Using seed $seed"
52echo ""
53
54for file in /tmp/zzuf-text-$$ /tmp/zzuf-zero-$$ /tmp/zzuf-random-$$; do
55    for r in 0.0 0.00001 0.0001 0.001 0.01 0.1 1.0 10.0; do
56        echo "Testing zzuf on $file, ratio $r:"
57        OK=1
58        MD5=""
59        check $seed $r "cat $file" "cat"
60# don't do grep, it adds a newline at EOF!
61#        check $seed $r "grep -- -a \\'\\' $file" "grep -a"
62        check $seed $r "sed n $file" "sed n"
63        check $seed $r "dd bs=65536 if=$file" "dd(bs=65536)"
64        check $seed $r "dd bs=1111 if=$file" "dd(bs=1111)"
65        check $seed $r "dd bs=1024 if=$file" "dd(bs=1024)"
66        check $seed $r "dd bs=1 if=$file" "dd(bs=1)"
67        check $seed $r "$FDCAT $file" "fdcat"
68        check $seed $r "$STRAMCAT $file" "streamcat"
69        if [ "$OK" != 1 ]; then
70            echo "*** FAILED ***"
71            FAILED=$(($FAILED + 1))
72        fi
73        TESTED=$(($TESTED + 1))
74        echo ""
75    done
76done
77cleanup
78
79if [ "$FAILED" != 0 ]; then
80    echo "$FAILED tests failed out of $TESTED. Files preserved:"
81    echo "  /tmp/zzuf-zero-$$"
82    echo "  /tmp/zzuf-random-$$"
83    echo "  /tmp/zzuf-text-$$"
84    exit 1
85fi
86echo "All $TESTED tests OK."
87exit 0
88
Note: See TracBrowser for help on using the repository browser.