xref: /aosp_15_r20/external/AFLplusplus/test/test-unicorn-mode.sh (revision 08b48e0b10e97b33e7b60c5b6e2243bd915777f2)
1#!/bin/sh
2
3. ./test-pre.sh
4
5$ECHO "$BLUE[*] Testing: unicorn_mode"
6test -d ../unicorn_mode/unicornafl -a -e ../unicorn_mode/unicornafl/Makefile && {
7  test -e ../unicorn_mode/samples/python_simple/simple_target.bin -a -e ../unicorn_mode/samples/compcov_x64/compcov_target.bin && {
8    {
9      # We want to see python errors etc. in logs, in case something doesn't work
10      export AFL_DEBUG_CHILD=1
11
12      # some python version should be available now
13      PYTHONS="`command -v python3` `command -v python` `command -v python2`"
14      EASY_INSTALL_FOUND=0
15      for PYTHON in $PYTHONS ; do
16
17        if $PYTHON -c "import setuptools" ; then
18
19            EASY_INSTALL_FOUND=1
20            PY=$PYTHON
21            break
22
23        fi
24
25      done
26      if [ "0" = $EASY_INSTALL_FOUND ]; then
27
28        echo "[-] Error: Python setup-tools not found. Run 'sudo apt-get install python-setuptools'."
29        PREREQ_NOTFOUND=1
30
31      fi
32
33
34      cd ../unicorn_mode/samples/persistent
35      make >>errors 2>&1
36      $ECHO "$GREY[*] running afl-fuzz for unicorn_mode (persistent), this will take approx 25 seconds"
37      AFL_DEBUG_CHILD=1 ../../../afl-fuzz -m none -V15 -U -i sample_inputs -o out -d -- ./harness @@ >>errors 2>&1
38      test -n "$( ls out/default/queue/id:000002* 2>/dev/null )" && {
39        $ECHO "$GREEN[+] afl-fuzz is working correctly with unicorn_mode (persistent)"
40      } || {
41        echo CUT------------------------------------------------------------------CUT
42        cat errors
43        echo CUT------------------------------------------------------------------CUT
44        $ECHO "$RED[!] afl-fuzz is not working correctly with unicorn_mode (persistent)"
45        CODE=1
46      }
47
48      rm -rf out errors >/dev/null
49      make clean >/dev/null
50      cd ../../../test
51
52      # travis workaround
53      test "$PY" = "/opt/pyenv/shims/python" -a -x /usr/bin/python && PY=/usr/bin/python
54      mkdir -p in
55      echo 0 > in/in
56      $ECHO "$GREY[*] Using python binary $PY"
57      if ! $PY -c 'import unicornafl' 2>/dev/null ; then
58        $ECHO "$YELLOW[-] we cannot test unicorn_mode for python because it is not present"
59        INCOMPLETE=1
60      else
61      {
62        $ECHO "$GREY[*] running afl-fuzz for unicorn_mode in python, this will take approx 25 seconds"
63        {
64          ../afl-fuzz -m ${MEM_LIMIT} -V15 -U -i in -o out -d -- "$PY" ../unicorn_mode/samples/python_simple/simple_test_harness.py @@ >>errors 2>&1
65        } >>errors 2>&1
66        test -n "$( ls out/default/queue/id:000002* 2>/dev/null )" && {
67          $ECHO "$GREEN[+] afl-fuzz is working correctly with unicorn_mode"
68        } || {
69          echo CUT------------------------------------------------------------------CUT
70          cat errors
71          echo CUT------------------------------------------------------------------CUT
72          $ECHO "$RED[!] afl-fuzz is not working correctly with unicorn_mode"
73          CODE=1
74        }
75        rm -f errors
76
77        printf '\x01\x01' > in/in
78        # This seed is close to the first byte of the comparison.
79        # If CompCov works, a new tuple will appear in the map => new input in queue
80        $ECHO "$GREY[*] running afl-fuzz for unicorn_mode compcov, this will take approx 35 seconds"
81        {
82          export AFL_COMPCOV_LEVEL=2
83          ../afl-fuzz -m ${MEM_LIMIT} -V15 -U -i in -o out -d -- "$PY" ../unicorn_mode/samples/compcov_x64/compcov_test_harness.py @@ >>errors 2>&1
84          unset AFL_COMPCOV_LEVEL
85        } >>errors 2>&1
86        test -n "$( ls out/default/queue/id:000001* 2>/dev/null )" && {
87          $ECHO "$GREEN[+] afl-fuzz is working correctly with unicorn_mode compcov"
88        } || {
89          echo CUT------------------------------------------------------------------CUT
90          cat errors
91          echo CUT------------------------------------------------------------------CUT
92          $ECHO "$RED[!] afl-fuzz is not working correctly with unicorn_mode compcov"
93          CODE=1
94        }
95        rm -rf in out errors
96      }
97      fi
98
99      unset AFL_DEBUG_CHILD
100
101    }
102  } || {
103    $ECHO "$RED[!] missing sample binaries in unicorn_mode/samples/ - what is going on??"
104    CODE=1
105  }
106
107} || {
108  $ECHO "$YELLOW[-] unicorn_mode is not compiled, cannot test"
109  INCOMPLETE=1
110}
111
112. ./test-post.sh
113