on xenial help sign in
Add support to unlock-device for the new adbd coming down the pipeline. Also fix autopilot tests and run scripts for that.

Approved by: Gerry Boland

commit2c9ebd707ca4615870ed041a3dcf75e49ff267b5 authorMichael Terry <michael.terry@canonical.com> dateMon 8 Sep 2014, 14:13 (12 years ago) parent1af115f7d984cc
6 files changed+75−75
run_on_device.sh+43−41 tests/autopilot/unity8/application_lifecycle/tests/test_application_lifecycle.py+4−2 tests/autopilot/unity8/process_helpers.py+12−17 tests/autopilot/unity8/shell/emulators/greeter.py+4−1 tests/autopilot/unity8/shell/tests/test_lock_screen.py+8−9 tools/unlock-device+4−5
run_on_device.sh+43−41
@@ -4,8 +4,8 @@ USER=phablet
44USER_ID=32011
55PACKAGE=unity8
66BINARY=unity8
7−TARGET_IP=${TARGET_IP-127.0.0.1}
8−TARGET_SSH_PORT=${TARGET_SSH_PORT-2222}
7+TARGET_IP=127.0.0.1
8+TARGET_SSH_PORT=2222
99TARGET_DEBUG_PORT=3768
1010RUN_OPTIONS=-qmljsdebugger=port:$TARGET_DEBUG_PORT
1111SETUP=false
@@ -14,18 +14,23 @@ PINLOCK=false
1414KEYLOCK=false
1515NUM_JOBS='$(( `grep -c ^processor /proc/cpuinfo` + 1 ))'
1616FLIPPED=false
17−CHROOT_PREFIX="/data/ubuntu"
1817SSH_WAS_STARTED=0
1918SSH_STARTED=0
19+PASSWORD=""
20+PASSFILE=""
2021
2122usage() {
22− echo "usage: run_on_device [OPTIONS]\n"
23− echo "Script to setup a build environment for the shell and sync build and run it on the device\n"
23+ echo "usage: run_on_device -a SUDO_PASSWORD [OPTIONS]"
24+ echo
25+ echo "Script to setup a build environment for the shell and sync build and run it on the device"
26+ echo
2427 echo "OPTIONS:"
25− echo " -s, --setup Setup the build environment"
26− echo " -p, --pinlock Enable a PIN lock screen when running"
27− echo " -k, --keylock Enable a Keyboard lock screen when running"
28− echo ""
28+ echo " -a, --password The sudo password to use"
29+ echo " -s, --setup Setup the build environment"
30+ echo " -g, --gdb Run with gdb"
31+ echo " -p, --pinlock Enable a PIN lock screen when running"
32+ echo " -k, --keylock Enable a Keyboard lock screen when running"
33+ echo
2934 echo "IMPORTANT:"
3035 echo " * Make sure to have networking setup on the device beforehand."
3136 echo " * Execute that script from a directory containing unity8 code."
@@ -34,7 +39,7 @@ usage() {
3439
3540start_ssh() {
3641 if [ $SSH_STARTED -eq 0 ]; then
37− exec_with_adb initctl start ssh
42+ adb_sudo initctl start ssh
3843 SSH_STARTED=1
3944 fi
4045}
@@ -44,25 +49,13 @@ exec_with_ssh() {
4449 ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -t $USER@$TARGET_IP -p $TARGET_SSH_PORT sudo -u $USER -i bash -ic \"$@\"
4550}
4651
47−exec_with_adb() {
48− if $FLIPPED; then
49− adb shell $@
50− else
51− adb shell chroot /data/ubuntu /usr/bin/env -i PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin "$@"
52− fi
53−}
54−
55−adb_root() {
56− adb root
57− adb wait-for-device
52+adb_sudo() {
53+ adb shell "SUDO_ASKPASS=${PASSFILE} sudo --askpass $@"
5854}
5955
6056install_ssh_key() {
61− ssh-keygen -R $TARGET_IP
62− HOME_DIR="${CHROOT_PREFIX}/home/phablet"
57+ HOME_DIR="/home/phablet"
6358 adb push ~/.ssh/id_rsa.pub $HOME_DIR/.ssh/authorized_keys
64− adb shell chown $USER_ID:$USER_ID $HOME_DIR/.ssh
65− adb shell chown $USER_ID:$USER_ID $HOME_DIR/.ssh/authorized_keys
6659 adb shell chmod 700 $HOME_DIR/.ssh
6760 adb shell chmod 600 $HOME_DIR/.ssh/authorized_keys
6861}
@@ -73,8 +66,14 @@ setup_adb_forwarding() {
7366}
7467
7568install_dependencies() {
76− exec_with_adb apt-get update
77− exec_with_adb apt-get -y --force-yes install build-essential rsync bzr ccache gdb ninja-build devscripts equivs unity-plugin-scopes
69+ phablet-config writable-image --remotepassword ${PASSWORD} -p build-essential \
70+ -p rsync \
71+ -p bzr \
72+ -p ccache \
73+ -p gdb \
74+ -p ninja-build \
75+ -p devscripts \
76+ -p equivs
7877}
7978
8079sync_code() {
@@ -108,12 +107,13 @@ run() {
108107 exec_with_ssh "start unity8"
109108}
110109
111−set -- `getopt -n$0 -u -a --longoptions="setup,gdb,pinlock,keylock,help" "sgpkh" "$@"`
110+set -- `getopt -n$0 -u -a --longoptions="password:,setup,gdb,pinlock,keylock,help" "a:sgpkh" "$@"`
112111
113112# FIXME: giving incorrect arguments does not call usage and exit
114113while [ $# -gt 0 ]
115114do
116115 case "$1" in
116+ -a|--password) PASSWORD=$2;;
117117 -s|--setup) SETUP=true;;
118118 -g|--gdb) GDB=true;;
119119 -p|--pinlock) PINLOCK=true;;
@@ -124,21 +124,21 @@ do
124124 shift
125125done
126126
127+if [ -z "${PASSWORD}" ]; then
128+ echo "ERROR: You need to provide a sudo password..."
129+ echo
130+ usage
131+fi
127132
128−adb_root
129−[ "${TARGET_IP}" = "127.0.0.1" ] && setup_adb_forwarding
133+PASSFILE=$( adb shell "FILE=\`mktemp\`
134+ echo \"#!/bin/sh\" > \$FILE
135+ echo \"echo \\\"${PASSWORD}\\\"\" >> \$FILE
136+ chmod +x \$FILE
137+ echo \$FILE" | tr -d '\r' )
130138
131−if [ "`adb shell 'grep -q Ubuntu /etc/lsb-release 2> /dev/null && echo -n FLIPPED'`" = "FLIPPED" ]; then
132− FLIPPED=true
133− CHROOT_PREFIX=""
134− if [ "${TARGET_IP}" != "127.0.0.1" ]; then
135− echo "ERROR: Flipped image detected, adb over TCP/IP isn't supported, yet :/"
136− echo "Unset TARGET_IP and try again."
137− exit 2
138− fi
139−fi
139+setup_adb_forwarding
140140
141−status_output=$(exec_with_adb initctl status ssh)
141+status_output=$(adb_sudo initctl status ssh)
142142if [[ $status_output == "ssh start/running, process "* ]]; then
143143 SSH_WAS_STARTED=1
144144fi
@@ -158,6 +158,8 @@ else
158158 run
159159fi
160160
161+adb shell "rm ${PASSFILE}"
162+
161163if [ $SSH_WAS_STARTED -eq 0 ]; then
162− exec_with_adb initctl stop ssh
164+ adb_sudo initctl stop ssh
163165fi
tests/autopilot/unity8/application_lifecycle/tests/test_application_lifecycle.py+4−2
@@ -97,7 +97,8 @@ class ApplicationLifecycleTests(tests.ApplicationLifeCycleTestCase):
9797 self.assertThat(greeter.created, Eventually(Equals(True)))
9898
9999 application_name = self.launch_fake_app()
100− self.assertThat(greeter.created, Eventually(Equals(False)))
100+ greeter.wait_swiped_away()
101+ process_helpers.unlock_unity()
101102 self.assert_current_focused_application(application_name)
102103
103104 def test_greeter_hides_on_app_focus(self):
@@ -113,7 +114,8 @@ class ApplicationLifecycleTests(tests.ApplicationLifeCycleTestCase):
113114 self.assertThat(greeter.created, Eventually(Equals(True)))
114115
115116 self.launch_upstart_application(application_name)
116− self.assertThat(greeter.created, Eventually(Equals(False)))
117+ greeter.wait_swiped_away()
118+ process_helpers.unlock_unity()
117119 self.assert_current_focused_application(application_name)
118120
119121 def test_click_dash_icon_must_unfocus_application(self):
tests/autopilot/unity8/process_helpers.py+12−17
@@ -20,6 +20,7 @@
2020import logging
2121import subprocess
2222import sys
23+import dbus
2324
2425# This has to work in both python 3 (ap 1.5) and py2 (ap legacy 1.4.1) so we
2526# pick the correct location in each case. Remove the py2 branch once we no
@@ -82,22 +83,16 @@ def unlock_unity(unity_proxy_obj=None):
8283 if greeter.created is False:
8384 raise RuntimeWarning("Greeter appears to be already unlocked.")
8485
85− # Because of potential input jerkiness under heavy load,
86− # retry unlocking the greeter two times.
87− # https://bugs.launchpad.net/ubuntu/+bug/1260113
88−
89− retries = 3
90− while retries > 0:
91− try:
92− greeter.swipe()
93− except AssertionError:
94− retries -= 1
95− if retries == 0:
96− raise
97− logger.info("Failed to unlock greeter, trying again...")
98− else:
99− logger.info("Greeter unlocked, continuing.")
100− break
86+ bus = dbus.SessionBus()
87+ dbus_proxy = bus.get_object("com.canonical.UnityGreeter", "/")
88+ try:
89+ dbus_proxy.HideGreeter()
90+ except dbus.DBusException:
91+ logger.info("Failed to unlock greeter")
92+ raise
93+ else:
94+ greeter.created.wait_for(False)
95+ logger.info("Greeter unlocked, continuing.")
10196
10297
10398def lock_unity(unity_proxy_obj=None):
@@ -198,7 +193,7 @@ def get_job_status(name):
198193 ], universal_newlines=True)
199194 except subprocess.CalledProcessError as error:
200195 raise JobError(
201− "Unable to get {}'s status: {}".format(name, error)
196+ "Unable to get {}'s status: {}".format(name, error)
202197 )
203198
204199
tests/autopilot/unity8/shell/emulators/greeter.py+4−1
@@ -25,6 +25,9 @@ from unity8.shell.emulators import UnityEmulatorBase
2525class Greeter(UnityEmulatorBase):
2626 """An emulator that understands the greeter screen."""
2727
28+ def wait_swiped_away(self):
29+ self.showProgress.wait_for(0)
30+
2831 def swipe(self):
2932 """Swipe the greeter screen away."""
3033 self.created.wait_for(True)
@@ -37,7 +40,7 @@ class Greeter(UnityEmulatorBase):
3740 stop_y = start_y
3841 self.pointing_device.drag(start_x, start_y, stop_x, stop_y)
3942
40− self.showProgress.wait_for(0)
43+ self.wait_swiped_away()
4144
4245 def get_prompt(self):
4346 return self.select_single(
tests/autopilot/unity8/shell/tests/test_lock_screen.py+8−9
@@ -20,7 +20,6 @@
2020
2121from __future__ import absolute_import
2222
23−from unity8.process_helpers import unlock_unity
2423from unity8.shell import with_lightdm_mock
2524from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios
2625
@@ -45,11 +44,11 @@ class TestLockscreen(UnityTestCase):
4544 @with_lightdm_mock("single-pin")
4645 def test_can_unlock_pin_screen(self):
4746 """Must be able to unlock the PIN entry lock screen."""
48− unity_proxy = self.launch_unity()
47+ self.launch_unity()
4948 greeter = self.main_window.get_greeter()
5049
5150 if greeter.narrowMode:
52− unlock_unity(unity_proxy)
51+ greeter.swipe()
5352 lockscreen = self._wait_for_lockscreen()
5453 self.main_window.enter_pin_code("1234")
5554 self.assertThat(lockscreen.shown, Eventually(Equals(False)))
@@ -60,11 +59,11 @@ class TestLockscreen(UnityTestCase):
6059 @with_lightdm_mock("single-passphrase")
6160 def test_can_unlock_passphrase_screen(self):
6261 """Must be able to unlock the passphrase entry screen."""
63− unity_proxy = self.launch_unity()
62+ self.launch_unity()
6463 greeter = self.main_window.get_greeter()
6564
6665 if greeter.narrowMode:
67− unlock_unity(unity_proxy)
66+ greeter.swipe()
6867 lockscreen = self._wait_for_lockscreen()
6968 self._enter_pin_passphrase("password")
7069 self.assertThat(lockscreen.shown, Eventually(Equals(False)))
@@ -75,11 +74,11 @@ class TestLockscreen(UnityTestCase):
7574 @with_lightdm_mock("single-pin")
7675 def test_pin_screen_wrong_code(self):
7776 """Entering the wrong pin code must not dismiss the lock screen."""
78− unity_proxy = self.launch_unity()
77+ self.launch_unity()
7978 greeter = self.main_window.get_greeter()
8079
8180 if greeter.narrowMode:
82− unlock_unity(unity_proxy)
81+ greeter.swipe()
8382 lockscreen = self._wait_for_lockscreen()
8483 self.main_window.enter_pin_code("4321")
8584 pinentryField = self.main_window.get_pinentryField()
@@ -94,11 +93,11 @@ class TestLockscreen(UnityTestCase):
9493 @with_lightdm_mock("single-passphrase")
9594 def test_passphrase_screen_wrong_password(self):
9695 """Entering the wrong password must not dismiss the lock screen."""
97− unity_proxy = self.launch_unity()
96+ self.launch_unity()
9897 greeter = self.main_window.get_greeter()
9998
10099 if greeter.narrowMode:
101− unlock_unity(unity_proxy)
100+ greeter.swipe()
102101 lockscreen = self._wait_for_lockscreen()
103102 self._enter_pin_passphrase("foobar")
104103 pinentryField = self.main_window.get_pinentryField()
tools/unlock-device+4−5
@@ -19,13 +19,12 @@ done
1919
2020eval "$WAIT_COMMAND"
2121
22−# Force a sleep of twenty no matter what, since we may need to wait for unity8
22+# Force a sleep no matter what, since we may need to wait for unity8
2323# to finish coming up (it's hard to tell when the greeter is actually rendered)
24−sleep 20
24+sleep 30
2525
26−GDBUS_CMD="gdbus call --session --dest com.canonical.UnityGreeter --object-path / --method com.canonical.UnityGreeter.HideGreeter && echo Greeter unlocked"
27−
28−UNLOCK_OUTPUT=$(adb shell "if [ \"\$(id -u)\" = 0 ]; then sudo -u phablet -i $GDBUS_CMD; else $GDBUS_CMD; fi" 2>&1)
26+# We need to go through sudo to get a proper environment for dbus set up
27+UNLOCK_OUTPUT=$(adb shell "gdbus call --session --dest com.canonical.UnityGreeter --object-path / --method com.canonical.UnityGreeter.HideGreeter && echo Greeter unlocked" 2>&1)
2928if echo "$UNLOCK_OUTPUT" | grep 'Greeter unlocked' >/dev/null; then
3029 echo "I: Unlock passed"
3130 exit 0