-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfuzz.sh
executable file
·80 lines (67 loc) · 1.97 KB
/
fuzz.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
#!/bin/sh
# https://gitlab.com/akihe/radamsa
# radamsa -n produces multiple outputs in one go. However that doesn't suit
# the use here, because we're inspecting output for certian properties for
# each output, and concatenating them all would tend to miss the latter texts
# by bailing out on earlier errors.
#
# I think using -n would make sense for testing in parallel, if lfdump were
# to support that.
die() {
echo $* >&2
exit 1
}
verbose=0
if [ "$1" = '-v' ]; then
verbose=1
shift
fi
x=0
while true; do
case $x in
0)
x=1
# TODO: don't actually want an OCTET here, be more specific
(
kgt -l iso-ebnf -e blab < doc/logfmt.ebnf;
echo 'OCTET=[\x00-\xff] ALPHA=[A-Za-z] DIGIT=[0-9]'
) | blab -f 100
;;
1)
x=0
cat $BUILD/test/blab.fmt $* | sort -R \ | head -1
;;
esac | radamsa -o $BUILD/test/fuzz.fmt
$BUILD/bin/lfdump "`cat $BUILD/test/fuzz.fmt`" \
> $BUILD/test/fuzz.out \
2> $BUILD/test/fuzz.err
r=$?
if [ $verbose -eq 1 ]; then
echo -e '\e[HJ\e[2J'
cat $BUILD/test/fuzz.fmt | head -5
echo "-- stdout --"; cat $BUILD/test/fuzz.out | head -10
echo "-- stderr --"; cat $BUILD/test/fuzz.err | head -20
fi
if [ `stat -c '%s' $BUILD/test/fuzz.out` -gt 0 ]; then
grep -qvi '^error: ' $BUILD/test/fuzz.out || die "unexpected error"
fi
if [ $r -eq 1 ]; then
grep -qvi '^error: success' $BUILD/test/fuzz.err || die "success error"
grep -q '^error: ' $BUILD/test/fuzz.err || die "missing error"
grep -q "^at [0-9]\+: '.\+'\$" $BUILD/test/fuzz.err || die "ill-formed line"
grep -q '^-*\^\+$' $BUILD/test/fuzz.err || die "ill-formed marker"
fi
if [ $r -eq 0 ]; then
[ `stat -c '%s' $BUILD/test/fuzz.err` -eq 0 ] || die "unexpected stderr output"
fi
if [ $r -gt 127 ]; then
if [ $verbose -ne 1 ]; then
echo -e '\e[HJ\e[2J'
echo "-- input --"; cat $BUILD/test/fuzz.fmt
echo "-- \$?=$r"
echo "-- stdout --"; cat $BUILD/test/fuzz.out
echo "-- stderr --"; cat $BUILD/test/fuzz.err
fi
break
fi
done