README: mention new -count option
[rofl0r-jobflow.git] / test.sh
blob93b53d94d69a40e5ab512ae0ed6493c32946ccc3
1 #!/bin/sh
2 test -z "$JF" && JF=./jobflow
3 TMP=/tmp/jobflow.test.$$
4 gcc tests/stdin_printer.c -o tests/stdin_printer.out || { error compiling tests/stdin_printer.c ; exit 1 ; }
5 tmp() {
6 echo $TMP.$testno
8 md5() {
9 md5sum "$1"|cut -d " " -f 1
11 fs() {
12 wc -c "$1"|cut -d " " -f 1
14 equal() {
15 test $(md5 "$1") = $(md5 "$2")
17 equal_size() {
18 test $(fs "$1") = $(fs "$2")
20 cleanup() {
21 rm -f $(tmp).1 $(tmp).2 $(tmp).3 $(tmp).4
23 test_equal() {
24 if equal "$1" "$2" ; then
25 cleanup
26 else
27 echo "test $testno failed."
28 echo "inspect $(tmp).* for analysis"
31 test_equal_size() {
32 if equal_size "$1" "$2" ; then
33 cleanup
34 else
35 echo "test $testno failed."
36 echo "inspect $(tmp).* for analysis"
39 dotest() {
40 [ -z "$testno" ] && testno=0
41 testno=$((testno + 1))
42 echo "running test $testno ($1)"
45 dotest "argpermutation std"
46 echo foo1337bar > $(tmp).1
47 echo 1337 | $JF -exec echo 'foo{}bar' > $(tmp).2
48 test_equal $(tmp).1 $(tmp).2
50 dotest "argpermutation std 2x"
51 echo foo1337bar1337 > $(tmp).1
52 echo 1337 | $JF -exec echo 'foo{}bar{}' > $(tmp).2
53 test_equal $(tmp).1 $(tmp).2
55 dotest "argpermutation dot"
56 echo foobar.png > $(tmp).1
57 echo foobar.bmp | $JF -exec echo '{.}.png' > $(tmp).2
58 test_equal $(tmp).1 $(tmp).2
60 dotest "argpermutation dot 2x"
61 echo 'mv foobar.pcx foobar.png' > $(tmp).1
62 echo foobar.bmp | $JF -exec echo 'mv {.}.pcx {.}.png' > $(tmp).2
63 test_equal $(tmp).1 $(tmp).2
65 dotest "seq 10 catmode skip 5"
66 seq 10 > $(tmp).1
67 $JF -skip=5 < $(tmp).1 > $(tmp).2
68 tail -n 5 < $(tmp).1 > $(tmp).3
69 test_equal $(tmp).2 $(tmp).3
71 dotest "seq 10 catmode skip 5 count 3"
72 seq 10 > $(tmp).1
73 $JF -skip=5 -count=3 < $(tmp).1 > $(tmp).2
74 tail -n 5 < $(tmp).1 | head -n 3 > $(tmp).3
75 test_equal $(tmp).2 $(tmp).3
77 dotest "seq 10000 bulk skip 1337"
78 seq 10000 | sort -u > $(tmp).1
79 $JF -bulk=4K -skip=1337 -exec tests/stdin_printer.out < $(tmp).1 | sort -u > $(tmp).2
80 tail -n $((10000 - 1337)) < $(tmp).1 > $(tmp).3
81 test_equal $(tmp).2 $(tmp).3
83 dotest "seq 100000 bulk skip 31337 3x"
84 seq 100000 | sort -u > $(tmp).1
85 $JF -bulk=4K -threads=3 -skip=31337 -exec tests/stdin_printer.out < $(tmp).1 | sort -u > $(tmp).2
86 tail -n $((100000 - 31337)) < $(tmp).1 > $(tmp).3
87 test_equal $(tmp).2 $(tmp).3
89 dotest "seq 100 catmode"
90 seq 100 > $(tmp).1
91 $JF < $(tmp).1 > $(tmp).2
92 test_equal $(tmp).1 $(tmp).2
94 dotest "seq 100 echo"
95 seq 100 > $(tmp).1
96 $JF -threads=1 -exec echo {} < $(tmp).1 > $(tmp).2
97 test_equal $(tmp).1 $(tmp).2
99 dotest "seq 10000 pipe cat"
100 seq 10000 | sort -u > $(tmp).1
101 $JF -threads=1 -exec cat < $(tmp).1 > $(tmp).2
102 test_equal $(tmp).1 $(tmp).2
104 dotest "seq 10000 pipe cat 3x"
105 # since cat reads input in chunks and not in lines, we can
106 # observe interesting effects: if one of the chunks processed
107 # by one of the cat instances happens not to end after a newline
108 # character, the contents of that line will be written up to
109 # the last character, and then another process will dump its
110 # stdout, so we'll have a line containing ouput from both
111 # processes. so it may happen that e.g. one process dumps first
112 # 2 bytes of string "100", i.e. "10" without newline, then another
113 # process will write "1\n", so the end result may have "101\n"
114 # twice, which would get filtered out by sort -u.
115 seq 10000 > $(tmp).1
116 $JF -threads=3 -exec cat < $(tmp).1 > $(tmp).2
117 test_equal_size $(tmp).1 $(tmp).2
119 dotest "seq 10000 pipe cat buffered 3x"
120 # same restrictions as above apply, but since we use -buffered
121 seq 10000 | sort -u > $(tmp).1
122 $JF -threads=3 -buffered -exec cat < $(tmp).1 | sort -u > $(tmp).2
123 test_equal $(tmp).1 $(tmp).2
125 dotest "seq 10000 pipe linecat 3x"
126 seq 10000 | sort -u > $(tmp).1
127 $JF -threads=3 -exec tests/stdin_printer.out < $(tmp).1 | sort -u > $(tmp).2
128 test_equal $(tmp).1 $(tmp).2
130 dotest "seq 10000 echo 3x"
131 seq 10000 | sort -u > $(tmp).1
132 $JF -threads=3 -exec echo {} < $(tmp).1 | sort -u > $(tmp).2
133 test_equal $(tmp).1 $(tmp).2
135 RNDLINES=7331
137 dotest "random skip echo"
138 od < /dev/urandom | head -n $RNDLINES > $(tmp).1
139 $JF -threads=1 -skip=$((RNDLINES - 10)) -exec echo {} < $(tmp).1 > $(tmp).2
140 tail -n 10 < $(tmp).1 > $(tmp).3
141 test_equal $(tmp).2 $(tmp).3
143 dotest "random echo"
144 od < /dev/urandom | head -n $RNDLINES > $(tmp).1
145 $JF -threads=1 -exec echo {} < $(tmp).1 > $(tmp).2
146 test_equal $(tmp).1 $(tmp).2
148 dotest "random echo 2x"
149 od < /dev/urandom | head -n $RNDLINES > $(tmp).1
150 $JF -threads=2 -exec echo {} < $(tmp).1 | sort -u > $(tmp).2
151 test_equal $(tmp).1 $(tmp).2
153 dotest "random echo 3x"
154 od < /dev/urandom | head -n $RNDLINES > $(tmp).1
155 $JF -threads=3 -exec echo {} < $(tmp).1 | sort -u > $(tmp).2
156 test_equal $(tmp).1 $(tmp).2
158 dotest "random echo 4x"
159 od < /dev/urandom | head -n $RNDLINES > $(tmp).1
160 $JF -threads=4 -exec echo {} < $(tmp).1 | sort -u > $(tmp).2
161 test_equal $(tmp).1 $(tmp).2
163 dotest "random echo 17x"
164 od < /dev/urandom | head -n $RNDLINES > $(tmp).1
165 $JF -threads=17 -exec echo {} < $(tmp).1 | sort -u > $(tmp).2
166 test_equal $(tmp).1 $(tmp).2
168 dotest "random echo buffered 17x"
169 od < /dev/urandom | head -n $RNDLINES > $(tmp).1
170 $JF -threads=17 -buffered -exec echo {} < $(tmp).1 | sort -u > $(tmp).2
171 test_equal $(tmp).1 $(tmp).2
173 dotest "random pipe"
174 od < /dev/urandom | head -n $RNDLINES > $(tmp).1
175 $JF -threads=1 -exec cat < $(tmp).1 > $(tmp).2
176 test_equal $(tmp).1 $(tmp).2
178 dotest "random pipe 3x"
179 od < /dev/urandom | head -n $RNDLINES > $(tmp).1
180 $JF -threads=3 -exec cat < $(tmp).1 | sort -u > $(tmp).2
181 test_equal $(tmp).1 $(tmp).2
183 dotest "random pipe 17x"
184 od < /dev/urandom | head -n $RNDLINES > $(tmp).1
185 $JF -threads=17 -exec cat < $(tmp).1 | sort -u > $(tmp).2
186 test_equal $(tmp).1 $(tmp).2
188 dotest "random pipe buffered 17x"
189 od < /dev/urandom | head -n $RNDLINES > $(tmp).1
190 $JF -threads=17 -buffered -exec tests/stdin_printer.out < $(tmp).1 | sort -u > $(tmp).2
191 test_equal $(tmp).1 $(tmp).2