diff --git a/automated/android/apk-automation/apk-automation.sh b/automated/android/apk-automation/apk-automation.sh index f3dd56ce1..d0106e0a4 100755 --- a/automated/android/apk-automation/apk-automation.sh +++ b/automated/android/apk-automation/apk-automation.sh @@ -42,7 +42,7 @@ if [ "${SKIP_INSTALL}" = "true" ] || [ "${SKIP_INSTALL}" = "True" ]; then else ! check_root && error_msg "Please run this script as superuser!" #install_deps "git python python-lxml python-pil python-setuptools python-requests python-matplotlib python-requests ca-certificates curl tar xz-utils" "${SKIP_INSTALL}" - install_deps "python3.9 python3-distutils git ca-certificates curl tar xz-utils" "${SKIP_INSTALL}" + install_deps "python3 python3-distutils git ca-certificates curl tar xz-utils" "${SKIP_INSTALL}" if python3 --version|grep 'Python 3.6'; then # Workaround for Ubuntu 18.04 Bionic version. # ModuleNotFoundError: No module named 'distutils.cmd' needs python3-distutils @@ -53,12 +53,13 @@ else url_android_view_clien="https://github.com/dtmilano/AndroidViewClient" fi + chech_python_version "$(python --verison)" "3.9" "Error" curl "${url_pip}" -o get-pip.py sudo python3 get-pip.py sudo pip install virtualenv pip --version virenv_dir=python-workspace - virtualenv --python=python3.9 ${virenv_dir} + virtualenv --python=python3 ${virenv_dir} [ ! -d AndroidViewClient ] && git clone --depth 1 "${url_android_view_clien}" # shellcheck disable=SC1090 source ${virenv_dir}/bin/activate diff --git a/automated/android/noninteractive-tradefed/setup.sh b/automated/android/noninteractive-tradefed/setup.sh index de5bbd3d3..651311233 100755 --- a/automated/android/noninteractive-tradefed/setup.sh +++ b/automated/android/noninteractive-tradefed/setup.sh @@ -5,15 +5,23 @@ . ../../lib/sh-test-lib . ../../lib/android-test-lib +SKIP_INSTALL=${1:-"false"} +JDK="openjdk-11-jdk-headless" java_path="/usr/lib/jvm/java-11-openjdk-amd64/bin/java" if [ -n "${ANDROID_VERSION}" ] && echo "${ANDROID_VERSION}" | grep -q "aosp-android14"; then # use openjdk-17 for Android14+ versions + JDK="openjdk-17-jdk-headless" java_path="/usr/lib/jvm/java-17-openjdk-amd64/bin/java" fi +PKG_DEPS="aapt apt-utils bzip2 coreutils curl git lib32gcc-s1-amd64-cross libcurl4 protobuf-compiler psmisc python3 python-is-python3 python3-lxml python3-pexpect python3-protobuf python3-setuptools sudo tar unzip usbutils wget xz-utils zip " + dist_name case "${dist}" in ubuntu) + dpkg --add-architecture i386 + apt-get update -q + install_deps "${PKG_DEPS} ${JDK}" "${SKIP_INSTALL}" # make sure to use the right java version update-alternatives --set java ${java_path} ;; @@ -22,6 +30,10 @@ case "${dist}" in ;; esac +# Only aosp-master need the python version check. +if [ -n "${ANDROID_VERSION}" ] && echo "${ANDROID_VERSION}" | grep -q "aosp-master"; then + chech_python_version "$(python --verison)" "3.8" "Error" +fi install_latest_adb initialize_adb adb_root diff --git a/automated/android/noninteractive-tradefed/tradefed.yaml b/automated/android/noninteractive-tradefed/tradefed.yaml index a03900976..b2c95f101 100644 --- a/automated/android/noninteractive-tradefed/tradefed.yaml +++ b/automated/android/noninteractive-tradefed/tradefed.yaml @@ -14,6 +14,7 @@ metadata: - functional params: + SKIP_INSTALL: "false" # Specify timeout in seconds for wait_boot_completed and wait_homescreen. TIMEOUT: "300" # Download CTS package or copy it from local disk. @@ -46,7 +47,7 @@ run: steps: - cd ./automated/android/noninteractive-tradefed # Run setup.sh in the original shell to reserve env variables. - - . ./setup.sh + - . ./setup.sh "${SKIP_INSTALL}" - echo "after ./setup.sh" # delete the test user to clean environment - userdel testuser -r -f || true diff --git a/automated/lib/sh-test-lib b/automated/lib/sh-test-lib index a18f127af..cbddf65e0 100755 --- a/automated/lib/sh-test-lib +++ b/automated/lib/sh-test-lib @@ -766,3 +766,52 @@ check_config() { check_return "config_value_${c}" done } + +major() { + # shellcheck disable=SC2039 + local pv="${1}" + echo "${pv}" | awk -F'.' '{print $1}' +} + +minor() { + # shellcheck disable=SC2039 + local pv="${1}" + echo "${pv}" | awk -F'.' '{print $2}' +} + +check_python_version() { + # send in "python --version" + local pv="${1}" + python_version=$(echo "${pv}" | awk -F' ' '{print $NF}') + # example "3.9" + local min_version="${2}" + local err="${3}" + # shellcheck disable=SC2155 + local x="$(major "${python_version}")" + # shellcheck disable=SC2155 + local y="$(minor "${python_version}")" + # shellcheck disable=SC2155 + local mx="$(major "${min_version}")" + # shellcheck disable=SC2155 + local my="$(minor "${min_version}")" + # shellcheck disable=SC2155 + local str="Wrong Python version installed ${pv}" + if [ "${x}" -lt "${mx}" ]; then + if [ "${err}" = "Error" ]; then + error_msg "${str}" + else + warn_msg "${str}" + return + fi + fi + + if [ "${y}" -lt "${my}" ]; then + if [ "${x}" -le "${mx}" ]; then + if [ "${err}" = "Error" ]; then + error_msg "${str}" + else + warn_msg "${str}" + fi + fi + fi +}