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

Subscribers

People subscribed via source and target branches