1#!/bin/sh 2 3. ./test-pre.sh 4 5$ECHO "$BLUE[*] Testing: LTO llvm_mode" 6test -e ../afl-clang-lto -a -e ../SanitizerCoverageLTO.so && { 7 # on FreeBSD need to set AFL_CC 8 test `uname -s` = 'FreeBSD' && { 9 if type clang >/dev/null; then 10 export AFL_CC=`command -v clang` 11 else 12 export AFL_CC=`$LLVM_CONFIG --bindir`/clang 13 fi 14 } 15 16 ../afl-clang-lto -o test-instr.plain ../test-instr.c > /dev/null 2>&1 17 test -e test-instr.plain && { 18 $ECHO "$GREEN[+] llvm_mode LTO compilation succeeded" 19 echo 0 | AFL_QUIET=1 ../afl-showmap -m ${MEM_LIMIT} -o test-instr.plain.0 -r -- ./test-instr.plain > /dev/null 2>&1 20 AFL_QUIET=1 ../afl-showmap -m ${MEM_LIMIT} -o test-instr.plain.1 -r -- ./test-instr.plain < /dev/null > /dev/null 2>&1 21 test -e test-instr.plain.0 -a -e test-instr.plain.1 && { 22 diff -q test-instr.plain.0 test-instr.plain.1 > /dev/null 2>&1 && { 23 $ECHO "$RED[!] llvm_mode LTO instrumentation should be different on different input but is not" 24 CODE=1 25 } || { 26 $ECHO "$GREEN[+] llvm_mode LTO instrumentation present and working correctly" 27 TUPLES=`echo 0|AFL_QUIET=1 ../afl-showmap -m ${MEM_LIMIT} -o /dev/null -- ./test-instr.plain 2>&1 | grep Captur | awk '{print$3}'` 28 test "$TUPLES" -gt 2 -a "$TUPLES" -lt 7 && { 29 $ECHO "$GREEN[+] llvm_mode LTO run reported $TUPLES instrumented locations which is fine" 30 } || { 31 $ECHO "$RED[!] llvm_mode LTO instrumentation produces weird numbers: $TUPLES" 32 CODE=1 33 } 34 } 35 } || { 36 $ECHO "$RED[!] llvm_mode LTO instrumentation failed" 37 CODE=1 38 } 39 rm -f test-instr.plain.0 test-instr.plain.1 40 } || { 41 $ECHO "$RED[!] LTO llvm_mode failed" 42 CODE=1 43 } 44 rm -f test-instr.plain 45 46 echo foobar.c > instrumentlist.txt 47 AFL_DEBUG=1 AFL_LLVM_INSTRUMENT_FILE=instrumentlist.txt ../afl-clang-lto -o test-compcov test-compcov.c > test.out 2>&1 48 test -e test-compcov && { 49 grep -q "No instrumentation targets found" test.out && { 50 $ECHO "$GREEN[+] llvm_mode LTO instrumentlist feature works correctly" 51 } || { 52 echo CUT------------------------------------------------------------------CUT 53 cat test.out 54 echo CUT------------------------------------------------------------------CUT 55 $ECHO "$RED[!] llvm_mode LTO instrumentlist feature failed" 56 CODE=1 57 } 58 } || { 59 $ECHO "$RED[!] llvm_mode LTO instrumentlist feature compilation failed" 60 CODE=1 61 } 62 rm -f test-compcov test.out instrumentlist.txt 63 ../afl-clang-lto -o test-persistent ../utils/persistent_mode/persistent_demo.c > /dev/null 2>&1 64 test -e test-persistent && { 65 echo foo | AFL_QUIET=1 ../afl-showmap -m none -o /dev/null -q -r ./test-persistent && { 66 $ECHO "$GREEN[+] llvm_mode LTO persistent mode feature works correctly" 67 } || { 68 $ECHO "$RED[!] llvm_mode LTO persistent mode feature failed to work" 69 CODE=1 70 } 71 } || { 72 $ECHO "$RED[!] llvm_mode LTO persistent mode feature compilation failed" 73 CODE=1 74 } 75 rm -f test-persistent 76} || { 77 $ECHO "$YELLOW[-] LTO llvm_mode not compiled, cannot test" 78 INCOMPLETE=1 79} 80 81. ./test-post.sh 82