summaryrefslogtreecommitdiff
path: root/ubuntu/scripts/usb-test-basic.sh
blob: fa30d6cf8020a348aa73b4de71625c6d25ae998d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/sh
#
# USB test cases for Linux Linaro ubuntu
#
# Copyright (C) 2012 - 2014, 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: Chase Qi <chase.qi@linaro.org>
#

# generate test result with lava-test-case
test_result(){
if [ $? -eq 0 ]; then
    lava-test-case $1 --result pass
else
    lava-test-case $1 --result fail
fi
}

# get the usb devices/hubs list
echo "========"
lsusb
test_result list-all-usb-devices

# examine all usb devices/hubs
if [ -d /dev/bus/usb/ ]; then
    for bus in `ls /dev/bus/usb/`; do
        for device in `ls /dev/bus/usb/$bus/`; do
            echo "========"
            echo "Bus $bus, device $device"
            lsusb -D /dev/bus/usb/$bus/$device
            status=$?

            if [ $status -ne 0 ]; then
                echo "Bus$bus-Device$device examination failed"
                break 2
            fi

        done
    done

    if [ $status -eq 0 ]; then
        lava-test-case examine-all-usb-devices --result pass
    else
        lava-test-case examine-all-usb-devices --result fail
    fi

else
    echo "/dev/bus/usb/ not exists"
    lava-test-case examine-all-usb-devices --result fail
fi

# print supported usb protocols
echo "========"
if [ -z "`lsusb -v | grep -i bcdusb`" ]; then
    lava-test-case print-supported-protocols --result fail
else
    lsusb -v | grep -i bcdusb | sort | uniq
    test_result print-supported-protocols
fi

# print supported speeds
echo "========"
if [ -z "`lsusb -t`" ]; then
    lava-test-case print-supported-speeds --result fail
else
    lsusb -t
    test_result print-supported-speeds
fi
# clean exit so lava-test can trust the results
exit 0