#!/bin/bash # # Copyright (c) 2016-2017, Linaro Ltd. # All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # AOSP Emulator Boot to GUI Test. # https://android-build.linaro.org/jenkins/view/ART-Tip/job/linaro-art-tip-build-BootToGui-aosp_arm64/ readonly local_path=$(dirname "$0") source "${local_path}/../utils/utils.sh" source "${local_path}/../utils/utils_android.sh" readonly default_lunch_target="aosp_arm-eng" readonly watchdog_timer="5m" # 5 minutes watchdog timer. readonly test_timer_name="Boot to GUI Test" readonly boot_timer_name="Time to GUI" readonly test_timer_file="$(get_workspace)/time_test.txt" readonly boot_timer_file="$(get_workspace)/time_boot.txt" readonly logcat_file="$(get_workspace)/log_logcat.txt" declare -A pid usage() { log I "$0" log I "This script is used to run the boot ${default_lunch_target} Jenkins test." log I "By default the lunch target is inferred from the environment as" log I "\${TARGET_PRODUCT}-\${TARGET_BUILD_VARIANT} (as set up by the \`lunch\`" log I "command). If those are not defined \`${default_lunch_target}\` is used" log I "instead. (current environment's default: $(lunch_target_from_env))" log I " -h - help" log I " -v - verbose" } build_target() { log I "Building the ${default_lunch_target} target." make_build } check_boot_to_gui() { start_timer "${boot_timer_name}" # Keep on checking until the watchdog timer kicks in. while true; do local boot_completed=$(adb_shell getprop sys.boot_completed) if [[ ${boot_completed} =~ 1 ]]; then stop_timer "${boot_timer_name}" dump_timer "${boot_timer_name}" "${boot_timer_file}" return 0 fi # Don't spam ADB. Wait 10 seconds before checking again. sleep 10s done } start_watchdog_timer() { log I "Starting the Watchdog Timer." sleep "${watchdog_timer}" # Target has failed to boot in the expected time. log E "${TARGET_PRODUCT} failed to boot in the expected time ${watchdog_timer}." kill "${pid["boot_loop"]}" clean_up } clean_up() { local -a pids_to_kill pids_to_kill+=(${pid["emulator"]}) pids_to_kill+=(${pid["logcat"]}) pids_to_kill+=($(pgrep -P "${pid["emulator"]}")) pids_to_kill+=($(pgrep -P "${pid["logcat"]}")) # Kill the emulator, logcat, and all related processes. kill "${pids_to_kill[@]}" } argument_parser() { while getopts ":vh" opt; do case ${opt} in v) enable_verbose ;; h) usage exit 0 ;; \?) log E "Invalid option: ${OPTARG}" abort ;; esac done } main() { argument_parser "$@" start_timer "${test_timer_name}" # The Boot to GUI test does not need to be run in an Android environmnet. # But if run in an interactive mode ask the user if he is OK to run with the # default target. setup_android_target_to_environment_or_default "${default_lunch_target}" build_target # Launch emulator. safe emulator -no-window & pid["emulator"]=$! # Start logcat. adb logcat > "${logcat_file}" & pid["logcat"]=$! # Run the boot-to-gui loop. check_boot_to_gui & pid["boot_loop"]=$! # Have the watchdog kick in and stop everything else if it lapses. start_watchdog_timer & pid["watchdog"]=$! wait "${pid["boot_loop"]}" ret=$? # Boot loop ended. Watchdog not needed anymore. kill "${pid["watchdog"]}" clean_up stop_timer "${test_timer_name}" dump_timer "${test_timer_name}" "${test_timer_file}" if [[ ${ret} == 0 ]]; then log S "Test finished!" else log E "Test failed!" ret=1 fi return ${ret} } main "$@"