1#!/bin/sh 2 3# All tests should start with sourcing test-pre.sh and finish with sourcing test-post.sh 4# They may set an error code with $CODE=1 5# If tests are incomplete, they may set $INCOMPLETE=1 6 7AFL_TEST_COUNT=$((AFL_TEST_COUNT+1)) 8AFL_TEST_DEPTH=$((AFL_TEST_DEPTH+1)) 9 10if [ $AFL_TEST_DEPTH = 1 ]; then 11# First run :) 12 13# 14# Ensure we have: test, type, diff, grep -qE 15# 16test -z "" 2>/dev/null || { echo Error: test command not found ; exit 1 ; } 17GREP=`type grep > /dev/null 2>&1 && echo OK` 18test "$GREP" = OK || { echo Error: grep command not found ; exit 1 ; } 19echo foobar | grep -qE 'asd|oob' 2>/dev/null || { echo Error: grep command does not support -q and/or -E option ; exit 1 ; } 20test -e ./test-all.sh || cd $(dirname $0) || exit 1 21test -e ./test-all.sh || { echo Error: you must be in the test/ directory ; exit 1 ; } 22export AFL_PATH=`pwd`/.. 23export AFL_TRY_AFFINITY=1 # workaround for travis that fails for no avail cores 24 25echo 1 > test.1 26echo 1 > test.2 27OK=OK 28diff test.1 test.2 >/dev/null 2>&1 || OK= 29rm -f test.1 test.2 30test -z "$OK" && { echo Error: diff is not working ; exit 1 ; } 31test -z "$LLVM_CONFIG" && LLVM_CONFIG=llvm-config 32 33# check for '-a' option of grep 34if grep -a test test-all.sh >/dev/null 2>&1; then 35 GREPAOPTION=' -a' 36else 37 GREPAOPTION= 38fi 39 40test_compcov_binary_functionality() { 41 RUN="../afl-showmap -m ${MEM_LIMIT} -o /dev/null -- $1" 42 $RUN 'LIBTOKENCAP' | grep 'your string was LIBTOKENCAP' \ 43 && $RUN 'BUGMENOT' | grep 'your string was BUGMENOT' \ 44 && $RUN 'BANANA' | grep 'your string started with BAN' \ 45 && $RUN 'APRI' | grep 'your string was APRI' \ 46 && $RUN 'kiWI' | grep 'your string was Kiwi' \ 47 && $RUN 'Avocado' | grep 'your string was avocado' \ 48 && $RUN 'GRAX' 3 | grep 'your string was a prefix of Grapes' \ 49 && $RUN 'LOCALVARIABLE' | grep 'local var memcmp works!' \ 50 && $RUN 'abc' | grep 'short local var memcmp works!' \ 51 && $RUN 'GLOBALVARIABLE' | grep 'global var memcmp works!' 52} > /dev/null 53 54ECHO="printf %b\\n" 55$ECHO \\101 2>&1 | grep -qE '^A' || { 56 ECHO= 57 test -e /bin/printf && { 58 ECHO="/bin/printf %b\\n" 59 $ECHO "\\101" 2>&1 | grep -qE '^A' || ECHO= 60 } 61} 62test -z "$ECHO" && { printf Error: printf command does not support octal character codes ; exit 1 ; } 63 64export AFL_EXIT_WHEN_DONE=1 65export AFL_EXIT_ON_TIME=60 66export AFL_SKIP_CPUFREQ=1 67export AFL_I_DONT_CARE_ABOUT_MISSING_CRASHES=1 68unset AFL_NO_X86 69unset AFL_QUIET 70unset AFL_DEBUG 71unset AFL_HARDEN 72unset AFL_USE_ASAN 73unset AFL_USE_MSAN 74unset AFL_USE_UBSAN 75unset AFL_USE_LSAN 76unset AFL_TMPDIR 77unset AFL_CC 78unset AFL_PRELOAD 79unset AFL_GCC_INSTRUMENT_FILE 80unset AFL_LLVM_INSTRUMENT_FILE 81unset AFL_LLVM_INSTRIM 82unset AFL_LLVM_LAF_SPLIT_SWITCHES 83unset AFL_LLVM_LAF_TRANSFORM_COMPARES 84unset AFL_LLVM_LAF_SPLIT_COMPARES 85unset AFL_QEMU_PERSISTENT_ADDR 86unset AFL_QEMU_PERSISTENT_RETADDR_OFFSET 87unset AFL_QEMU_PERSISTENT_GPR 88unset AFL_QEMU_PERSISTENT_RET 89unset AFL_QEMU_PERSISTENT_HOOK 90unset AFL_QEMU_PERSISTENT_CNT 91unset AFL_QEMU_PERSISTENT_MEM 92unset AFL_QEMU_PERSISTENT_EXITS 93unset AFL_CUSTOM_MUTATOR_LIBRARY 94unset AFL_PYTHON_MODULE 95unset AFL_PRELOAD 96unset LD_PRELOAD 97unset SKIP 98 99rm -rf in in2 out 100 101test -z "$TRAVIS_OS_NAME" && { 102 export ASAN_OPTIONS=detect_leaks=0:allocator_may_return_null=1:abort_on_error=1:symbolize=0 103} 104test -n "$TRAVIS_OS_NAME" && { 105 export ASAN_OPTIONS=detect_leaks=0:allocator_may_return_null=1:abort_on_error=1:symbolize=1 106} 107 108#export AFL_LLVM_INSTRUMENT=AFL # AFL mode makes dlopen not link on macos 109 110# on OpenBSD we need to work with llvm from /usr/local/bin 111test -e /usr/local/bin/opt && { 112 test `uname -s` = 'Darwin' || export PATH="/usr/local/bin:${PATH}" 113} 114# on MacOS X we prefer afl-clang over afl-gcc, because 115# afl-gcc does not work there (it is a symlink from clang) 116test `uname -s` = 'Darwin' -o `uname -s` = 'FreeBSD' && { 117 AFL_GCC=afl-clang 118} || { 119 AFL_GCC=afl-gcc 120} 121command -v gcc >/dev/null 2>&1 || AFL_GCC=afl-clang 122 123SYS=`uname -m` 124 125GREY="\\033[1;90m" 126BLUE="\\033[1;94m" 127GREEN="\\033[0;32m" 128RED="\\033[0;31m" 129YELLOW="\\033[1;93m" 130RESET="\\033[0m" 131 132MEM_LIMIT=none 133 134export PATH="${PATH}:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin" 135 136$ECHO "${RESET}${GREY}[*] starting AFL++ test framework ..." 137 138test -z "$SYS" && $ECHO "$YELLOW[-] uname -m did not succeed" 139 140CODE=0 141INCOMPLETE=0 142 143fi 144