1#!/usr/bin/env bash 2_USAGE="avatar [OPTIONS] <COMMAND> ... 3 OPTIONS: 4 -h, --help Show this message and exit. 5 COMMANDS: 6 help Show this message and exit. 7 format [FILES..] Format python test files. 8 Files in 'p/m/B/android/pandora/test/*.py' are included by default. 9 lint [FILES..] Lint python test files. 10 Files in 'p/m/B/android/pandora/test/*.py' are included by default. 11 run [OPTIONS..] Run avatar tests through tradefed. 12 OPTIONS: (subset, see 'avatar run --help-all') 13 --include-filter=<ClassA[#test_a]> 14 Add a test filter in form of 'ClassA[#test_a]'. 15 --test-bed Set mobly test bed (default is 'android.bumbles'). 16 --mobly-std-log Print mobly logs to standard outputs. 17 --mobly-options=<'--opt-a --opt-b'> 18 Pass additional options to mobly, like '--verbose' or '--list_tests'. 19 ... All other tradefed options, like '--log-level VERBOSE'. 20 See 'avatar run --help-all' 21 " 22 23_VENV_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/avatar/venv" 24_BT_ROOT="${ANDROID_BUILD_TOP}/packages/modules/Bluetooth" 25_TEST_ROOT="${_BT_ROOT}/android/pandora/test" 26_PY_SOURCES=( 27 "${ANDROID_BUILD_TOP}/external/pandora/avatar/"{avatar,examples} 28 "${_BT_ROOT}/pandora/server/bumble_experimental" 29 "${_TEST_ROOT}/"*_test.py 30 "${_TEST_ROOT}/main.py" 31) 32 33_PANDORA_PYTHON_PATHS=( 34 "${_BT_ROOT}/pandora/server/" 35 "${ANDROID_BUILD_TOP}/external/pandora/avatar/" 36 "${ANDROID_BUILD_TOP}/external/python/bumble/" 37 "${ANDROID_BUILD_TOP}/external/python/mobly/" 38 "${ANDROID_BUILD_TOP}/external/python/pyee/" 39 "${ANDROID_BUILD_TOP}/out/soong/.intermediates/external/pandora/bt-test-interfaces/python/pandora-python-gen-src/gen/" 40 "${ANDROID_BUILD_TOP}/out/soong/.intermediates/packages/modules/Bluetooth/pandora/interfaces/python/pandora_experimental-python-gen-src/gen/" 41) 42 43if [[ "$1" =~ ^('format'|'lint'|'run')$ ]]; then 44 [ ! -d "${_VENV_DIR}" ] && python3 -m venv "${_VENV_DIR}" 45 source "${_VENV_DIR}"/bin/activate 46 pip install \ 47 'grpcio==1.51.1' \ 48 'cryptography==35' \ 49 'protobuf==4.22.1' \ 50 'pyright==1.1.298' \ 51 'mypy==1.1.1' \ 52 'types-protobuf==4.22.0.1' \ 53 'black==22.10.0' \ 54 'isort==5.12.0' 55 export PYTHONPATH="$(IFS=:; echo "${_PANDORA_PYTHON_PATHS[*]}"):${PYTHONPATH}" 56fi 57 58case "$1" in 59 'format') shift 60 black -S -l 119 "$@" "${_PY_SOURCES[@]}" 61 isort --profile black -l 119 --ds --lbt 1 --ca "$@" "${_PY_SOURCES[@]}" 62 ;; 63 'lint') shift 64 mypy \ 65 --pretty --show-column-numbers --strict --no-warn-unused-ignores --ignore-missing-imports \ 66 "$@" "${_PY_SOURCES[@]}" || exit 1 67 pyright \ 68 -p "${_TEST_ROOT}" \ 69 "$@" "${_PY_SOURCES[@]}" 70 ;; 71 'run') shift 72 tradefed.sh \ 73 run commandAndExit template/local_min --template:map test=avatar --log-level INFO \ 74 --venv-dir "${_VENV_DIR}" \ 75 "$@" 76 ;; 77 'help'|'--help'|'-h') shift 78 echo "${_USAGE}" 79 exit 0 80 ;; 81 '') 82 echo "no command provided (try help)" 83 echo "${_USAGE}" 84 exit 1 85 ;; 86 *) 87 echo "$1: invalid command (try help)" 88 echo "${_USAGE}" 89 exit 1 90 ;; 91esac 92