diff options
author | Fathi Boudra <fathi.boudra@linaro.org> | 2013-10-05 10:34:01 +0300 |
---|---|---|
committer | Fathi Boudra <fathi.boudra@linaro.org> | 2013-10-05 10:34:01 +0300 |
commit | ca705e4916a899f669c087f6d793de9db45eaeeb (patch) | |
tree | ee83dcff2f4dc063313f7881aaaafe30b290cad6 /ubuntu/scripts | |
parent | 0b10bbdec64e73b2ff74d703469f6bdd402f5b6b (diff) |
ubuntu: move from bzr to git repositories, clean up descriptions
Signed-off-by: Milosz Wasilewski <milosz.wasilewski@linaro.org>
Signed-off-by: Fathi Boudra <fathi.boudra@linaro.org>
Diffstat (limited to 'ubuntu/scripts')
-rwxr-xr-x | ubuntu/scripts/basic-graphics-test.sh | 170 | ||||
-rwxr-xr-x | ubuntu/scripts/bluetooth-enablement-test.sh | 199 | ||||
-rwxr-xr-x | ubuntu/scripts/device-tree.sh | 72 | ||||
-rw-r--r-- | ubuntu/scripts/include/sh-test-lib | 62 | ||||
-rwxr-xr-x | ubuntu/scripts/run-perf-test.sh | 84 | ||||
-rwxr-xr-x | ubuntu/scripts/wifi-enablement-test.sh | 289 |
6 files changed, 876 insertions, 0 deletions
diff --git a/ubuntu/scripts/basic-graphics-test.sh b/ubuntu/scripts/basic-graphics-test.sh new file mode 100755 index 0000000..ec828c7 --- /dev/null +++ b/ubuntu/scripts/basic-graphics-test.sh @@ -0,0 +1,170 @@ +#!/bin/bash +# +# Basic Graphics test cases +# +# Copyright (C) 2012, 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: Ricardo Salveti <rsalveti@linaro.org> +# + +DEFAULT_USER="linaro" + +source include/sh-test-lib + +set_lightdm_session() { + session=$1 + + # make sure no other config file is bypassing us + rm -f /home/$DEFAULT_USER/.dmrc + rm -rf /var/cache/lightdm + rm -rf /var/lib/AccountsService/users + dbus_user_path=`dbus-send --system --type=method_call --print-reply \ + --dest=org.freedesktop.Accounts /org/freedesktop/Accounts \ + org.freedesktop.Accounts.FindUserByName string:$DEFAULT_USER \ + | awk -F "\"" {'print $2'}` + dbus-send --system --type=method_call --print-reply \ + --dest=org.freedesktop.Accounts ${dbus_user_path} \ + org.freedesktop.Accounts.User.SetXSession string:$session 1>&2 +} + +kill_xorg() { + pid=`pidof /usr/bin/X` + if [ "x$pid" != "x" ]; then + kill -9 $pid 1>&2 + fi + rm -f /tmp/.X0-lock +} + +test_restore() { + kill_xorg + service lightdm stop 1>&2 + sleep 2 + service lightdm start 1>&2 + sleep 10 # give enough time to start +} + +## Test case definitions + +# Validate that Xorg is running +test_xorg() { + TEST="xorg_running" + if ! service lightdm status | grep -q "start\/running"; then + service lightdm start 1>&2 + check_return_fail "lightdm start" && return 1 + sleep 10 # give enough time to start and possibly fail + fi + + pidof "/usr/bin/X" 1>&2 + check_return_fail "Xorg not running" && return 1 + + pass_test +} + +# Validate that the board can run unity-2d +test_unity2d() { + TEST="unity_2d_running" + + service lightdm stop 1>&2 + sleep 2 # to die in peace + set_lightdm_session ubuntu-2d + service lightdm start 1>&2 + check_return_fail "lightdm start" && return 1 + + sleep 120 + pidof "/usr/bin/unity-2d-panel" 1>&2 + check_return_fail "unity-2d-panel not running" && return 1 + pidof "/usr/bin/unity-2d-shell" 1>&2 + check_return_fail "unity-2d-shell not running" && return 1 + + pass_test +} + +# Validate that the board can run unity-3d +test_unity3d() { + TEST="unity_3d_running" + + service lightdm stop 1>&2 + sleep 2 # to die in peace + set_lightdm_session ubuntu + service lightdm start 1>&2 + check_return_fail "lightdm start" && return 1 + + sleep 180 + pidof "/usr/bin/compiz" 1>&2 + check_return_fail "compiz not running" && return 1 + pidof "/usr/bin/gtk-window-decorator" 1>&2 + check_return_fail "gtk-window-decorator not running" && return 1 + pidof "/usr/lib/unity/unity-panel-service" 1>&2 + check_return_fail "unity-panel-service not running" && return 1 + + pass_test +} + +# Validate that the board is able to start unity 3d +test_unity_support() { + TEST="nux_tools_unity_support" + + service lightdm stop 1>&2 + kill_xorg + sleep 2 # to die in peace + (/usr/bin/X -verbose 10 :0 1>&2 &) + export DISPLAY=:0.0 + check_return_fail "Xorg failed to start" && return 1 + + sleep 5 + /usr/lib/nux/unity_support_test 1>&2 + check_return_fail "unity 3d is not supported" && return 1 + + pass_test +} + +# Validate that the board has a valid gles driver +test_opengles_driver() { + TEST="valid_not_mesa_opengles_driver" + + service lightdm stop 1>&2 + kill_xorg + sleep 2 # to die in peace + (/usr/bin/X -verbose 10 :0 1>&2 &) + export DISPLAY=:0.0 + check_return_fail "Xorg failed to start" && return 1 + sleep 5 + + /usr/bin/es2_info 1>&2 + + if /usr/bin/es2_info 2>&1 | grep -q "EGL_VENDOR = Mesa"; then + fail_test "EGL driver provided by Mesa" + return 1 + fi + + pass_test +} + +# check we're root +if ! check_root; then + error_msg "Please run the test case as root" +fi + +# run the tests +test_xorg +test_unity2d +test_unity3d +test_unity_support +test_opengles_driver + +# get lightdm running again for later usage +test_restore diff --git a/ubuntu/scripts/bluetooth-enablement-test.sh b/ubuntu/scripts/bluetooth-enablement-test.sh new file mode 100755 index 0000000..4794c16 --- /dev/null +++ b/ubuntu/scripts/bluetooth-enablement-test.sh @@ -0,0 +1,199 @@ +#!/bin/bash +# +# Bluetooth Enablement test cases +# +# Copyright (C) 2012, 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: Ricardo Salveti <rsalveti@linaro.org> +# +# TODO: Add support for pairing + +SERV_BD_ID="LAVA-Bluetooth01" +SERV_BD_ADDR="00:15:83:15:A3:10" +IFACE="" +IFACE_ADDR="" + +source include/sh-test-lib + +## Test case definitions + +# Has bt adapter +test_has_valid_bt_adapter() { + TEST="has_valid_bt_adapter" + + # show interfaces at stderr, so it can be useful at lava's dashboard + hciconfig 1>&2 + + # for now grab just the first device + TESTIFACE=`hciconfig | head -n 1 | cut -d':' -f1` + [ "x$TESTIFACE" == "x" ] && fail_test "No bluetooth adapter found" && return 1 + + # check if it can put the interface up + hciconfig $TESTIFACE up + check_return_fail "Unable to open and initialize HCI device ($TESTIFACE)" && return 1 + + # set piscan at the bt interface + hciconfig $TESTIFACE piscan + check_return_fail "Unable to enable page and inquire scan ($TESTIFACE)" && return 1 + + # make sure the bt interface has a valid bd address + TESTIFACE_ADDR=`hciconfig $TESTIFACE | grep "BD Address" | awk '{print $3}'` + [ "x$TESTIFACE_ADDR" == "x00:00:00:00:00:00" ] && fail_test "Adapter's mac addr is null" && return 1 + + # set IFACE as a valid bt interface + IFACE=$TESTIFACE + IFACE_ADDR=$TESTIFACE_ADDR + + pass_test +} + +test_bluez_adapter_get_address() { + TEST="bluez_adapter_get_address" + [ "x$IFACE" == "x" ] && fail_test "No valid bluetooth adapter found" && return 1 + + addr=`bluez-test-adapter address` + [ "x$addr" == "x" ] && fail_test "Bluez: failed to get adapter's address" && return 1 + [ "$addr" != "$IFACE_ADDR" ] && fail_test "Bluez: adapter addr != hciconfig addr" && return 1 + + pass_test +} + +test_bluez_adapter_set_name() { + TEST="bluez_adapter_set_name" + [ "x$IFACE" == "x" ] && fail_test "No valid bluetooth adapter found" && return 1 + + # get original name + orig_name=`bluez-test-adapter name` + [ "x$orig_name" == "x" ] && fail_test "Bluez: failed to get adapter's orignal name" && return 1 + + # set to custom name + bluez-test-adapter name linaro-bt-test + check_return_fail "Bluez: unable to set device's name" && return 1 + + # get custom name + custom_name=`bluez-test-adapter name` + [ "x$custom_name" == "x" ] && fail_test "Bluez: failed to get adapter's custom name" && return 1 + [ "$custom_name" != "linaro-bt-test" ] && fail_test "Bluez: adap name != custom one" && return 1 + + # set back to original + bluez-test-adapter name $orig_name + check_return_fail "Bluez: unable to set device original name" && return 1 + + pass_test +} + +test_bluez_adapter_powered_on_off() { + TEST="bluez_adapter_powered_on_off" + [ "x$IFACE" == "x" ] && fail_test "No valid bluetooth adapter found" && return 1 + + # assume powered by default + for i in 1 2 3; do + bluez-test-adapter powered off + check_return_fail "Bluez: failed to set powered off" && return 1 + sleep 2 + bluez-test-adapter powered on + check_return_fail "Bluez: failed to set powered on" && return 1 + sleep 2 + done + + pass_test +} + +test_bluez_adapter_pairable_on_off() { + TEST="bluez_adapter_pairable_on_off" + [ "x$IFACE" == "x" ] && fail_test "No valid bluetooth adapter found" && return 1 + + # assume pairable on by default + for i in 1 2 3; do + bluez-test-adapter pairable off + check_return_fail "Bluez: failed to set pairable off" && return 1 + sleep 2 + bluez-test-adapter pairable on + check_return_fail "Bluez: failed to set pairable on" && return 1 + sleep 2 + done + + pass_test +} + +test_bluez_adapter_discoverable_on_off() { + TEST="bluez_adapter_discoverable_on_off" + [ "x$IFACE" == "x" ] && fail_test "No valid bluetooth adapter found" && return 1 + + # assume discoverable on by default + for i in 1 2 3; do + bluez-test-adapter discoverable off + check_return_fail "Bluez: failed to set discoverable off" && return 1 + sleep 5 + bluez-test-adapter discoverable on + check_return_fail "Bluez: failed to set discoverable on" && return 1 + sleep 5 + done + + pass_test +} + +test_bluez_hci_discovery() { + TEST="bluez_hci_discovery" + [ "x$IFACE" == "x" ] && fail_test "No valid bluetooth adapter found" && return 1 + + bluez-test-discovery 1>&2 + check_return_fail "Bluez: failed to scan for bt devices" && return 1 + hcitool -i $IFACE scan 1>&2 + check_return_fail "Hcitool: failed to scan for bt devices" && return 1 + + pass_test +} + +test_bluez_discovery_find_target_ap() { + TEST="bluez_discovery_find_target_ap" + [ "x$IFACE" == "x" ] && fail_test "No valid bluetooth adapter found" && return 1 + + scan_out=`bluez-test-discovery` + if ! echo $scan_out | grep -q "Name = $SERV_BD_ID"; then + fail_test "Bluez: failed to find target AP ($SERV_BD_ID) when scanning" + return 1 + fi + if ! echo $scan_out | grep -q "[ $SERV_BD_ADDR ]"; then + fail_test "Bluez: failed to find target AP addr ($SERV_BD_ADDR) when scanning" + return 1 + fi + + pass_test +} + +# check we're root +if ! check_root; then + error_msg "Please run the test case as root" +fi + +# test to check if we have an bt adapter +test_has_valid_bt_adapter + +# run the tests + +## using bluez-tests +test_bluez_adapter_get_address +test_bluez_adapter_set_name +test_bluez_adapter_powered_on_off +test_bluez_adapter_pairable_on_off +test_bluez_adapter_discoverable_on_off +test_bluez_hci_discovery +test_bluez_discovery_find_target_ap + +# exit with a good return code, so lava believes it finished OK +exit 0 diff --git a/ubuntu/scripts/device-tree.sh b/ubuntu/scripts/device-tree.sh new file mode 100755 index 0000000..f22ee5a --- /dev/null +++ b/ubuntu/scripts/device-tree.sh @@ -0,0 +1,72 @@ +#!/bin/bash +# +# Device Tree Enablement test cases +# +# Copyright (C) 2012, 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: Ricardo Salveti <rsalveti@linaro.org> +# + +source include/sh-test-lib + +## Test case definitions + +# Check if /proc/device-tree is available +test_has_proc_device_tree() { + TEST="has_proc_device_tree" + + if [ ! -d /proc/device-tree ]; then + fail_test "Unable to find /proc/device-tree" + return 1 + fi + + find /proc/device-tree + + pass_test +} + +# Check if model is not empty +test_device_tree_model_not_empty() { + TEST="device_tree_model_not_empty" + + if [ ! -f /proc/device-tree/model ]; then + fail_test "Unable to find /proc/device-tree/model" + return 1 + fi + + model=`cat /proc/device-tree/model` + if [ -z "$model" ]; then + fail_test "Empty model description at /proc/device-tree/model" + return 1 + fi + + echo "MODEL: $model" 1>&2 + + pass_test +} + +# check we're root +if ! check_root; then + error_msg "Please run the test case as root" +fi + +# run the tests +test_has_proc_device_tree +test_device_tree_model_not_empty + +# clean exit so lava-test can trust the results +exit 0 diff --git a/ubuntu/scripts/include/sh-test-lib b/ubuntu/scripts/include/sh-test-lib new file mode 100644 index 0000000..6c0e8f2 --- /dev/null +++ b/ubuntu/scripts/include/sh-test-lib @@ -0,0 +1,62 @@ +#!/bin/bash +# +# Shared shell library for test management +# +# Copyright (C) 2012, 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: Ricardo Salveti <rsalveti@linaro.org> +# + +function error_msg() { + local msg=$1 + test -z "$msg" && msg="Unknown error" + echo "ERROR: $msg" >&2 + exit 1 +} + +function warn_msg() { + local msg=$1 + test -z "$msg" && msg="Unknown error" + echo "WARNING: $msg\n" >&2 +} + +function check_return_fail() { + if [ $? -ne 0 ]; then + fail_test "$1" + return 0 + else + return 1 + fi +} + +function fail_test() { + local reason=$1 + echo "${TEST}: FAIL - ${reason}" +} + +function pass_test() { + echo "${TEST}: PASS" +} + +function check_root() { + if [ $UID -eq 0 ]; then + return 0 + else + return 1 + fi +} + diff --git a/ubuntu/scripts/run-perf-test.sh b/ubuntu/scripts/run-perf-test.sh new file mode 100755 index 0000000..912dd73 --- /dev/null +++ b/ubuntu/scripts/run-perf-test.sh @@ -0,0 +1,84 @@ +#!/bin/sh +# Copyright (C) 2012, 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: Avik Sil <avik.sil@linaro.org> +# + +set -x + +# Test user id +if [ `whoami` != 'root' ] ; then + echo "You must be the superuser to run this script" >&2 + exit 1 +fi + +# Let's assume that only Ubuntu has apt-get... +if [ -e /usr/bin/apt-get ]; then + # Install most appropriate linux-linaro-tools-* package + KERNELVER=`uname -r | cut -f 1 -d'-'` + PKGNAME=`apt-cache search "linux-linaro-tools-$KERNELVER" | head -1 | cut -f 1 -d' '` + PERFBIN_PREFIX="/usr/bin/perf_" + PERFBIN_VER=`uname -r | awk -F '-' '{print $1"-"$2}'` + if [ ! -e $PERFBIN_PREFIX$PERFBIN_VER ]; then + apt-get install --yes $PKGNAME + PERFBIN=`dpkg -L $PKGNAME | grep perf_` + if [ "$PERFBIN" != "$PERFBIN_PREFIX$PERFBIN_VER" ]; then + ln -s $PERFBIN $PERFBIN_PREFIX$PERFBIN_VER + fi + fi +fi + +# Test 'perf record' +echo "Performing perf record test..." +TCID="perf record test" +perf record -e cycles -o perf-lava-test.data stress -c 4 -t 10 2>&1 | tee perf-record.log +samples=`grep -ao "[0-9]\+[ ]\+samples" perf-record.log| cut -f 1 -d' '` +if [ $samples -gt 1 ]; then + echo "$TCID : PASS" +else + echo "$TCID : FAIL" +fi +rm perf-record.log + +# Test 'perf report' +echo "Performing perf report test..." +TCID="perf report test" +perf report -i perf-lava-test.data 2>&1 | tee perf-report.log +pcnt_samples=`grep -c -e "^[ ]\+[0-9]\+.[0-9]\+%" perf-report.log` +if [ $pcnt_samples -gt 1 ]; then + echo "$TCID : PASS" +else + echo "$TCID : FAIL" +fi +rm perf-report.log perf-lava-test.data + +# Test 'perf stat' +echo "Performing perf stat test..." +TCID="perf stat test" +perf stat -e cycles stress -c 4 -t 10 2>&1 | tee perf-stat.log +cycles=`grep -o "[0-9,]\+[ ]\+cycles" perf-stat.log | sed 's/,//g' | cut -f 1 -d' '` +if [ $cycles -gt 1 ]; then + echo "$TCID : PASS" +else + echo "$TCID : FAIL" +fi +rm perf-stat.log + +# Test 'perf test' +echo "Performing 'perf test'..." +TCID="perf test" +perf test 2>&1 | sed -e 's/FAILED!/FAIL/g' -e 's/Ok/PASS/g' -e "s/[ ]\?[0-9]\+:/$TCID -/g" -e 's/:/ :/g' diff --git a/ubuntu/scripts/wifi-enablement-test.sh b/ubuntu/scripts/wifi-enablement-test.sh new file mode 100755 index 0000000..3c964b1 --- /dev/null +++ b/ubuntu/scripts/wifi-enablement-test.sh @@ -0,0 +1,289 @@ +#!/bin/bash +# +# Wifi Enablement test cases +# +# Copyright (C) 2012, 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: Ricardo Salveti <rsalveti@linaro.org> +# Alexander Sack <asac@linaro.org> +# +# TODO: Improve argument parsing + +# arguments: SSID, PSK, WPA DRIVER +SSID="$1" +PSK="$2" +DRIVER="$3" +IFACE="" +GCTRLIFACE="/var/run/wpasupplicant-global-lava-test" +LCTRLIFACE="/var/run/wpasupplicant-local-lava-test" +PFDHCLIENT="/var/run/dhclient-lava-test.pid" +SAMPLEFILE="http://readyshare.routerlogin.net/shares/USB_Storage/samplemedia.linaro.org/mpeg4/big_buck_bunny_1080p_MPEG4_MP3_25fps_7600K.AVI" + +source include/sh-test-lib + +test_setup() { + service network-manager stop 1>&2 + killall -9 wpa_supplicant 1>&2 + killall -9 dhclient 1>&2 + [ "x$IFACE" != "x" ] && ifconfig $IFACE 0.0.0.0 + rm -f $GCTRLIFACE + rm -f $LCTRLIFACE + rm -f $PFDHCLIENT +} + +test_restore() { + killall -9 wpa_supplicant 1>&2 + killall -9 dhclient 1>&2 + [ "x$IFACE" != "x" ] && ifconfig $IFACE 0.0.0.0 + rm -f $GCTRLIFACE + rm -f $LCTRLIFACE + rm -f $PFDHCLIENT + service network-manager start 1>&2 +} + +## Test case definitions + +# Has wireless device +test_has_wireless_device() { + TEST="has_wireless_device_${SSID}_${DRIVER}" + + iwconfig 1>&2 + + # for now grab just the first interface + IFACE=`iwconfig | grep '^[a-zA-Z]*[0-9]*.*IEEE.*ESS.*$' \ + | head -n1 | sed -e 's/[ ].*$//'` + [ "x$IFACE" == "x" ] && fail_test "No valid wireless interface found" && return 1 + + pass_test +} + +# Able to put interface down +test_able_put_iface_down() { + TEST="able_put_iface_down_${SSID}_${DRIVER}" + [ "x$IFACE" == "x" ] && fail_test "No valid wireless interface found" && return 1 + + ifconfig $IFACE down + check_return_fail "unable to put interface $IFACE down" && return 1 + + pass_test +} + +# Able to put interface up +test_able_put_iface_up() { + TEST="able_put_iface_up_${SSID}_${DRIVER}" + [ "x$IFACE" == "x" ] && fail_test "No valid wireless interface found" && return 1 + + ifconfig $IFACE up + check_return_fail "unable to put interface $IFACE up" && return 1 + + pass_test +} + +# Can scan for APs +test_able_scan_aps() { + TEST="able_scan_aps_${SSID}_${DRIVER}" + [ "x$IFACE" == "x" ] && fail_test "No valid wireless interface found" && return 1 + + # should work for at least 3 times in a row + for i in 1 2 3; do + iwlist $IFACE scan 1>&2 + check_return_fail "failed to scan for aps" && return 1 + sleep 3 + done + + pass_test +} + +# Can find target AP +test_able_scan_find_target_ap() { + TEST="able_scan_find_target_ap_${SSID}_${DRIVER}" + [ "x$IFACE" == "x" ] && fail_test "No valid wireless interface found" && return 1 + + iwlist $IFACE scan | grep -q "ESSID:\"$SSID\"" + check_return_fail "unable to find ESSID '$SSID' while scanning for APs" && return 1 + + pass_test +} + +# Can start wpa supplicant +test_able_start_wpa_supplicant() { + TEST="able_start_wpa_supplicant_${SSID}_${DRIVER}" + + /sbin/wpa_supplicant -dd -B -g $GCTRLIFACE 1>&2 + check_return_fail "fail to start wpa_supplicant" && return 1 + + if [ ! -S $GCTRLIFACE ]; then + fail_test "fail to create wpa supplicant global ctrl_interface" + return 1 + fi + + pass_test +} + +# Can add interface wpa supplicant +test_able_add_iface_wpa_supplicant() { + TEST="able_add_iface_wpa_supplicant_${SSID}_${DRIVER}" + [ "x$IFACE" == "x" ] && fail_test "No valid wireless interface found" && return 1 + + ret=$(/sbin/wpa_cli -g $GCTRLIFACE interface_add $IFACE "" $DRIVER $LCTRLIFACE) + if ! echo ${ret} | egrep -q "OK$"; then + fail_test "fail to add interface $IFACE with wpa_cli" + return 1 + fi + + pass_test +} + +# Can add network wpa supplicant +test_able_add_network_wpa_supplicant() { + TEST="able_add_network_wpa_supplicant_${SSID}_${DRIVER}" + [ "x$IFACE" == "x" ] && fail_test "No valid wireless interface found" && return 1 + + /sbin/wpa_cli -p $LCTRLIFACE -i$IFACE add_network 1>&2 + check_return_fail "fail to add network with wpa_cli" && return 1 + + pass_test +} + +# Can config network wpa supplicant +test_able_set_network_wpa_supplicant() { + TEST="able_set_network_wpa_supplicant_${SSID}_${DRIVER}" + [ "x$IFACE" == "x" ] && fail_test "No valid wireless interface found" && return 1 + + ret=$(/sbin/wpa_cli -p $LCTRLIFACE -i$IFACE set_network 0 ssid \""$SSID"\") + if [ "x$ret" != "xOK" ]; then + fail_test "fail to set the network SSID '$SSID' with wpa_cli" + return 1 + fi + ret=$(/sbin/wpa_cli -p $LCTRLIFACE -i$IFACE set_network 0 psk \""$PSK"\") + if [ "x$ret" != "xOK" ]; then + fail_test "fail to set the network PSK '$SSID' with wpa_cli" + return 1 + fi + + pass_test +} + +# Can enable network wpa supplicant +test_able_enable_network_wpa_supplicant() { + TEST="able_enable_network_wpa_supplicant_${SSID}_${DRIVER}" + [ "x$IFACE" == "x" ] && fail_test "No valid wireless interface found" && return 1 + + ret=$(/sbin/wpa_cli -p $LCTRLIFACE -i$IFACE enable_network 0) + if [ "x$ret" != "xOK" ]; then + fail_test "fail to enable the network with wpa_cli" + return 1 + fi + + pass_test +} + +# Can associate at the AP +test_able_associate_ap_wpa_supplicant() { + TEST="able_associate_ap_wpa_supplicant_${SSID}_${DRIVER}" + [ "x$IFACE" == "x" ] && fail_test "No valid wireless interface found" && return 1 + + i=1 + ret=FAIL + while [ $i -le 20 ]; do + sleep 1 + if /sbin/wpa_cli -p $LCTRLIFACE -i$IFACE status \ + | grep -q "wpa_state=COMPLETED"; then + ret=OK + break + fi + i=$((i+1)) + done + + if [ "x$ret" != "xOK" ]; then + fail_test "fail to associate to AP" + return 1 + fi + + pass_test +} + +# Can grap ip with dhclient +test_able_get_ip_dhclient() { + TEST="able_get_ip_dhclient_${SSID}_${DRIVER}" + [ "x$IFACE" == "x" ] && fail_test "No valid wireless interface found" && return 1 + + /sbin/dhclient -pf $PFDHCLIENT $IFACE 1>&2 + /sbin/ifconfig -a 1>&2 + + if [ ! -f $PFDHCLIENT ]; then + fail_test "fail get a valid ip address from AP" + return 1 + fi + + pass_test +} + +# Can transfer a file and use the network +test_able_transfer_file_network() { + TEST="able_transfer_file_${SSID}_${DRIVER}" + [ "x$IFACE" == "x" ] && fail_test "No valid wireless interface found" && return 1 + + /usr/bin/wget --tries=3 --output-document=/tmp/samplefile ${SAMPLEFILE} 1>&2 + check_return_fail "fail to download $SAMPLEFILE" && return 1 + + pass_test +} + +# Can terminate wpa supplicant ip with dhclient +test_able_terminate_wpa_supplicant() { + TEST="able_terminate_wpa_supplicant_${SSID}_${DRIVER}" + + # take a nap before closing wpa supplicant down + sleep 5 + ret=$(/sbin/wpa_cli -g $GCTRLIFACE terminate) + if ! echo ${ret} | egrep -q "OK$"; then + fail_test "fail to terminate wpa supplicant" + return 1 + fi + + pass_test +} + +# check we're root +if ! check_root; then + error_msg "Please run the test case as root" +fi + +# test to check if we have an interface +test_has_wireless_device + +# setup the environment +test_setup + +# run the tests +test_able_put_iface_down +test_able_put_iface_up +test_able_scan_aps +test_able_scan_find_target_ap +test_able_start_wpa_supplicant +test_able_add_iface_wpa_supplicant +test_able_add_network_wpa_supplicant +test_able_set_network_wpa_supplicant +test_able_enable_network_wpa_supplicant +test_able_associate_ap_wpa_supplicant +test_able_get_ip_dhclient +test_able_transfer_file_network +test_able_terminate_wpa_supplicant + +# get back the environment to previous state +test_restore |