| #!/bin/bash |
| # Copyright 2018 The Fuchsia Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| ### Performs WLAN smoke tests by reaching out the Internet |
| TEST_TIMEOUT_SEC=80 |
| readonly LOG_DIR="/tmp" |
| readonly LOG_FILE="wlan-doctor.log" |
| readonly SOURCE="garnet/bin/wlan/wlan-smoke.sh" |
| readonly SCRIPT="$(basename ${SOURCE})" |
| readonly ETH_IFACE_PREFIX="en" |
| readonly SHELL_CMD="fx-command-run shell" |
| |
| source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"/lib/vars.sh |
| fx-config-read |
| |
| function usage { |
| cat <<END |
| usage: fx test-wlan [timeout] |
| Copies the test script to target and runs from it. Examine results after {timeout} seconds. |
| END |
| } |
| |
| if [[ $# -gt 1 ]]; then |
| usage |
| exit 1 |
| fi |
| |
| if [[ $# -eq 1 ]]; then |
| re='^[0-9]+$' |
| if [[ $1 =~ $re ]]; then |
| TEST_TIMEOUT_SEC="$1" |
| else |
| usage |
| exit 1 |
| fi |
| fi |
| |
| function setup { |
| "${ZIRCON_TOOLS_DIR}"/netruncmd : ifconfig en2 up |
| } |
| |
| function get_eth_iface_list { |
| local iface_list=$(${SHELL_CMD} ifconfig | grep "^${ETH_IFACE_PREFIX}" | tr '[:blank:]' ' ' | cut -f1 -d ' ') |
| echo "${iface_list}" |
| } |
| |
| function run { |
| fx-command-run cp "${FUCHSIA_DIR}/${SOURCE}" "${LOG_DIR}/${SCRIPT}" > /dev/null 2>&1 |
| local suppres_output=$(${SHELL_CMD} "${LOG_DIR}/${SCRIPT}" "${LOG_DIR}/${LOG_FILE}" &) |
| } |
| |
| function wait_for_result { |
| local timeout="$1" |
| local target_iface="$2" |
| echo "Wait ${timeout} seconds for wlan-smoke to complete" |
| for i in $( seq 1 "$timeout" ); do |
| if [ "$i" -lt 3 ]; then |
| sleep 1 |
| else |
| local ssh_output=$(${SHELL_CMD} -o ConnectTimeout=1 ifconfig "${target_iface}" 2>&1) |
| if echo "${ssh_output}" | grep -q UP ; then |
| printf "\nDone in %d seconds" "$i" |
| break |
| fi |
| fi |
| printf "." |
| if ! ((i % 10)); then |
| printf " " |
| fi |
| if ! ((i % 60)); then |
| echo "" |
| fi |
| done |
| echo "" |
| } |
| |
| function recover_eth { |
| echo "$@" | while read -r eth_iface ; do |
| "${ZIRCON_TOOLS_DIR}"/netruncmd : ifconfig "${eth_iface}" up |
| done |
| } |
| |
| function display_cleanup { |
| fx-command-run cp --to-host "${LOG_DIR}/${LOG_FILE}" "${LOG_DIR}" > /dev/null 2>&1 |
| if [ -f "${LOG_DIR}/${LOG_FILE}" ]; then |
| cat "${LOG_DIR}/${LOG_FILE}" |
| if ! grep -qe "wlan smoke: End$" "${LOG_DIR}/${LOG_FILE}"; then |
| echo "WLAN test result incomplete. Please try again." |
| fi |
| rm "${LOG_DIR}/${LOG_FILE}" |
| else |
| echo "WLAN test result not found. Please try agian." |
| fi |
| } |
| |
| setup |
| eth_iface_list=$(get_eth_iface_list) |
| if [ -z "$eth_iface_list" ]; then |
| echo "No ethernet interface found on target. Please try again." |
| exit 1 |
| fi |
| |
| run |
| wait_for_result "${TEST_TIMEOUT_SEC}" "${eth_iface_list[0]}" |
| recover_eth "${eth_iface_list[@]}" |
| display_cleanup |