add some argument permutation tests
[rofl0r-jobflow.git] / test.sh
blob6b7c97ca62f959c18b549f4f6837d6553060b569
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 10000 bulk skip 1337"
72 seq 10000 | sort -u > $(tmp).1
73 $JF -bulk=4K -skip=1337 -exec tests/stdin_printer.out < $(tmp).1 | sort -u > $(tmp).2
74 tail -n $((10000 - 1337)) < $(tmp).1 > $(tmp).3
75 test_equal $(tmp).2 $(tmp).3
77 dotest "seq 100000 bulk skip 31337 3x"
78 seq 100000 | sort -u > $(tmp).1
79 $JF -bulk=4K -threads=3 -skip=31337 -exec tests/stdin_printer.out < $(tmp).1 | sort -u > $(tmp).2
80 tail -n $((100000 - 31337)) < $(tmp).1 > $(tmp).3
81 test_equal $(tmp).2 $(tmp).3
83 dotest "seq 100 catmode"
84 seq 100 > $(tmp).1
85 $JF < $(tmp).1 > $(tmp).2
86 test_equal $(tmp).1 $(tmp).2
88 dotest "seq 100 echo"
89 seq 100 > $(tmp).1
90 $JF -threads=1 -exec echo {} < $(tmp).1 > $(tmp).2
91 test_equal $(tmp).1 $(tmp).2
93 dotest "seq 10000 pipe cat"
94 seq 10000 | sort -u > $(tmp).1
95 $JF -threads=1 -exec cat < $(tmp).1 > $(tmp).2
96 test_equal $(tmp).1 $(tmp).2
98 dotest "seq 10000 pipe cat 3x"
99 # since cat reads input in chunks and not in lines, we can
100 # observe interesting effects: if one of the chunks processed
101 # by one of the cat instances happens not to end after a newline
102 # character, the contents of that line will be written up to
103 # the last character, and then another process will dump its
104 # stdout, so we'll have a line containing ouput from both
105 # processes. so it may happen that e.g. one process dumps first
106 # 2 bytes of string "100", i.e. "10" without newline, then another
107 # process will write "1\n", so the end result may have "101\n"
108 # twice, which would get filtered out by sort -u.
109 seq 10000 > $(tmp).1
110 $JF -threads=3 -exec cat < $(tmp).1 > $(tmp).2
111 test_equal_size $(tmp).1 $(tmp).2
113 dotest "seq 10000 pipe cat buffered 3x"
114 # same restrictions as above apply, but since we use -buffered
115 seq 10000 | sort -u > $(tmp).1
116 $JF -threads=3 -buffered -exec cat < $(tmp).1 | sort -u > $(tmp).2
117 test_equal $(tmp).1 $(tmp).2
119 dotest "seq 10000 pipe linecat 3x"
120 seq 10000 | sort -u > $(tmp).1
121 $JF -threads=3 -exec tests/stdin_printer.out < $(tmp).1 | sort -u > $(tmp).2
122 test_equal $(tmp).1 $(tmp).2
124 dotest "seq 10000 echo 3x"
125 seq 10000 | sort -u > $(tmp).1
126 $JF -threads=3 -exec echo {} < $(tmp).1 | sort -u > $(tmp).2
127 test_equal $(tmp).1 $(tmp).2
129 RNDLINES=7331
131 dotest "random skip echo"
132 od < /dev/urandom | head -n $RNDLINES > $(tmp).1
133 $JF -threads=1 -skip=$((RNDLINES - 10)) -exec echo {} < $(tmp).1 > $(tmp).2
134 tail -n 10 < $(tmp).1 > $(tmp).3
135 test_equal $(tmp).2 $(tmp).3
137 dotest "random echo"
138 od < /dev/urandom | head -n $RNDLINES > $(tmp).1
139 $JF -threads=1 -exec echo {} < $(tmp).1 > $(tmp).2
140 test_equal $(tmp).1 $(tmp).2
142 dotest "random echo 2x"
143 od < /dev/urandom | head -n $RNDLINES > $(tmp).1
144 $JF -threads=2 -exec echo {} < $(tmp).1 | sort -u > $(tmp).2
145 test_equal $(tmp).1 $(tmp).2
147 dotest "random echo 3x"
148 od < /dev/urandom | head -n $RNDLINES > $(tmp).1
149 $JF -threads=3 -exec echo {} < $(tmp).1 | sort -u > $(tmp).2
150 test_equal $(tmp).1 $(tmp).2
152 dotest "random echo 4x"
153 od < /dev/urandom | head -n $RNDLINES > $(tmp).1
154 $JF -threads=4 -exec echo {} < $(tmp).1 | sort -u > $(tmp).2
155 test_equal $(tmp).1 $(tmp).2
157 dotest "random echo 17x"
158 od < /dev/urandom | head -n $RNDLINES > $(tmp).1
159 $JF -threads=17 -exec echo {} < $(tmp).1 | sort -u > $(tmp).2
160 test_equal $(tmp).1 $(tmp).2
162 dotest "random echo buffered 17x"
163 od < /dev/urandom | head -n $RNDLINES > $(tmp).1
164 $JF -threads=17 -buffered -exec echo {} < $(tmp).1 | sort -u > $(tmp).2
165 test_equal $(tmp).1 $(tmp).2
167 dotest "random pipe"
168 od < /dev/urandom | head -n $RNDLINES > $(tmp).1
169 $JF -threads=1 -exec cat < $(tmp).1 > $(tmp).2
170 test_equal $(tmp).1 $(tmp).2
172 dotest "random pipe 3x"
173 od < /dev/urandom | head -n $RNDLINES > $(tmp).1
174 $JF -threads=3 -exec cat < $(tmp).1 | sort -u > $(tmp).2
175 test_equal $(tmp).1 $(tmp).2
177 dotest "random pipe 17x"
178 od < /dev/urandom | head -n $RNDLINES > $(tmp).1
179 $JF -threads=17 -exec cat < $(tmp).1 | sort -u > $(tmp).2
180 test_equal $(tmp).1 $(tmp).2
182 dotest "random pipe buffered 17x"
183 od < /dev/urandom | head -n $RNDLINES > $(tmp).1
184 $JF -threads=17 -buffered -exec tests/stdin_printer.out < $(tmp).1 | sort -u > $(tmp).2
185 test_equal $(tmp).1 $(tmp).2