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.
2c9ebd7Michael Terry
run_on_device.sh+43−41
@@ -4,8 +4,8 @@ USER=phablet
4USER_ID=32011
4USER_ID=32011
5PACKAGE=unity8
5PACKAGE=unity8
6BINARY=unity8
6BINARY=unity8
7−TARGET_IP=${TARGET_IP-127.0.0.1}
7+TARGET_IP=127.0.0.1
8−TARGET_SSH_PORT=${TARGET_SSH_PORT-2222}
8+TARGET_SSH_PORT=2222
9TARGET_DEBUG_PORT=3768
9TARGET_DEBUG_PORT=3768
10RUN_OPTIONS=-qmljsdebugger=port:$TARGET_DEBUG_PORT
10RUN_OPTIONS=-qmljsdebugger=port:$TARGET_DEBUG_PORT
11SETUP=false
11SETUP=false
@@ -14,18 +14,23 @@ PINLOCK=false
14KEYLOCK=false
14KEYLOCK=false
15NUM_JOBS='$(( `grep -c ^processor /proc/cpuinfo` + 1 ))'
15NUM_JOBS='$(( `grep -c ^processor /proc/cpuinfo` + 1 ))'
16FLIPPED=false
16FLIPPED=false
17−CHROOT_PREFIX="/data/ubuntu"
18SSH_WAS_STARTED=0
17SSH_WAS_STARTED=0
19SSH_STARTED=0
18SSH_STARTED=0
19+PASSWORD=""
20+PASSFILE=""
20
21
21usage() {
22usage() {
22− echo "usage: run_on_device [OPTIONS]\n"
23+ echo "usage: run_on_device -a SUDO_PASSWORD [OPTIONS]"
24+ echo
23− echo "Script to setup a build environment for the shell and sync build and run it on the device\n"
25+ echo "Script to setup a build environment for the shell and sync build and run it on the device"
26+ echo
24 echo "OPTIONS:"
27 echo "OPTIONS:"
28+ echo " -a, --password The sudo password to use"
25− echo " -s, --setup Setup the build environment"
29+ echo " -s, --setup Setup the build environment"
30+ echo " -g, --gdb Run with gdb"
26− echo " -p, --pinlock Enable a PIN lock screen when running"
31+ echo " -p, --pinlock Enable a PIN lock screen when running"
27− echo " -k, --keylock Enable a Keyboard lock screen when running"
32+ echo " -k, --keylock Enable a Keyboard lock screen when running"
28− echo ""
33+ echo
29 echo "IMPORTANT:"
34 echo "IMPORTANT:"
30 echo " * Make sure to have networking setup on the device beforehand."
35 echo " * Make sure to have networking setup on the device beforehand."
31 echo " * Execute that script from a directory containing unity8 code."
36 echo " * Execute that script from a directory containing unity8 code."
@@ -34,7 +39,7 @@ usage() {
34
39
35start_ssh() {
40start_ssh() {
36 if [ $SSH_STARTED -eq 0 ]; then
41 if [ $SSH_STARTED -eq 0 ]; then
37− exec_with_adb initctl start ssh
42+ adb_sudo initctl start ssh
38 SSH_STARTED=1
43 SSH_STARTED=1
39 fi
44 fi
40}
45}
@@ -44,25 +49,13 @@ exec_with_ssh() {
44 ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -t $USER@$TARGET_IP -p $TARGET_SSH_PORT sudo -u $USER -i bash -ic \"$@\"
49 ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -t $USER@$TARGET_IP -p $TARGET_SSH_PORT sudo -u $USER -i bash -ic \"$@\"
45}
50}
46
51
47−exec_with_adb() {
52+adb_sudo() {
48− if $FLIPPED; then
53+ adb shell "SUDO_ASKPASS=${PASSFILE} sudo --askpass $@"
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
58}
54}
59
55
60install_ssh_key() {
56install_ssh_key() {
61− ssh-keygen -R $TARGET_IP
62− HOME_DIR="${CHROOT_PREFIX}/home/phablet"
57+ HOME_DIR="/home/phablet"
63 adb push ~/.ssh/id_rsa.pub $HOME_DIR/.ssh/authorized_keys
58 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
66 adb shell chmod 700 $HOME_DIR/.ssh
59 adb shell chmod 700 $HOME_DIR/.ssh
67 adb shell chmod 600 $HOME_DIR/.ssh/authorized_keys
60 adb shell chmod 600 $HOME_DIR/.ssh/authorized_keys
68}
61}
@@ -73,8 +66,14 @@ setup_adb_forwarding() {
73}
66}
74
67
75install_dependencies() {
68install_dependencies() {
76− exec_with_adb apt-get update
69+ phablet-config writable-image --remotepassword ${PASSWORD} -p build-essential \
77− exec_with_adb apt-get -y --force-yes install build-essential rsync bzr ccache gdb ninja-build devscripts equivs unity-plugin-scopes
70+ -p rsync \
71+ -p bzr \
72+ -p ccache \
73+ -p gdb \
74+ -p ninja-build \
75+ -p devscripts \
76+ -p equivs
78}
77}
79
78
80sync_code() {
79sync_code() {
@@ -108,12 +107,13 @@ run() {
108 exec_with_ssh "start unity8"
107 exec_with_ssh "start unity8"
109}
108}
110
109
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" "$@"`
112
111
113# FIXME: giving incorrect arguments does not call usage and exit
112# FIXME: giving incorrect arguments does not call usage and exit
114while [ $# -gt 0 ]
113while [ $# -gt 0 ]
115do
114do
116 case "$1" in
115 case "$1" in
116+ -a|--password) PASSWORD=$2;;
117 -s|--setup) SETUP=true;;
117 -s|--setup) SETUP=true;;
118 -g|--gdb) GDB=true;;
118 -g|--gdb) GDB=true;;
119 -p|--pinlock) PINLOCK=true;;
119 -p|--pinlock) PINLOCK=true;;
@@ -124,21 +124,21 @@ do
124 shift
124 shift
125done
125done
126
126
127+if [ -z "${PASSWORD}" ]; then
128+ echo "ERROR: You need to provide a sudo password..."
129+ echo
130+ usage
131+fi
127
132
128−adb_root
133+PASSFILE=$( adb shell "FILE=\`mktemp\`
129−[ "${TARGET_IP}" = "127.0.0.1" ] && setup_adb_forwarding
134+ echo \"#!/bin/sh\" > \$FILE
135+ echo \"echo \\\"${PASSWORD}\\\"\" >> \$FILE
136+ chmod +x \$FILE
137+ echo \$FILE" | tr -d '\r' )
130
138
131−if [ "`adb shell 'grep -q Ubuntu /etc/lsb-release 2> /dev/null && echo -n FLIPPED'`" = "FLIPPED" ]; then
139+setup_adb_forwarding
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
140
140
141−status_output=$(exec_with_adb initctl status ssh)
141+status_output=$(adb_sudo initctl status ssh)
142if [[ $status_output == "ssh start/running, process "* ]]; then
142if [[ $status_output == "ssh start/running, process "* ]]; then
143 SSH_WAS_STARTED=1
143 SSH_WAS_STARTED=1
144fi
144fi
@@ -158,6 +158,8 @@ else
158 run
158 run
159fi
159fi
160
160
161+adb shell "rm ${PASSFILE}"
162+
161if [ $SSH_WAS_STARTED -eq 0 ]; then
163if [ $SSH_WAS_STARTED -eq 0 ]; then
162− exec_with_adb initctl stop ssh
164+ adb_sudo initctl stop ssh
163fi
165fi
tests/autopilot/unity8/application_lifecycle/tests/test_application_lifecycle.py+4−2
@@ -97,7 +97,8 @@ class ApplicationLifecycleTests(tests.ApplicationLifeCycleTestCase):
97 self.assertThat(greeter.created, Eventually(Equals(True)))
97 self.assertThat(greeter.created, Eventually(Equals(True)))
98
98
99 application_name = self.launch_fake_app()
99 application_name = self.launch_fake_app()
100− self.assertThat(greeter.created, Eventually(Equals(False)))
100+ greeter.wait_swiped_away()
101+ process_helpers.unlock_unity()
101 self.assert_current_focused_application(application_name)
102 self.assert_current_focused_application(application_name)
102
103
103 def test_greeter_hides_on_app_focus(self):
104 def test_greeter_hides_on_app_focus(self):
@@ -113,7 +114,8 @@ class ApplicationLifecycleTests(tests.ApplicationLifeCycleTestCase):
113 self.assertThat(greeter.created, Eventually(Equals(True)))
114 self.assertThat(greeter.created, Eventually(Equals(True)))
114
115
115 self.launch_upstart_application(application_name)
116 self.launch_upstart_application(application_name)
116− self.assertThat(greeter.created, Eventually(Equals(False)))
117+ greeter.wait_swiped_away()
118+ process_helpers.unlock_unity()
117 self.assert_current_focused_application(application_name)
119 self.assert_current_focused_application(application_name)
118
120
119 def test_click_dash_icon_must_unfocus_application(self):
121 def test_click_dash_icon_must_unfocus_application(self):
tests/autopilot/unity8/process_helpers.py+12−17
@@ -20,6 +20,7 @@
20import logging
20import logging
21import subprocess
21import subprocess
22import sys
22import sys
23+import dbus
23
24
24# This has to work in both python 3 (ap 1.5) and py2 (ap legacy 1.4.1) so we
25# This has to work in both python 3 (ap 1.5) and py2 (ap legacy 1.4.1) so we
25# pick the correct location in each case. Remove the py2 branch once we no
26# 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):
82 if greeter.created is False:
83 if greeter.created is False:
83 raise RuntimeWarning("Greeter appears to be already unlocked.")
84 raise RuntimeWarning("Greeter appears to be already unlocked.")
84
85
85− # Because of potential input jerkiness under heavy load,
86+ bus = dbus.SessionBus()
86− # retry unlocking the greeter two times.
87+ dbus_proxy = bus.get_object("com.canonical.UnityGreeter", "/")
87− # https://bugs.launchpad.net/ubuntu/+bug/1260113
88−
89− retries = 3
90− while retries > 0:
91− try:
88+ try:
92− greeter.swipe()
89+ dbus_proxy.HideGreeter()
93− except AssertionError:
90+ except dbus.DBusException:
94− retries -= 1
95− if retries == 0:
96− raise
97− logger.info("Failed to unlock greeter, trying again...")
91+ logger.info("Failed to unlock greeter")
92+ raise
98− else:
93+ else:
94+ greeter.created.wait_for(False)
99− logger.info("Greeter unlocked, continuing.")
95+ logger.info("Greeter unlocked, continuing.")
100− break
101
96
102
97
103def lock_unity(unity_proxy_obj=None):
98def lock_unity(unity_proxy_obj=None):
@@ -198,7 +193,7 @@ def get_job_status(name):
198 ], universal_newlines=True)
193 ], universal_newlines=True)
199 except subprocess.CalledProcessError as error:
194 except subprocess.CalledProcessError as error:
200 raise JobError(
195 raise JobError(
201− "Unable to get {}'s status: {}".format(name, error)
196+ "Unable to get {}'s status: {}".format(name, error)
202 )
197 )
203
198
204
199
tests/autopilot/unity8/shell/emulators/greeter.py+4−1
@@ -25,6 +25,9 @@ from unity8.shell.emulators import UnityEmulatorBase
25class Greeter(UnityEmulatorBase):
25class Greeter(UnityEmulatorBase):
26 """An emulator that understands the greeter screen."""
26 """An emulator that understands the greeter screen."""
27
27
28+ def wait_swiped_away(self):
29+ self.showProgress.wait_for(0)
30+
28 def swipe(self):
31 def swipe(self):
29 """Swipe the greeter screen away."""
32 """Swipe the greeter screen away."""
30 self.created.wait_for(True)
33 self.created.wait_for(True)
@@ -37,7 +40,7 @@ class Greeter(UnityEmulatorBase):
37 stop_y = start_y
40 stop_y = start_y
38 self.pointing_device.drag(start_x, start_y, stop_x, stop_y)
41 self.pointing_device.drag(start_x, start_y, stop_x, stop_y)
39
42
40− self.showProgress.wait_for(0)
43+ self.wait_swiped_away()
41
44
42 def get_prompt(self):
45 def get_prompt(self):
43 return self.select_single(
46 return self.select_single(
tests/autopilot/unity8/shell/tests/test_lock_screen.py+8−9
@@ -20,7 +20,6 @@
20
20
21from __future__ import absolute_import
21from __future__ import absolute_import
22
22
23−from unity8.process_helpers import unlock_unity
24from unity8.shell import with_lightdm_mock
23from unity8.shell import with_lightdm_mock
25from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios
24from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios
26
25
@@ -45,11 +44,11 @@ class TestLockscreen(UnityTestCase):
45 @with_lightdm_mock("single-pin")
44 @with_lightdm_mock("single-pin")
46 def test_can_unlock_pin_screen(self):
45 def test_can_unlock_pin_screen(self):
47 """Must be able to unlock the PIN entry lock screen."""
46 """Must be able to unlock the PIN entry lock screen."""
48− unity_proxy = self.launch_unity()
47+ self.launch_unity()
49 greeter = self.main_window.get_greeter()
48 greeter = self.main_window.get_greeter()
50
49
51 if greeter.narrowMode:
50 if greeter.narrowMode:
52− unlock_unity(unity_proxy)
51+ greeter.swipe()
53 lockscreen = self._wait_for_lockscreen()
52 lockscreen = self._wait_for_lockscreen()
54 self.main_window.enter_pin_code("1234")
53 self.main_window.enter_pin_code("1234")
55 self.assertThat(lockscreen.shown, Eventually(Equals(False)))
54 self.assertThat(lockscreen.shown, Eventually(Equals(False)))
@@ -60,11 +59,11 @@ class TestLockscreen(UnityTestCase):
60 @with_lightdm_mock("single-passphrase")
59 @with_lightdm_mock("single-passphrase")
61 def test_can_unlock_passphrase_screen(self):
60 def test_can_unlock_passphrase_screen(self):
62 """Must be able to unlock the passphrase entry screen."""
61 """Must be able to unlock the passphrase entry screen."""
63− unity_proxy = self.launch_unity()
62+ self.launch_unity()
64 greeter = self.main_window.get_greeter()
63 greeter = self.main_window.get_greeter()
65
64
66 if greeter.narrowMode:
65 if greeter.narrowMode:
67− unlock_unity(unity_proxy)
66+ greeter.swipe()
68 lockscreen = self._wait_for_lockscreen()
67 lockscreen = self._wait_for_lockscreen()
69 self._enter_pin_passphrase("password")
68 self._enter_pin_passphrase("password")
70 self.assertThat(lockscreen.shown, Eventually(Equals(False)))
69 self.assertThat(lockscreen.shown, Eventually(Equals(False)))
@@ -75,11 +74,11 @@ class TestLockscreen(UnityTestCase):
75 @with_lightdm_mock("single-pin")
74 @with_lightdm_mock("single-pin")
76 def test_pin_screen_wrong_code(self):
75 def test_pin_screen_wrong_code(self):
77 """Entering the wrong pin code must not dismiss the lock screen."""
76 """Entering the wrong pin code must not dismiss the lock screen."""
78− unity_proxy = self.launch_unity()
77+ self.launch_unity()
79 greeter = self.main_window.get_greeter()
78 greeter = self.main_window.get_greeter()
80
79
81 if greeter.narrowMode:
80 if greeter.narrowMode:
82− unlock_unity(unity_proxy)
81+ greeter.swipe()
83 lockscreen = self._wait_for_lockscreen()
82 lockscreen = self._wait_for_lockscreen()
84 self.main_window.enter_pin_code("4321")
83 self.main_window.enter_pin_code("4321")
85 pinentryField = self.main_window.get_pinentryField()
84 pinentryField = self.main_window.get_pinentryField()
@@ -94,11 +93,11 @@ class TestLockscreen(UnityTestCase):
94 @with_lightdm_mock("single-passphrase")
93 @with_lightdm_mock("single-passphrase")
95 def test_passphrase_screen_wrong_password(self):
94 def test_passphrase_screen_wrong_password(self):
96 """Entering the wrong password must not dismiss the lock screen."""
95 """Entering the wrong password must not dismiss the lock screen."""
97− unity_proxy = self.launch_unity()
96+ self.launch_unity()
98 greeter = self.main_window.get_greeter()
97 greeter = self.main_window.get_greeter()
99
98
100 if greeter.narrowMode:
99 if greeter.narrowMode:
101− unlock_unity(unity_proxy)
100+ greeter.swipe()
102 lockscreen = self._wait_for_lockscreen()
101 lockscreen = self._wait_for_lockscreen()
103 self._enter_pin_passphrase("foobar")
102 self._enter_pin_passphrase("foobar")
104 pinentryField = self.main_window.get_pinentryField()
103 pinentryField = self.main_window.get_pinentryField()
tools/unlock-device+4−5
@@ -19,13 +19,12 @@ done
19
19
20eval "$WAIT_COMMAND"
20eval "$WAIT_COMMAND"
21
21
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
23# to finish coming up (it's hard to tell when the greeter is actually rendered)
23# to finish coming up (it's hard to tell when the greeter is actually rendered)
24−sleep 20
24+sleep 30
25
25
26+# We need to go through sudo to get a proper environment for dbus set up
26−GDBUS_CMD="gdbus call --session --dest com.canonical.UnityGreeter --object-path / --method com.canonical.UnityGreeter.HideGreeter && echo Greeter unlocked"
27+UNLOCK_OUTPUT=$(adb shell "gdbus call --session --dest com.canonical.UnityGreeter --object-path / --method com.canonical.UnityGreeter.HideGreeter && echo Greeter unlocked" 2>&1)
27−
28−UNLOCK_OUTPUT=$(adb shell "if [ \"\$(id -u)\" = 0 ]; then sudo -u phablet -i $GDBUS_CMD; else $GDBUS_CMD; fi" 2>&1)
29if echo "$UNLOCK_OUTPUT" | grep 'Greeter unlocked' >/dev/null; then
28if echo "$UNLOCK_OUTPUT" | grep 'Greeter unlocked' >/dev/null; then
30 echo "I: Unlock passed"
29 echo "I: Unlock passed"
31 exit 0
30 exit 0