1#! /bin/bash
2
3if [[ -z "${ANDROID_BUILD_TOP}" ]]; then
4  echo "ANDROID_BUILD_TOP is not set"
5fi
6
7if [[ -z "${ANDROID_HOST_OUT}" ]]; then
8  echo "ANDROID_HOST_OUT is not set for host run"
9fi
10
11HOST=false
12POSITIONAL=()
13while [[ $# -gt 0 ]]
14do
15key="$1"
16case $key in
17    --host)
18    HOST=true
19    shift # past argument
20    ;;
21    *)    # unknown option
22    POSITIONAL+=("$1") # save it in an array for later
23    shift # past argument
24    ;;
25esac
26done
27set -- "${POSITIONAL[@]}" # restore positional parameters
28
29TEST_NAME=bluetooth_gd_${1}_fuzz_test
30
31if [ "$HOST" == true ] ; then
32  HOST_ARCH=$($ANDROID_BUILD_TOP/build/soong/soong_ui.bash --dumpvar-mode HOST_ARCH)
33  SANITIZE_HOST=address $ANDROID_BUILD_TOP/build/soong/soong_ui.bash --build-mode --"all-modules" --dir="$(pwd)" $TEST_NAME && ${ANDROID_HOST_OUT}/fuzz/$HOST_ARCH/$TEST_NAME/$TEST_NAME $2
34fi
35