Skip to content

Commit 194188f

Browse files
committed
split up testcases
1 parent cc74efa commit 194188f

14 files changed

+1231
-1182
lines changed

GNUmakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ all: test_x86 test_shm test_python ready $(PROGS) afl-as test_build all_done
270270
man: $(MANPAGES)
271271

272272
tests: source-only
273-
@cd test ; ./test.sh
273+
@cd test ; ./test-all.sh
274274
@rm -f test/errors
275275

276276
performance-tests: performance-test

test/test-all.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/sh
2+
3+
source ./test-pre.sh
4+
5+
source ./test-basic.sh
6+
7+
source ./test-llvm.sh
8+
9+
source ./test-llvm-lto.sh
10+
11+
source ./test-gcc-plugin.sh
12+
13+
source ./test-compcov.sh
14+
15+
source ./test-qemu-mode.sh
16+
17+
source ./test-unicorn-mode.sh
18+
19+
source ./test-custom-mutators.sh
20+
21+
source ./test-unittests.sh
22+
23+
source ./test-post.sh

test/test-basic.sh

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#!/bin/sh
2+
3+
source ./test-pre.sh
4+
5+
$ECHO "$BLUE[*] Testing: ${AFL_GCC}, afl-showmap, afl-fuzz, afl-cmin and afl-tmin"
6+
test "$SYS" = "i686" -o "$SYS" = "x86_64" -o "$SYS" = "amd64" -o "$SYS" = "i86pc" -o "$SYS" = "i386" && {
7+
test -e ../${AFL_GCC} -a -e ../afl-showmap -a -e ../afl-fuzz && {
8+
../${AFL_GCC} -o test-instr.plain ../test-instr.c > /dev/null 2>&1
9+
AFL_HARDEN=1 ../${AFL_GCC} -o test-compcov.harden test-compcov.c > /dev/null 2>&1
10+
test -e test-instr.plain && {
11+
$ECHO "$GREEN[+] ${AFL_GCC} compilation succeeded"
12+
echo 0 | ../afl-showmap -m ${MEM_LIMIT} -o test-instr.plain.0 -r -- ./test-instr.plain > /dev/null 2>&1
13+
../afl-showmap -m ${MEM_LIMIT} -o test-instr.plain.1 -r -- ./test-instr.plain < /dev/null > /dev/null 2>&1
14+
test -e test-instr.plain.0 -a -e test-instr.plain.1 && {
15+
diff test-instr.plain.0 test-instr.plain.1 > /dev/null 2>&1 && {
16+
$ECHO "$RED[!] ${AFL_GCC} instrumentation should be different on different input but is not"
17+
CODE=1
18+
} || {
19+
$ECHO "$GREEN[+] ${AFL_GCC} instrumentation present and working correctly"
20+
}
21+
} || {
22+
$ECHO "$RED[!] ${AFL_GCC} instrumentation failed"
23+
CODE=1
24+
}
25+
rm -f test-instr.plain.0 test-instr.plain.1
26+
TUPLES=`echo 0|../afl-showmap -m ${MEM_LIMIT} -o /dev/null -- ./test-instr.plain 2>&1 | grep Captur | awk '{print$3}'`
27+
test "$TUPLES" -gt 3 -a "$TUPLES" -lt 11 && {
28+
$ECHO "$GREEN[+] ${AFL_GCC} run reported $TUPLES instrumented locations which is fine"
29+
} || {
30+
$ECHO "$RED[!] ${AFL_GCC} instrumentation produces weird numbers: $TUPLES"
31+
CODE=1
32+
}
33+
} || {
34+
$ECHO "$RED[!] ${AFL_GCC} failed"
35+
echo CUT------------------------------------------------------------------CUT
36+
uname -a
37+
../${AFL_GCC} -o test-instr.plain ../test-instr.c
38+
echo CUT------------------------------------------------------------------CUT
39+
CODE=1
40+
}
41+
test -e test-compcov.harden && {
42+
grep -Eq$GREPAOPTION 'stack_chk_fail|fstack-protector-all|fortified' test-compcov.harden > /dev/null 2>&1 && {
43+
$ECHO "$GREEN[+] ${AFL_GCC} hardened mode succeeded and is working"
44+
} || {
45+
$ECHO "$RED[!] ${AFL_GCC} hardened mode is not hardened"
46+
CODE=1
47+
}
48+
rm -f test-compcov.harden
49+
} || {
50+
$ECHO "$RED[!] ${AFL_GCC} hardened mode compilation failed"
51+
CODE=1
52+
}
53+
# now we want to be sure that afl-fuzz is working
54+
# make sure core_pattern is set to core on linux
55+
(test "$(uname -s)" = "Linux" && test "$(sysctl kernel.core_pattern)" != "kernel.core_pattern = core" && {
56+
$ECHO "$YELLOW[-] we should not run afl-fuzz with enabled core dumps. Run 'sudo sh afl-system-config'.$RESET"
57+
true
58+
}) ||
59+
# make sure crash reporter is disabled on Mac OS X
60+
(test "$(uname -s)" = "Darwin" && test $(launchctl list 2>/dev/null | grep -q '\.ReportCrash$') && {
61+
$ECHO "$RED[!] we cannot run afl-fuzz with enabled crash reporter. Run 'sudo sh afl-system-config'.$RESET"
62+
true
63+
}) || {
64+
mkdir -p in
65+
echo 0 > in/in
66+
$ECHO "$GREY[*] running afl-fuzz for ${AFL_GCC}, this will take approx 10 seconds"
67+
{
68+
../afl-fuzz -V10 -m ${MEM_LIMIT} -i in -o out -- ./test-instr.plain >>errors 2>&1
69+
} >>errors 2>&1
70+
test -n "$( ls out/queue/id:000002* 2>/dev/null )" && {
71+
$ECHO "$GREEN[+] afl-fuzz is working correctly with ${AFL_GCC}"
72+
} || {
73+
echo CUT------------------------------------------------------------------CUT
74+
cat errors
75+
echo CUT------------------------------------------------------------------CUT
76+
$ECHO "$RED[!] afl-fuzz is not working correctly with ${AFL_GCC}"
77+
CODE=1
78+
}
79+
echo 000000000000000000000000 > in/in2
80+
echo 111 > in/in3
81+
mkdir -p in2
82+
../afl-cmin -m ${MEM_LIMIT} -i in -o in2 -- ./test-instr.plain >/dev/null 2>&1 # why is afl-forkserver writing to stderr?
83+
CNT=`ls in2/* 2>/dev/null | wc -l`
84+
case "$CNT" in
85+
*2) $ECHO "$GREEN[+] afl-cmin correctly minimized the number of testcases" ;;
86+
*) $ECHO "$RED[!] afl-cmin did not correctly minimize the number of testcases ($CNT)"
87+
CODE=1
88+
;;
89+
esac
90+
rm -f in2/in*
91+
export AFL_QUIET=1
92+
if command -v bash >/dev/null ; then {
93+
../afl-cmin.bash -m ${MEM_LIMIT} -i in -o in2 -- ./test-instr.plain >/dev/null
94+
CNT=`ls in2/* 2>/dev/null | wc -l`
95+
case "$CNT" in
96+
*2) $ECHO "$GREEN[+] afl-cmin.bash correctly minimized the number of testcases" ;;
97+
*) $ECHO "$RED[!] afl-cmin.bash did not correctly minimize the number of testcases ($CNT)"
98+
CODE=1
99+
;;
100+
esac
101+
} else {
102+
$ECHO "$YELLOW[-] no bash available, cannot test afl-cmin.bash"
103+
INCOMPLETE=1
104+
}
105+
fi
106+
../afl-tmin -m ${MEM_LIMIT} -i in/in2 -o in2/in2 -- ./test-instr.plain > /dev/null 2>&1
107+
SIZE=`ls -l in2/in2 2>/dev/null | awk '{print$5}'`
108+
test "$SIZE" = 1 && $ECHO "$GREEN[+] afl-tmin correctly minimized the testcase"
109+
test "$SIZE" = 1 || {
110+
$ECHO "$RED[!] afl-tmin did incorrectly minimize the testcase to $SIZE"
111+
CODE=1
112+
}
113+
rm -rf in out errors in2
114+
unset AFL_QUIET
115+
}
116+
rm -f test-instr.plain
117+
} || {
118+
$ECHO "$YELLOW[-] afl is not compiled, cannot test"
119+
INCOMPLETE=1
120+
}
121+
} || {
122+
$ECHO "$YELLOW[-] not an intel platform, cannot test afl-gcc"
123+
}
124+
125+
source ./test-post.sh

test/test-compcov.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/sh
2+
3+
source ./test-pre.sh
4+
5+
test -z "$AFL_CC" && unset AFL_CC
6+
7+
$ECHO "$BLUE[*] Testing: shared library extensions"
8+
cc $CFLAGS -o test-compcov test-compcov.c > /dev/null 2>&1
9+
test -e ../libtokencap.so && {
10+
AFL_TOKEN_FILE=token.out LD_PRELOAD=../libtokencap.so DYLD_INSERT_LIBRARIES=../libtokencap.so DYLD_FORCE_FLAT_NAMESPACE=1 ./test-compcov foobar > /dev/null 2>&1
11+
grep -q BUGMENOT token.out > /dev/null 2>&1 && {
12+
$ECHO "$GREEN[+] libtokencap did successfully capture tokens"
13+
} || {
14+
$ECHO "$RED[!] libtokencap did not capture tokens"
15+
CODE=1
16+
}
17+
rm -f token.out
18+
} || {
19+
$ECHO "$YELLOW[-] libtokencap is not compiled, cannot test"
20+
INCOMPLETE=1
21+
}
22+
test -e ../libdislocator.so && {
23+
{
24+
ulimit -c 1
25+
# DYLD_INSERT_LIBRARIES and DYLD_FORCE_FLAT_NAMESPACE is used on Darwin/MacOSX
26+
LD_PRELOAD=../libdislocator.so DYLD_INSERT_LIBRARIES=../libdislocator.so DYLD_FORCE_FLAT_NAMESPACE=1 ./test-compcov BUFFEROVERFLOW > test.out 2>/dev/null
27+
} > /dev/null 2>&1
28+
grep -q BUFFEROVERFLOW test.out > /dev/null 2>&1 && {
29+
$ECHO "$RED[!] libdislocator did not detect the memory corruption"
30+
CODE=1
31+
} || {
32+
$ECHO "$GREEN[+] libdislocator did successfully detect the memory corruption"
33+
}
34+
rm -f test.out core test-compcov.core core.test-compcov
35+
} || {
36+
$ECHO "$YELLOW[-] libdislocator is not compiled, cannot test"
37+
INCOMPLETE=1
38+
}
39+
rm -f test-compcov
40+
41+
test -z "$AFL_CC" && {
42+
if type gcc >/dev/null; then
43+
export AFL_CC=gcc
44+
else
45+
if type clang >/dev/null; then
46+
export AFL_CC=clang
47+
fi
48+
fi
49+
}
50+
51+
source ./test-post.sh

test/test-custom-mutators.sh

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#!/bin/sh
2+
3+
source ./test-pre.sh
4+
5+
$ECHO "$BLUE[*] Testing: custom mutator"
6+
test "1" = "`../afl-fuzz | grep -i 'without python' >/dev/null; echo $?`" && {
7+
# normalize path
8+
CUSTOM_MUTATOR_PATH=$(cd $(pwd)/../examples/custom_mutators;pwd)
9+
test -e test-custom-mutator.c -a -e ${CUSTOM_MUTATOR_PATH}/example.c -a -e ${CUSTOM_MUTATOR_PATH}/example.py && {
10+
unset AFL_CC
11+
# Compile the vulnerable program for single mutator
12+
test -e ../afl-clang-fast && {
13+
../afl-clang-fast -o test-custom-mutator test-custom-mutator.c > /dev/null 2>&1
14+
} || {
15+
test -e ../afl-gcc-fast && {
16+
../afl-gcc-fast -o test-custom-mutator test-custom-mutator.c > /dev/null 2>&1
17+
} || {
18+
../afl-gcc -o test-custom-mutator test-custom-mutator.c > /dev/null 2>&1
19+
}
20+
}
21+
# Compile the vulnerable program for multiple mutators
22+
test -e ../afl-clang-fast && {
23+
../afl-clang-fast -o test-multiple-mutators test-multiple-mutators.c > /dev/null 2>&1
24+
} || {
25+
test -e ../afl-gcc-fast && {
26+
../afl-gcc-fast -o test-multiple-mutators test-multiple-mutators.c > /dev/null 2>&1
27+
} || {
28+
../afl-gcc -o test-multiple-mutators test-multiple-mutators.c > /dev/null 2>&1
29+
}
30+
}
31+
# Compile the custom mutator
32+
cc -D_FIXED_CHAR=0x41 -g -fPIC -shared -I../include ../examples/custom_mutators/simple_example.c -o libexamplemutator.so > /dev/null 2>&1
33+
cc -D_FIXED_CHAR=0x42 -g -fPIC -shared -I../include ../examples/custom_mutators/simple_example.c -o libexamplemutator2.so > /dev/null 2>&1
34+
test -e test-custom-mutator -a -e ./libexamplemutator.so && {
35+
# Create input directory
36+
mkdir -p in
37+
echo "00000" > in/in
38+
39+
# Run afl-fuzz w/ the C mutator
40+
$ECHO "$GREY[*] running afl-fuzz for the C mutator, this will take approx 5 seconds"
41+
{
42+
AFL_CUSTOM_MUTATOR_LIBRARY=./libexamplemutator.so AFL_CUSTOM_MUTATOR_ONLY=1 ../afl-fuzz -V1 -m ${MEM_LIMIT} -i in -o out -- ./test-custom-mutator >>errors 2>&1
43+
} >>errors 2>&1
44+
45+
# Check results
46+
test -n "$( ls out/crashes/id:000000* 2>/dev/null )" && { # TODO: update here
47+
$ECHO "$GREEN[+] afl-fuzz is working correctly with the C mutator"
48+
} || {
49+
echo CUT------------------------------------------------------------------CUT
50+
cat errors
51+
echo CUT------------------------------------------------------------------CUT
52+
$ECHO "$RED[!] afl-fuzz is not working correctly with the C mutator"
53+
CODE=1
54+
}
55+
56+
# Clean
57+
rm -rf out errors
58+
59+
# Run afl-fuzz w/ multiple C mutators
60+
$ECHO "$GREY[*] running afl-fuzz with multiple custom C mutators, this will take approx 5 seconds"
61+
{
62+
AFL_CUSTOM_MUTATOR_LIBRARY="./libexamplemutator.so;./libexamplemutator2.so" AFL_CUSTOM_MUTATOR_ONLY=1 ../afl-fuzz -V1 -m ${MEM_LIMIT} -i in -o out -- ./test-multiple-mutators >>errors 2>&1
63+
} >>errors 2>&1
64+
65+
test -n "$( ls out/crashes/id:000000* 2>/dev/null )" && { # TODO: update here
66+
$ECHO "$GREEN[+] afl-fuzz is working correctly with multiple C mutators"
67+
} || {
68+
echo CUT------------------------------------------------------------------CUT
69+
cat errors
70+
echo CUT------------------------------------------------------------------CUT
71+
$ECHO "$RED[!] afl-fuzz is not working correctly with multiple C mutators"
72+
CODE=1
73+
}
74+
75+
# Clean
76+
rm -rf out errors
77+
78+
# Run afl-fuzz w/ the Python mutator
79+
$ECHO "$GREY[*] running afl-fuzz for the Python mutator, this will take approx 5 seconds"
80+
{
81+
export PYTHONPATH=${CUSTOM_MUTATOR_PATH}
82+
export AFL_PYTHON_MODULE=example
83+
AFL_CUSTOM_MUTATOR_ONLY=1 ../afl-fuzz -V5 -m ${MEM_LIMIT} -i in -o out -- ./test-custom-mutator >>errors 2>&1
84+
unset PYTHONPATH
85+
unset AFL_PYTHON_MODULE
86+
} >>errors 2>&1
87+
88+
# Check results
89+
test -n "$( ls out/crashes/id:000000* 2>/dev/null )" && { # TODO: update here
90+
$ECHO "$GREEN[+] afl-fuzz is working correctly with the Python mutator"
91+
} || {
92+
echo CUT------------------------------------------------------------------CUT
93+
cat errors
94+
echo CUT------------------------------------------------------------------CUT
95+
$ECHO "$RED[!] afl-fuzz is not working correctly with the Python mutator"
96+
CODE=1
97+
}
98+
99+
# Clean
100+
rm -rf in out errors
101+
rm -rf ${CUSTOM_MUTATOR_PATH}/__pycache__/
102+
rm -f test-multiple-mutators test-custom-mutator libexamplemutator.so libexamplemutator2.so
103+
} || {
104+
ls .
105+
ls ${CUSTOM_MUTATOR_PATH}
106+
$ECHO "$RED[!] cannot compile the test program or the custom mutator"
107+
CODE=1
108+
}
109+
110+
#test "$CODE" = 1 && { $ECHO "$YELLOW[!] custom mutator tests currently will not fail travis" ; CODE=0 ; }
111+
112+
make -C ../examples/custom_mutators clean > /dev/null 2>&1
113+
rm -f test-custom-mutator
114+
rm -f test-custom-mutators
115+
} || {
116+
$ECHO "$YELLOW[-] no custom mutators in $CUSTOM_MUTATOR_PATH, cannot test"
117+
INCOMPLETE=1
118+
}
119+
unset CUSTOM_MUTATOR_PATH
120+
} || {
121+
$ECHO "$YELLOW[-] no python support in afl-fuzz, cannot test"
122+
INCOMPLETE=1
123+
}
124+
125+
source ./test-post.sh

0 commit comments

Comments
 (0)