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