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

Last change on this file since 1745 was 1745, checked in by Sam Hocevar, 13 years ago
  • Added mmap() to the testsuite.
  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 3.2 KB
Line 
1#!/bin/sh
2
3set -e
4
5check()
6{
7    ZZOPTS="$1"
8    CMD="$2"
9    ALIAS="$3"
10    CHECK="$4"
11    echo -n " $(echo "$ALIAS .............." | cut -b1-18) "
12    MD5="$(eval "$ZZUF -m $ZZOPTS $CMD" 2>/dev/null | cut -f2 -d' ')"
13    if [ -n "$CHECK" ]; then
14        REFMD5="$CHECK"
15    fi
16    if [ -z "$REFMD5" ]; then
17        REFMD5="$MD5"
18        echo "$MD5"
19    else
20        TESTED=$(($TESTED + 1))
21        if [ "$MD5" != "$REFMD5" ]; then
22            FAILED=$(($FAILED + 1))
23            echo "$MD5 FAILED"
24        else
25            echo 'ok'
26        fi
27    fi
28}
29
30seed=$((0+0$1))
31DIR="$(dirname "$0")"
32ZZUF="$DIR/../src/zzuf"
33ZZCAT="$DIR/zzcat"
34if [ ! -f "$ZZCAT" ]; then
35  echo "error: test/zzcat is missing"
36  exit 1
37fi
38if file /bin/cat | grep -q 'statically linked'; then
39  STATIC_CAT=1
40fi
41if file /bin/dd | grep -q 'statically linked'; then
42  STATIC_DD=1
43fi
44FAILED=0
45TESTED=0
46
47echo "*** running zzuf test suite ***"
48echo "*** using seed $seed ***"
49
50for r in 0.0 0.00001 0.001 0.1 10.0; do
51    for type in 00 ff text random; do
52        file="$DIR/file-$type"
53        ZZOPTS="-s $seed -r $r"
54        case $file in
55          *text*) ZZOPTS="$ZZOPTS -P '\n'" ;;
56        esac
57        echo "*** file $file, ratio $r ***"
58        REFMD5=""
59        if [ $r = 0.0 -a $type = 00 ]; then
60            check="bb7df04e1b0a2570657527a7e108ae23"
61            echo "*** should be $check ***"
62            check "$ZZOPTS" "< $file" "zzuf" "$check"
63        else
64            check "$ZZOPTS" "< $file" "zzuf"
65        fi
66        for n in 1 2 3; do
67            check "$ZZOPTS" "$ZZCAT $n $file" "zzcat $n"
68        done
69        if [ "$STATIC_CAT" = "" ]; then
70            check "$ZZOPTS" "cat $file" "cat"
71            check "$ZZOPTS" "-i cat < $file" "|cat"
72        fi
73        if [ "$STATIC_DD" = "" ]; then
74            check "$ZZOPTS" "dd bs=65536 if=$file" "dd(bs=65536)"
75            check "$ZZOPTS" "dd bs=1111 if=$file" "dd(bs=1111)"
76            check "$ZZOPTS" "dd bs=1024 if=$file" "dd(bs=1024)"
77            check "$ZZOPTS" "dd bs=1 if=$file" "dd(bs=1)"
78        fi
79        case $file in
80          *text*)
81            # We don't include grep or sed when the input is not text, because
82            # they put a newline at the end of their input if it was not there
83            # initially. (Linux sed doesn't, but OS X sed does.)
84            check "$ZZOPTS" "head -- -n 9999 $file" "head -n 9999"
85            check "$ZZOPTS" "tail -- -n 9999 $file" "tail -n 9999"
86            check "$ZZOPTS" "tail -- -n +1 $file" "tail -n +1"
87            check "$ZZOPTS" "grep -- -a '' $file" "grep -a ''"
88            check "$ZZOPTS" "sed -- -e n $file" "sed -e n"
89            #check "$ZZOPTS" "cut -- -b1- $file" "cut -b1-"
90            check "$ZZOPTS" "-i head -- -n 9999 < $file" "|head -n 9999"
91            check "$ZZOPTS" "-i tail -- -n 9999 < $file" "|tail -n 9999"
92            check "$ZZOPTS" "-i tail -- -n +1 < $file" "|tail -n +1"
93            check "$ZZOPTS" "-i grep -- -a '' < $file" "|grep -a ''"
94            check "$ZZOPTS" "-i sed -- -e n < $file" "|sed -e n"
95            #check "$ZZOPTS" "-i cut -- -b1- < $file" "|cut -b1-"
96            ;;
97        esac
98    done
99done
100
101if [ "$FAILED" != 0 ]; then
102    echo "*** $FAILED tests failed out of $TESTED ***"
103    exit 1
104fi
105echo "*** all $TESTED tests OK ***"
106
107exit 0
108
Note: See TracBrowser for help on using the repository browser.