Merge lp:~liuyq0307/lava-android-test/connect-lab-wifi into lp:lava-android-test

Proposed by Yongqin Liu
Status: Merged
Merged at revision: 184
Proposed branch: lp:~liuyq0307/lava-android-test/connect-lab-wifi
Merge into: lp:lava-android-test
Diff against target: 315 lines (+275/-1)
5 files modified
MANIFEST.in (+1/-0)
lava_android_test/provider.py (+43/-1)
lava_android_test/test_definitions/hostshells/__init__.py (+2/-0)
lava_android_test/test_definitions/hostshells/connect-lab-wifi.sh (+168/-0)
lava_android_test/test_definitions/hostshells/example.sh (+61/-0)
To merge this branch: bzr merge lp:~liuyq0307/lava-android-test/connect-lab-wifi
Reviewer Review Type Date Requested Status
Michael Hudson-Doyle (community) Approve
Review via email: mp+114115@code.launchpad.net

Description of the change

Add the test to connect the wifi of lava lab.
Want to use the
    /srv/lava/instances/$INSTANCE/etc/lava-server/settings.conf
to set the WIFI_DEV_CONF environment variable,
but it seems not work when run the test via instance job.
the value of WIFI_DEV_CONF can't be gotten.
Don't know why.:(

To post a comment you must log in.
187. By Yongqin Liu

modify the bugs that not get the serial number when using configuration file

Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

It looks OK to me (modulo hardcoding where the config is for now), but I still don't know the codebase all that well.

review: Approve
Revision history for this message
Yongqin Liu (liuyq0307) wrote :

> It looks OK to me (modulo hardcoding where the config is for now), but I still
> don't know the codebase all that well.

Thanks, and there is another branch about the docs, may be from there you can know more about the code.

I will merge this branch first.

Thanks.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'MANIFEST.in'
--- MANIFEST.in 2012-06-28 09:52:29 +0000
+++ MANIFEST.in 2012-07-10 08:27:18 +0000
@@ -12,4 +12,5 @@
12include lava_android_test/test_definitions/ime/*12include lava_android_test/test_definitions/ime/*
13include lava_android_test/test_definitions/pm-qa/*13include lava_android_test/test_definitions/pm-qa/*
14include lava_android_test/test_definitions/shells/*14include lava_android_test/test_definitions/shells/*
15include lava_android_test/test_definitions/hostshells/*
1516
1617
=== modified file 'lava_android_test/provider.py'
--- lava_android_test/provider.py 2012-06-16 05:42:51 +0000
+++ lava_android_test/provider.py 2012-07-10 08:27:18 +0000
@@ -224,7 +224,7 @@
224 'shell chmod 777 %s' % test_sh_android_path]224 'shell chmod 777 %s' % test_sh_android_path]
225225
226 ADB_SHELL_STEPS = ['%s $(OPTIONS)' % test_sh_android_path]226 ADB_SHELL_STEPS = ['%s $(OPTIONS)' % test_sh_android_path]
227 PATTERN = ("^\s*(?P<test_case_id>\w+)="227 PATTERN = ("^\s*(?P<test_case_id>\S+)="
228 "(?P<result>(pass|fail|ok|ng|true|false|skip|done))\s*$")228 "(?P<result>(pass|fail|ok|ng|true|false|skip|done))\s*$")
229229
230 testobj = self.gen_testobj(230 testobj = self.gen_testobj(
@@ -236,3 +236,45 @@
236 parser=testdef.AndroidTestParser(PATTERN),236 parser=testdef.AndroidTestParser(PATTERN),
237 adb=ADB(serial))237 adb=ADB(serial))
238 return testobj238 return testobj
239
240
241class HostShellTestProvider(TestProvider):
242
243 test_prefix = 'hostshell'
244 config = get_config()
245 dotext = '.sh'
246
247 def list_test(self):
248 dotext = '.sh'
249 mod = self.import_mod("lava_android_test.test_definitions.hostshells")
250 sh_files = find_files(mod.curdir, dotext)
251 test_list = []
252 for f in sh_files:
253 ##Assume that the file name only has one '.sh'
254 f_name_no_dotext = os.path.basename(f).replace(dotext, '')
255 test_list.append('%s-%s' % (self.test_prefix, f_name_no_dotext))
256 return test_list
257
258 def load_test(self, test_name=None, serial=None):
259 if not test_name.startswith('%s-' % self.test_prefix):
260 raise UnfoundTest('The test(%s) is not found!' % test_name)
261 f_name_no_prefix = test_name.replace('%s-' % self.test_prefix, '', 1)
262
263 mod = self.import_mod("lava_android_test.test_definitions.%ss" %
264 self.test_prefix)
265 f_name = '%s%s' % (f_name_no_prefix, self.dotext)
266 test_sh_path = '%s/%s' % (mod.curdir, f_name)
267
268 HOST_SHELL_STEPS = ['bash %s -s $(SERIAL) $(OPTIONS)' % test_sh_path]
269 PATTERN = ("^\s*(?P<test_case_id>\S+)="
270 "(?P<result>(pass|fail|ok|ng|true|false|skip|done))\s*$")
271
272 testobj = self.gen_testobj(
273 testname=test_name,
274 installer=testdef.AndroidTestInstaller(),
275 runner=testdef.AndroidTestRunner(
276 steps_host_pre=HOST_SHELL_STEPS),
277 parser=testdef.AndroidTestParser(PATTERN),
278 adb=ADB(serial))
279 return testobj
280
239281
=== added directory 'lava_android_test/test_definitions/hostshells'
=== added file 'lava_android_test/test_definitions/hostshells/__init__.py'
--- lava_android_test/test_definitions/hostshells/__init__.py 1970-01-01 00:00:00 +0000
+++ lava_android_test/test_definitions/hostshells/__init__.py 2012-07-10 08:27:18 +0000
@@ -0,0 +1,2 @@
1import os
2curdir = os.path.dirname(os.path.realpath(__file__))
03
=== added file 'lava_android_test/test_definitions/hostshells/connect-lab-wifi.sh'
--- lava_android_test/test_definitions/hostshells/connect-lab-wifi.sh 1970-01-01 00:00:00 +0000
+++ lava_android_test/test_definitions/hostshells/connect-lab-wifi.sh 2012-07-10 08:27:18 +0000
@@ -0,0 +1,168 @@
1#!/bin/bash
2# Copyright (c) 2012 Linaro
3
4# Author: Linaro Validation Team <linaro-dev@lists.linaro.org>
5#
6# This file is part of LAVA Android Test.
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation, either version 3 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
21function generate_wpa_conf(){
22 conf=$1 && ssid=$2 passwd=$3
23 if [ -z "${conf}" ];then
24 return
25 fi
26
27 if [ -z "${ssid}" ]; then
28 cat >wpa_supplicant.conf <<__EOF__
29ctrl_interface=wlan0
30update_config=1
31device_type=0-00000000-0
32
33__EOF__
34
35 elif [ -z "${passwd}" ]; then
36 cat >wpa_supplicant.conf <<__EOF__
37ctrl_interface=wlan0
38update_config=1
39device_type=0-00000000-0
40
41network={
42 ssid="${ssid}"
43 key_mgmt=NONE
44 priority=2
45}
46
47__EOF__
48
49 else
50 cat >wpa_supplicant.conf <<__EOF__
51ctrl_interface=wlan0
52update_config=1
53device_type=0-00000000-0
54
55network={
56 ssid="${ssid}"
57 psk="${passwd}"
58 key_mgmt=WPA-PSK
59 priority=2
60}
61
62__EOF__
63
64 fi
65}
66
67function enable_wifi(){
68 conf=$1 && ssid=$2 && serial=$3
69 if [ -z "${conf}" ]; then
70 return
71 fi
72 ADB_OPTION=""
73 if [ -n "${serial}" ]; then
74 ADB_OPTION="-s ${serial}"
75 fi
76
77 adb ${ADB_OPTION} shell am start -a android.intent.action.MAIN -n com.android.settings/.Settings
78 sleep 3
79 adb ${ADB_OPTION} shell service call wifi 13 i32 0
80 sleep 5
81 adb ${ADB_OPTION} push "${conf}" /data/misc/wifi/wpa_supplicant.conf
82 adb ${ADB_OPTION} shell chown wifi.wifi /data/misc/wifi/wpa_supplicant.conf
83 adb ${ADB_OPTION} shell chmod 660 /data/misc/wifi/wpa_supplicant.conf
84 adb ${ADB_OPTION} shell ls -l /data/misc/wifi/wpa_supplicant.conf
85 adb ${ADB_OPTION} shell service call wifi 13 i32 1
86 sleep 30
87 for i in {1..30}; do
88 adb ${ADB_OPTION} shell wpa_cli list_networks|grep -E "^\s*[[:digit:]]+\s+${ssid}\s+any\s+\[CURRENT\]"
89 if [ $? -eq 0 ];then
90 break
91 fi
92 sleep 2
93 done
94
95 if [ $i -eq 30 ]; then
96 echo "connect-lava-wifi-${ssid}=fail"
97 return 1
98 else
99 echo "connect-lava-wifi-${ssid}=pass"
100 return 0
101 fi
102}
103
104function parse_argv() {
105 # Parse command line arguments
106 # Sets: VERBOSE, dev
107 while test -n "$1"; do
108 case "$1" in
109 --serial|-s)
110 SERIAL="$2"
111 shift 2
112 ;;
113 --passwd|-p)
114 PASSWD="$2"
115 shift 2
116 ;;
117 *)
118 if [ -n "${SSID}" ]; then
119 show_usage
120 exit 1
121 else
122 SSID="$1"
123 shift
124 fi
125 ;;
126 esac
127 done
128}
129
130function show_usage(){
131 # Display the usage line
132 echo "Usage 1, Specify the ssid and pawword via command line:"
133 echo " $0 [--passwd|-p passwd] [--serial|-s serial] ssid"
134 echo "Usage 2, Specify the ssid and pawword via configuration file:"
135 echo " Specify the file path via 'WIFI_DEV_CONF' environment variable,"
136 echo " /etc/lava/devices/wifi.conf is the default value if not specified"
137 echo " The content of this file like this:"
138 echo " SSID=the ssid of wifi"
139 echo " PASSWD=the password of the specified wifi via SSID"
140}
141
142function main(){
143 if [ -z "${WIFI_DEV_CONF}" ]; then
144 wifi_dev_conf="/etc/lava/devices/wifi.conf"
145 else
146 wifi_dev_conf="${WIFI_DEV_CONF}"
147 fi
148
149 echo "Will use ${wifi_dev_conf} as the configuration file for wifi if exists"
150 if [ -f "${wifi_dev_conf}" ]; then
151 . "${wifi_dev_conf}"
152 fi
153 parse_argv "$@"
154
155 if [ -z "${SSID}" ]; then
156 show_usage
157 exit 1
158 fi
159
160 wifi_conf="wpa_supplicant.conf"
161 generate_wpa_conf "${wifi_conf}" "${SSID}" "${PASSWD}"
162 enable_wifi "${wifi_conf}" "${SSID}" "${SERIAL}"
163 RET=$?
164 rm -f "${wifi_conf}"
165 exit $RET
166}
167
168main "$@"
0169
=== added file 'lava_android_test/test_definitions/hostshells/example.sh'
--- lava_android_test/test_definitions/hostshells/example.sh 1970-01-01 00:00:00 +0000
+++ lava_android_test/test_definitions/hostshells/example.sh 2012-07-10 08:27:18 +0000
@@ -0,0 +1,61 @@
1#!/bin/bash
2# Copyright (c) 2012 Linaro
3
4# Author: Linaro Validation Team <linaro-dev@lists.linaro.org>
5#
6# This file is part of LAVA Android Test.
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation, either version 3 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
21function parse_argv() {
22 # Parse command line arguments
23 while test -n "$1"; do
24 case "$1" in
25 --serial|-s)
26 SERIAL="$2"
27 if [ -n "${SERIAL}" ]; then
28 shift 2
29 else
30 shift 1
31 fi
32 ;;
33 --help|-h)
34 show_usage
35 exit 1
36 ;;
37 *)
38 if [ -n "${OPTIONS}" ]; then
39 OPTIONS="${OPTIONS} $1"
40 else
41 OPTIONS="$1"
42 fi
43 shift
44 ;;
45 esac
46 done
47}
48
49function show_usage(){
50 # Display the usage line
51 echo "Usage $0 [--serial|-s serial] other-option"
52 echo "Usage $0 [--help|-h]"
53}
54
55function main(){
56 parse_argv "$@"
57 echo "hostshells-example-fail=fail"
58 echo "hostshells-example-pass=pass"
59}
60
61main "$@"

Subscribers

People subscribed via source and target branches