Merge lp:~ogra/phablet-tools/phablet-test-run-fix-broken-shell into lp:phablet-tools

Proposed by Oliver Grawert
Status: Merged
Approved by: Ricardo Mendoza
Approved revision: 324
Merged at revision: 323
Proposed branch: lp:~ogra/phablet-tools/phablet-test-run-fix-broken-shell
Merge into: lp:phablet-tools
Diff against target: 125 lines (+37/-15)
1 file modified
phablet-test-run (+37/-15)
To merge this branch: bzr merge lp:~ogra/phablet-tools/phablet-test-run-fix-broken-shell
Reviewer Review Type Date Requested Status
Para Siva (community) Approve
Paul Larson (community) Needs Fixing
PS Jenkins bot continuous-integration Approve
Ubuntu Phablet Team Pending
Review via email: mp+236252@code.launchpad.net

Commit message

phablet-test-run:
Do not force an environment-less shell (to prevent unsetting of DBUS_SESSION_BUS_ADDRESS by using /bin/sh in commands).
Add password/PIN option for using root commands.
Require password or PIN for package installation tasks.

Description of the change

phablet-test-run: do not force an environment-less shell, add password/PIN option for using root commands, require password or PIN for package installation tasks

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
324. By Oliver Grawert

drop backslash

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Paul Larson (pwlars) wrote :

In CI, we need to set up sudo before we get as far as phablet-test-run. So by the time we get here it's already been configured to allow passwordless sudo for the phablet user on the device. Can we not make -r a requirement for us since this is already done?

review: Needs Fixing
Revision history for this message
Oliver Grawert (ogra) wrote :

i thought the test scripts do the package setup in advance anyway so that you do not need the -p option (which means you wont need the -r option either) at least i have never seen -p used for phablet-test-run in the logs.

in a normal lab test run -p should not be needed.

more important for smoke testing is the removal of "/bin/sh -c" from the commands, which in the new world does the right thing and drops the environment to the one of /bin/sh ... which in turn means it also drops all knowledge about dbus and upstart sessions. without thid no app test will run at all.

Revision history for this message
Para Siva (psivaa) wrote :

Tested the messaging_app with this patch on a krillin device and the tests were executed properly and passed. Approving.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'phablet-test-run'
2--- phablet-test-run 2014-09-08 16:30:46 +0000
3+++ phablet-test-run 2014-09-28 16:44:17 +0000
4@@ -33,16 +33,19 @@
5 NOSHELL=0
6 RETVAL=0
7 VERBOSE=""
8+ASKPASS=""
9+SUDO=""
10
11 print_usage() {
12 cat << EOF
13-usage: $0 [-s SERIAL] [-s] [-n] [-x] [-v] [-p PACKAGENAME] [-c PACKAGE] [-o DIR] [-a ARTIFACT] [-f xml|subunit|text] [-A args] testsuite
14+usage: $0 [-s SERIAL] [-s] [-n] [-x] [-v] [-p PACKAGENAME] [ -r PASSWORD/PIN ] [-c PACKAGE] [-o DIR] [-a ARTIFACT] [-f xml|subunit|text] [-A args] testsuite
15
16 Run the specified testsuite on the device
17
18 -s SERIAL Device serial number
19 -p PACKAGENAME Additional package to be installed, may be used multiple
20- times
21+ times (requires -r option)
22+ -r PASSWORD/PIN Device password or PIN for package installation
23 -c PACKAGE Copy and install local package to device, may be used
24 multiple times
25 -n Stop the shell during the test run
26@@ -61,12 +64,30 @@
27 adb wait-for-device
28 }
29
30+set_up_sudo() {
31+ if [ -z "$PW" ]; then
32+ echo "Please use the -r option to provide a device password or PIN"
33+ echo
34+ print_usage
35+ exit 0
36+ fi
37+ ASKPASS="$(adb shell "mktemp -t sudo_askpass.XXXX|tr -d '\n'")"
38+ adb shell "printf '#\x21/bin/sh\necho \"%s\"\n' '${PW}' >$ASKPASS; chmod +x $ASKPASS"
39+ SUDO="SUDO_ASKPASS=$ASKPASS sudo -A"
40+}
41+
42+clean_up_sudo() {
43+ [ -n "$ASKPASS" ] && adb shell "rm -rf $ASKPASS"
44+}
45+
46 exec_with_adb() {
47- adb shell /usr/bin/env -i PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin "$@"
48+ set_up_sudo
49+ adb shell "LC_ALL=C $SUDO /usr/bin/env -i PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin $@"
50+ clean_up_sudo
51 }
52
53 exec_with_adb_user() {
54- adb shell sudo -u $USER -i "$@"
55+ adb shell "LC_ALL=C $@"
56 }
57
58 install_packages() {
59@@ -113,39 +134,37 @@
60
61
62 run_autopilot_test() {
63- exec_with_adb chmod 666 /dev/uinput
64-
65 # This directory doesn't exist in a freshly flashed device, so create it.
66- exec_with_adb mkdir -p /home/phablet/autopilot
67+ exec_with_adb_user mkdir -p /home/phablet/autopilot
68
69 # adb shell always returns 0, so we have to do some hackery to get the
70 # actual RC from the test
71 {
72- apbase="sudo -iu $USER sh -c \"cd /home/phablet/autopilot; autopilot3 run $VERBOSE $APEXTRA"
73+ apbase="cd /home/phablet/autopilot; autopilot3 run $VERBOSE $APEXTRA"
74 if [ "$RESULTDIR" ]; then
75- adb shell "$apbase -o /tmp/test_results.$APFORMAT -f $APFORMAT $TESTSUITE\"; echo ADB_RC=\$?"
76+ adb shell "$apbase -o /tmp/test_results.$APFORMAT -f $APFORMAT $TESTSUITE; echo ADB_RC=\$?"
77 if [ $APFORMAT = "xml" ]; then
78 echo "***** Test summary *****"
79- exec_with_adb head -n 1 /tmp/test_results.$APFORMAT
80+ exec_with_adb_user "head -n 1 /tmp/test_results.$APFORMAT"
81 fi
82 else
83- adb shell "$apbase $TESTSUITE\"; echo ADB_RC=\$?"
84+ adb shell "$apbase $TESTSUITE; echo ADB_RC=\$?"
85 fi
86 } | get_returncode
87 }
88
89 run_cli_command() {
90- apbase="sudo -iu $USER sh -c \"cd /home/phablet; $TESTSUITE"
91+ apbase="cd /home/phablet; $TESTSUITE"
92 # adb shell always returns 0, so we have to do some hackery to get the
93 # actual RC from the test
94 {
95 if [ "$RESULTDIR" ]; then
96 result_output=/tmp/test_results.$APFORMAT
97 adb shell 'rm -rf $result_output'
98- adb shell "$apbase | tee $result_output\"; echo ADB_RC=\$?"
99+ adb shell "$apbase | tee $result_output; echo ADB_RC=\$?"
100 adb pull $result_output $RESULTDIR
101 else
102- adb shell "$apbase\"; echo ADB_RC=\$?"
103+ adb shell "$apbase; echo ADB_RC=\$?"
104 fi
105 } | get_returncode
106
107@@ -166,7 +185,7 @@
108 fi
109 }
110
111-while getopts A:a:c:f:hnxo:p:s:v opt; do
112+while getopts A:a:c:f:hnxo:p:r:s:v opt; do
113 case $opt in
114 A)
115 APEXTRA=$OPTARG
116@@ -193,6 +212,9 @@
117 p)
118 TESTPACKAGES="$TESTPACKAGES $OPTARG"
119 ;;
120+ r)
121+ PW=$OPTARG
122+ ;;
123 s)
124 SERIAL="$OPTARG"
125 ;;

Subscribers

People subscribed via source and target branches