From 86c2feaf11286ab3534190cebed9c688f7da5f72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?An=C3=ADbal=20Lim=C3=B3n?= Date: Fri, 1 Jun 2018 13:31:22 -0500 Subject: automated/linux: Add wlan download test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The test will connect to the specified SSID and then make a download of file with checksum validation if FILE_URL is specified. The test uses wpa_supplicant and dhclient to get the connection, if you specify an ETHERNET_DEVICE it will down the iface previous to start the connection/download test with Wireless LAN. Change-Id: I79fd2ea6582997790a72f6d7e0ae157e6ee817d6 Signed-off-by: Aníbal Limón --- .../linux/wlan-download/wlan-download-test.sh | 142 +++++++++++++++++++++ automated/linux/wlan-download/wlan-download.yaml | 34 +++++ 2 files changed, 176 insertions(+) create mode 100755 automated/linux/wlan-download/wlan-download-test.sh create mode 100644 automated/linux/wlan-download/wlan-download.yaml (limited to 'automated/linux/wlan-download') diff --git a/automated/linux/wlan-download/wlan-download-test.sh b/automated/linux/wlan-download/wlan-download-test.sh new file mode 100755 index 00000000..26c1804d --- /dev/null +++ b/automated/linux/wlan-download/wlan-download-test.sh @@ -0,0 +1,142 @@ +#!/bin/sh +# +# WLAN download test +# +# Copyright (C) 2018, Linaro Limited. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# Author: Anibal Limon +# + +set -x + +# shellcheck disable=SC1091 +. ../../lib/sh-test-lib +OUTPUT="$(pwd)/output" +RESULT_FILE="${OUTPUT}/result.txt" +export RESULT_FILE +DEVICE="wlan0" +ETHERNET_DEVICE="" +SSID_NAME="" +SSID_PASSWORD="" +FILE_URL="" +FILE_CHECKSUM="" +TIME_DELAY="0s" +NAMESERVER="" + +usage() { + echo "Usage: $0 <-s ssid_name> <-p ssid_password> [-d device] [-e ethernet_device] [-u file_url] [-c file_checksum] [-t time_delay] [-n nameserver]" 1>&2 + exit 1 +} + +while getopts "d:e:s:p:u:c:t:n:" o; do + case "$o" in + d) DEVICE="${OPTARG}" ;; + e) ETHERNET_DEVICE="${OPTARG}" ;; + s) SSID_NAME="${OPTARG}" ;; + p) SSID_PASSWORD="${OPTARG}" ;; + u) FILE_URL="${OPTARG}" ;; + c) FILE_CHECKSUM="${OPTARG}" ;; + t) TIME_DELAY="${OPTARG}" ;; + n) NAMESERVER="${OPTARG}" ;; + *) usage ;; + esac +done + +if [ -z "${SSID_NAME}" ] || [ -z "${SSID_PASSWORD}" ]; then + usage +fi + +# test WLAN device connection +test_wlan_connection() { + info_msg "Running wlan connect test..." + echo "ctrl_interface=/var/run/wpa_supplicant" > /tmp/wpa.conf + echo "update_config=1" >> /tmp/wpa.conf + wpa_passphrase "${SSID_NAME}" "${SSID_PASSWORD}" >> /tmp/wpa.conf + wpa_supplicant -dd -Dnl80211 -P /tmp/wpa_supplicant.pid -i "${DEVICE}" -c /tmp/wpa.conf -B + dhclient -pf /tmp/dhclient.pid "${DEVICE}" + check_return "wlan-connect" + has_address=$(ip -f inet addr show "${DEVICE}") + if [ -z "${has_address}" ]; then + report_fail "wlan-ip-address" + kill -9 "$(cat /tmp/wpa_supplicant.pid)" + kill -9 "$(cat /tmp/dhclient.pid)" + exit 1 + fi + echo "IP Address:" + echo "${has_address}" + report_pass "wlan-ip-address" + echo "IP Route:" + ip route + + if [ ! -z "${NAMESERVER}" ]; then + mv /etc/resolv.conf /etc/resolv.conf.backup + echo "nameserver ${NAMESERVER}" > /etc/resolv.conf + fi +} + +# test WLAN download +test_wlan_download() { + info_msg "Running wlan download test..." + hostname="$(echo "${FILE_URL}" | sed 's/.*:\/\///;s|\/.*||')" + ping -c 4 "${hostname}" + check_return "wlan-ping" + curl -OL --interface "${DEVICE}" "${FILE_URL}" + check_return "wlan-download" + local_file="$(basename "${FILE_URL}")" + local_md5="$(md5sum "$(basename "${local_file}")" | awk '{print $1}')" + echo "local_md5=${local_md5}" + test "${local_md5}" = "${FILE_CHECKSUM}" + check_return "wlan-download-checksum" + rm -f "${local_file}" +} + +# Test run. +! check_root && error_msg "This script must be run as root" +create_out_dir "${OUTPUT}" + +info_msg "About to run wlan download test..." +info_msg "Output directory: ${OUTPUT}" + +if [ ! -z "${ETHERNET_DEVICE}" ]; then + ip link set "${ETHERNET_DEVICE}" down + check_return "eth-down" +fi + +systemctl stop wpa_supplicant # to don't interfere with our wpa_supplicant instance +ip link set "${DEVICE}" up +sleep "${TIME_DELAY}" # XXX: some devices needs a wait after up to be ready, default: 0s +iw dev "${DEVICE}" scan +exit_on_fail "wlan-scan" +test_wlan_connection +if [ ! -z "${FILE_URL}" ]; then + test_wlan_download +fi + +wpa_cli remove_network 0 +check_return "wlan-disconnect" +ip link set "${DEVICE}" down +kill -9 "$(cat /tmp/wpa_supplicant.pid)" +kill -9 "$(cat /tmp/dhclient.pid)" + +if [ ! -z "${NAMESERVER}" ]; then + mv /etc/resolv.conf.backup /etc/resolv.conf +fi + +if [ ! -z "${ETHERNET_DEVICE}" ]; then + ip link set "${ETHERNET_DEVICE}" up + check_return "eth-up" +fi diff --git a/automated/linux/wlan-download/wlan-download.yaml b/automated/linux/wlan-download/wlan-download.yaml new file mode 100644 index 00000000..5aace2ca --- /dev/null +++ b/automated/linux/wlan-download/wlan-download.yaml @@ -0,0 +1,34 @@ +metadata: + format: Lava-Test Test Definition 1.0 + name: wlan-download + description: "Basic WLAN download test, requires ip, iw, wpa_supplicant and dhclient" + maintainer: + - anibal.limon@linaro.org + os: + - debian + - ubuntu + - centos + - fedora + scope: + - functional + devices: + - dragonboard410c + - dragonboard820c + +params: + DEVICE: wlan0 + ETHERNET_DEVICE: "" + SSID_NAME: "" + SSID_PASSWORD: "" + FILE_URL: "" + FILE_CHECKSUM: "" + TIME_DELAY: "0s" + NAMESERVER: "" + +run: + steps: + - . ./automated/lib/sh-test-lib + - install_deps wpasupplicant iw isc-dhcp-client curl + - cd ./automated/linux/wlan-download + - ./wlan-download-test.sh -d "${DEVICE}" -e "${ETHERNET_DEVICE}" -s "${SSID_NAME}" -p "${SSID_PASSWORD}" -u "${FILE_URL}" -c "${FILE_CHECKSUM}" -t "${TIME_DELAY}" -n "${NAMESERVER}" + - ../../utils/send-to-lava.sh ./output/result.txt -- cgit v1.2.3