README.md: remove memleak line
[rofl0r-jobflow.git] / test.sh
bloba83eb2e1f368149a1bb6d0622759304c52299d9e
1 #!/bin/sh
2 test -z "$JF" && JF=./jobflow.out
3 TMP=/tmp/jobflow.test.$$
4 tmp() {
5 echo $TMP.$testno
7 md5() {
8 md5sum "$1"|cut -d " " -f 1
10 fs() {
11 wc -c "$1"|cut -d " " -f 1
13 equal() {
14 test $(md5 "$1") = $(md5 "$2")
16 equal_size() {
17 test $(fs "$1") = $(fs "$2")
19 cleanup() {
20 rm -f $(tmp).1 $(tmp).2 $(tmp).3 $(tmp).4
22 test_equal() {
23 if equal "$1" "$2" ; then
24 cleanup
25 else
26 echo "test $testno failed."
27 echo "inspect $(tmp).* for analysis"
30 test_equal_size() {
31 if equal_size "$1" "$2" ; then
32 cleanup
33 else
34 echo "test $testno failed."
35 echo "inspect $(tmp).* for analysis"
38 dotest() {
39 [ -z "$testno" ] && testno=0
40 testno=$((testno + 1))
41 echo "running test $testno ($1)"
44 dotest "seq 10 catmode skip 5"
45 seq 10 > $(tmp).1
46 $JF -skip=5 < $(tmp).1 > $(tmp).2
47 tail -n 5 < $(tmp).1 > $(tmp).3
48 test_equal $(tmp).2 $(tmp).3
50 dotest "seq 10000 bulk skip 1337"
51 seq 10000 | sort -u > $(tmp).1
52 $JF -bulk -skip=1337 -exec tests/stdin_printer.out < $(tmp).1 | sort -u > $(tmp).2
53 tail -n $((10000 - 1337)) < $(tmp).1 > $(tmp).3
54 test_equal $(tmp).2 $(tmp).3
56 dotest "seq 100000 bulk skip 31337 3x"
57 seq 100000 | sort -u > $(tmp).1
58 $JF -bulk -threads=3 -skip=31337 -exec tests/stdin_printer.out < $(tmp).1 | sort -u > $(tmp).2
59 tail -n $((100000 - 31337)) < $(tmp).1 > $(tmp).3
60 test_equal $(tmp).2 $(tmp).3
62 dotest "seq 100 catmode"
63 seq 100 > $(tmp).1
64 $JF < $(tmp).1 > $(tmp).2
65 test_equal $(tmp).1 $(tmp).2
67 dotest "seq 100 echo"
68 seq 100 > $(tmp).1
69 $JF -threads=1 -exec echo {} < $(tmp).1 > $(tmp).2
70 test_equal $(tmp).1 $(tmp).2
72 dotest "seq 10000 pipe cat"
73 seq 10000 | sort -u > $(tmp).1
74 $JF -threads=1 -exec cat < $(tmp).1 > $(tmp).2
75 test_equal $(tmp).1 $(tmp).2
77 dotest "seq 10000 pipe cat 3x"
78 # since cat reads input in chunks and not in lines, we can
79 # observe interesting effects: if one of the chunks processed
80 # by one of the cat instances happens not to end after a newline
81 # character, the contents of that line will be written up to
82 # the last character, and then another process will dump its
83 # stdout, so we'll have a line containing ouput from both
84 # processes. so it may happen that e.g. one process dumps first
85 # 2 bytes of string "100", i.e. "10" without newline, then another
86 # process will write "1\n", so the end result may have "101\n"
87 # twice, which would get filtered out by sort -u.
88 seq 10000 > $(tmp).1
89 $JF -threads=3 -pipe -exec cat < $(tmp).1 > $(tmp).2
90 test_equal_size $(tmp).1 $(tmp).2
92 dotest "seq 10000 pipe cat buffered 3x"
93 # same restrictions as above apply, but since we use -buffered
94 seq 10000 | sort -u > $(tmp).1
95 $JF -threads=3 -pipe -buffered -exec cat < $(tmp).1 | sort -u > $(tmp).2
96 test_equal $(tmp).1 $(tmp).2
98 dotest "seq 10000 pipe linecat 3x"
99 seq 10000 | sort -u > $(tmp).1
100 $JF -threads=3 -pipe -exec tests/stdin_printer.out < $(tmp).1 | sort -u > $(tmp).2
101 test_equal $(tmp).1 $(tmp).2
103 dotest "seq 10000 echo 3x"
104 seq 10000 | sort -u > $(tmp).1
105 $JF -threads=3 -exec echo {} < $(tmp).1 | sort -u > $(tmp).2
106 test_equal $(tmp).1 $(tmp).2
108 RNDLINES=7331
110 dotest "random skip echo"
111 od < /dev/urandom | head -n $RNDLINES > $(tmp).1
112 $JF -threads=1 -skip=$((RNDLINES - 10)) -exec echo {} < $(tmp).1 > $(tmp).2
113 tail -n 10 < $(tmp).1 > $(tmp).3
114 test_equal $(tmp).2 $(tmp).3
116 dotest "random echo"
117 od < /dev/urandom | head -n $RNDLINES > $(tmp).1
118 $JF -threads=1 -exec echo {} < $(tmp).1 > $(tmp).2
119 test_equal $(tmp).1 $(tmp).2
121 dotest "random echo 2x"
122 od < /dev/urandom | head -n $RNDLINES > $(tmp).1
123 $JF -threads=2 -exec echo {} < $(tmp).1 | sort -u > $(tmp).2
124 test_equal $(tmp).1 $(tmp).2
126 dotest "random echo 3x"
127 od < /dev/urandom | head -n $RNDLINES > $(tmp).1
128 $JF -threads=3 -exec echo {} < $(tmp).1 | sort -u > $(tmp).2
129 test_equal $(tmp).1 $(tmp).2
131 dotest "random echo 4x"
132 od < /dev/urandom | head -n $RNDLINES > $(tmp).1
133 $JF -threads=4 -exec echo {} < $(tmp).1 | sort -u > $(tmp).2
134 test_equal $(tmp).1 $(tmp).2
136 dotest "random echo 17x"
137 od < /dev/urandom | head -n $RNDLINES > $(tmp).1
138 $JF -threads=17 -exec echo {} < $(tmp).1 | sort -u > $(tmp).2
139 test_equal $(tmp).1 $(tmp).2
141 dotest "random echo buffered 17x"
142 od < /dev/urandom | head -n $RNDLINES > $(tmp).1
143 $JF -threads=17 -buffered -exec echo {} < $(tmp).1 | sort -u > $(tmp).2
144 test_equal $(tmp).1 $(tmp).2
146 dotest "random pipe"
147 od < /dev/urandom | head -n $RNDLINES > $(tmp).1
148 $JF -threads=1 -exec cat < $(tmp).1 > $(tmp).2
149 test_equal $(tmp).1 $(tmp).2
151 dotest "random pipe 3x"
152 od < /dev/urandom | head -n $RNDLINES > $(tmp).1
153 $JF -threads=3 -exec cat < $(tmp).1 | sort -u > $(tmp).2
154 test_equal $(tmp).1 $(tmp).2
156 dotest "random pipe 17x"
157 od < /dev/urandom | head -n $RNDLINES > $(tmp).1
158 $JF -threads=17 -exec cat < $(tmp).1 | sort -u > $(tmp).2
159 test_equal $(tmp).1 $(tmp).2
161 dotest "random pipe buffered 17x"
162 od < /dev/urandom | head -n $RNDLINES > $(tmp).1
163 $JF -threads=17 -buffered -exec tests/stdin_printer.out < $(tmp).1 | sort -u > $(tmp).2
164 test_equal $(tmp).1 $(tmp).2