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

Last change on this file since 1509 was 1509, checked in by Sam Hocevar, 14 years ago
  • Fix a cleanup bug in the testsuite.
  • If any of the tests failed, do not erase the test files.
  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 2.1 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"
44FAILED=0
45TESTED=0
46
47echo "Creating test files"
48create
49echo "Using seed $seed"
50echo ""
51
52for file in /tmp/zzuf-text-$$ /tmp/zzuf-zero-$$ /tmp/zzuf-random-$$; do
53    for r in 0.0 0.00001 0.0001 0.001 0.01 0.1 1.0 10.0; do
54        echo "Testing zzuf on $file, ratio $r:"
55        OK=1
56        MD5=""
57        check $seed $r "cat $file" "cat"
58# don't do grep, it adds a newline at EOF!
59#        check $seed $r "grep -- -a \\'\\' $file" "grep -a"
60        check $seed $r "sed n $file" "sed n"
61        check $seed $r "dd bs=65536 if=$file" "dd(bs=65536)"
62        check $seed $r "dd bs=1111 if=$file" "dd(bs=1111)"
63        check $seed $r "dd bs=1024 if=$file" "dd(bs=1024)"
64        check $seed $r "dd bs=1 if=$file" "dd(bs=1)"
65        if [ "$OK" != 1 ]; then
66            echo "*** FAILED ***"
67            FAILED=$(($FAILED + 1))
68        fi
69        TESTED=$(($TESTED + 1))
70        echo ""
71    done
72done
73cleanup
74
75if [ "$FAILED" != 0 ]; then
76    echo "$FAILED tests failed out of $TESTED. Files preserved:"
77    echo "  /tmp/zzuf-zero-$$"
78    echo "  /tmp/zzuf-random-$$"
79    echo "  /tmp/zzuf-text-$$"
80    exit 1
81fi
82echo "All $TESTED tests OK."
83exit 0
84
Note: See TracBrowser for help on using the repository browser.