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

Last change on this file since 4247 was 4247, checked in by sam, 4 years ago

In the unit test phase, only launch sequences with functions we support.

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