source: zzuf/trunk/test/check-utils @ 4246

Last change on this file since 4246 was 4246, checked in by sam, 5 years ago

Improve zzcat documentation and add commandline flags, including --help
and --version.

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 5.2 KB
Line 
1#!/bin/sh
2
3. "$(dirname "$0")/functions.inc"
4
5checkutils()
6{
7    r=$1
8    for type in 00 ff text random; do
9        file="$DIR/file-$type"
10        ZZOPTS="-s $seed -r $r"
11        case $file in
12          *text*) ZZOPTS="$ZZOPTS -P '\\n' -R '\\000'" ;;
13        esac
14        echo "*** file $file, ratio $r ***"
15        REFMD5=""
16        if [ $r = 0.0 -a $type = 00 ]; then
17            check="bb7df04e1b0a2570657527a7e108ae23"
18            echo "*** should be $check ***"
19            check "$ZZOPTS" "< $file" "zzuf" "$check"
20        else
21            check "$ZZOPTS" "< $file" "zzuf"
22        fi
23        if [ "$STATIC_CAT" = "" ]; then
24            check "$ZZOPTS" "cat $file" "cat"
25            check "$ZZOPTS" "-i cat < $file" "|cat"
26        fi
27        if [ "$STATIC_DD" = "" ]; then
28            check "$ZZOPTS" "dd bs=65536 if=$file" "dd(bs=65536)"
29            check "$ZZOPTS" "dd bs=1111 if=$file" "dd(bs=1111)"
30            check "$ZZOPTS" "dd bs=1024 if=$file" "dd(bs=1024)"
31            check "$ZZOPTS" "dd bs=1 if=$file" "dd(bs=1)"
32        fi
33        case $file in
34          *text*)
35            # We don't include grep or sed when the input is not text, because
36            # they put a newline at the end of their input if it was not there
37            # initially. (Linux sed doesn't, but OS X sed does.)
38            check "$ZZOPTS" "head -n 9999 $file" "head -n 9999"
39            check "$ZZOPTS" "${TAILN}9999 $file" "${TAILN}9999"
40            check "$ZZOPTS" "${TAILP}1 $file" "${TAILP}1"
41            if grep -a '' /dev/null >/dev/null 2>&1; then
42                check "$ZZOPTS" "grep -a '' $file" "grep -a ''"
43            fi
44            check "$ZZOPTS" "sed -e n $file" "sed -e n"
45            #check "$ZZOPTS" "cut -b1- $file" "cut -b1-"
46            check "$ZZOPTS" "-i head -n 9999 < $file" "|head -n 9999"
47            check "$ZZOPTS" "-i ${TAILN}9999 < $file" "|${TAILN}9999"
48            check "$ZZOPTS" "-i ${TAILP}1 < $file" "|${TAILP}1"
49            if grep -a '' /dev/null >/dev/null 2>&1; then
50                check "$ZZOPTS" "-i grep -a '' < $file" "|grep -a ''"
51            fi
52            check "$ZZOPTS" "-i sed -e n < $file" "|sed -e n"
53            #check "$ZZOPTS" "-i cut -b1- < $file" "|cut -b1-"
54            ;;
55        esac
56        # Regression tests for stuff that used to break
57        check "$ZZOPTS" "$ZZCAT -x \"fread(1,33000) fseek(1,SEEK_SET) fread(1,1) fseek(4093,SEEK_CUR) fread(1,1) fseek(1,SEEK_CUR) fread(1,1)\" $file" \
58              "eglibc (2.9-21) bug regression"
59        check "$ZZOPTS" "$ZZCAT -x \"repeat(33000,getc_unlocked() ungetc() getline() feof(10))\" $file" \
60              "sed getc_unlocked() bug regression"
61        # Misc tests
62        for n in \
63          "fread(1,33000)" \
64          "repeat(33,fread(1,1000))" \
65          "repeat(1000,fread(1,33))" \
66          "getc() fread(1,33000)" \
67          "getc_unlocked() fread(1,33000)" \
68          "fgetc() fread(1,33000)" \
69          "fgetc_unlocked() fread(1,33000)" \
70          "getc() ungetc() fread(1,33000)" \
71          "getc_unlocked() ungetc() fread(1,33000)" \
72          "fgetc() ungetc() fread(1,33000)" \
73          "fgetc_unlocked() ungetc() fread(1,33000)" \
74          "repeat(33000,getc(),feof(10))" \
75          "repeat(33000,getc_unlocked(),feof(10))" \
76          "repeat(33000,fgetc(),feof(10))" \
77          "repeat(33000,fgetc_unlocked(),feof(10))" \
78          "repeat(8000,getc()) fread(1,33000)" \
79          "repeat(8000,getc_unlocked()) fread(1,33000)" \
80          "repeat(8000,fgetc()) fread(1,33000)" \
81          "repeat(8000,fgetc_unlocked()) fread(1,33000)" \
82          "repeat(10,getline()) fread(1,33000)" \
83          "repeat(10,getdelim(0)) fread(1,33000)" \
84          "repeat(10,getdelim(' ')) fread(1,33000)" \
85          "fread(1,100) fseek(50,SEEK_SET) fread(1,33000)" \
86          "fread(1,100) rewind() fseek(50,SEEK_CUR) fread(1,33000)" \
87          "fread(1,33000) rewind() repeat(10000,fseek(1,SEEK_CUR) fread(1,1))" \
88          "fread(1,33000) rewind() repeat(10000,fseek(2,SEEK_CUR) fread(1,2))" \
89          "fread(1,33000) rewind() repeat(10000,fseek(3,SEEK_CUR) fread(1,3))" \
90          "fread(1,33000) rewind() repeat(10000,fseek(4,SEEK_CUR) fread(1,4))" \
91          "repeat(33000,getc() ungetc() getline() feof(10))" \
92          "repeat(33000,fgetc() ungetc() getline() feof(10))" \
93          "fread(1,33000) fseek(1000,SEEK_CUR) repeat(10000,fread(1,2),feof(10))" \
94          "fread(1,33000) fseek(1000,SEEK_CUR) repeat(10000,getc(),feof(10))" \
95          "fread(1,33000) fseek(1000,SEEK_CUR) repeat(10000,fgetc(),feof(10))" \
96          "fread(1,33000) fseek(1000,SEEK_CUR) repeat(10000,getc_unlocked(),feof(10))" \
97          ; do
98            check "$ZZOPTS" "$ZZCAT -x \"$n\" $file" "$n"
99        done
100    done
101}
102
103check()
104{
105    ZZOPTS="$1"
106    CMD="$2"
107    ALIAS="$3"
108    CHECK="$4"
109    printf " $(echo "$ALIAS .................................." | cut -b1-38) "
110    MD5="$(eval "$ZZUF -m $ZZOPTS $CMD" 2>/dev/null | cut -f2 -d' ')"
111    if [ -n "$CHECK" ]; then
112        REFMD5="$CHECK"
113    fi
114    if [ -z "$REFMD5" ]; then
115        REFMD5="$MD5"
116        echo "$MD5"
117    elif [ "$MD5" != "$REFMD5" ]; then
118        fail_test "$MD5 FAILED"
119    else
120        pass_test 'ok'
121    fi
122}
123
124start_test "zzuf utils test suite"
125
126checkutils 0.0
127checkutils 0.001
128checkutils 1.0
129
130stop_test
131
Note: See TracBrowser for help on using the repository browser.