Merge lp:~chris.gagnon/phablet-tools/run-test-without-autopilot into lp:phablet-tools

Proposed by Chris Gagnon
Status: Merged
Approved by: Sergio Schvezov
Approved revision: 230
Merged at revision: 225
Proposed branch: lp:~chris.gagnon/phablet-tools/run-test-without-autopilot
Merge into: lp:phablet-tools
Diff against target: 152 lines (+53/-19)
1 file modified
phablet-test-run (+53/-19)
To merge this branch: bzr merge lp:~chris.gagnon/phablet-tools/run-test-without-autopilot
Reviewer Review Type Date Requested Status
Sergio Schvezov Approve
PS Jenkins bot continuous-integration Approve
Francis Ginther Approve
Chris Gagnon (community) Needs Resubmitting
Review via email: mp+194920@code.launchpad.net

Commit message

run non-autopilot tests with phablet-test-run using -x flag

Description of the change

use the -x flag to run tests that are not autopilot tests

example:
phablet-test-run -x -o . mir-integration-tests
phablet-test-run -x -o . run-mir-demo --mir-demo mir_demo_client_egltriangle
phablet-test-run -x -o . ls -la

To post a comment you must log in.
225. By Chris Gagnon

don't use [[ -z use [ -z so sh will work as well as bash

226. By Chris Gagnon

wrap $EXTRA_COMMAND in quotes and use test so it's consistant with ANDROID_SERIAL

Revision history for this message
Francis Ginther (fginther) wrote :

Found some issues with my test case:
"./phablet-test-run -x 'ls > /tmp/ls.log' -o outdir -a /tmp/ls.log"

1) sh style conditional test:
./phablet-test-run: 202: ./phablet-test-run: [[: not found

2) The script still tries to collect the autopilot result file, when '-x' is specified this should be skipped:
remote object '/tmp/test_results.xml' does not exist

3) The usage line (line 30) does not include '-x'.

When 1 is fixed, the test runs as expected and the artifact is copied.

review: Needs Fixing
227. By Chris Gagnon

fix issues 2 and 3 in MP

Revision history for this message
Chris Gagnon (chris.gagnon) wrote :

All issues have been fixed

review: Needs Resubmitting
228. By Chris Gagnon

make it so you don't need to quote the command when using -x

229. By Chris Gagnon

fix accidentally deleted d in line 33

230. By Chris Gagnon

refactor function names so it's easier to read

Revision history for this message
Francis Ginther (fginther) wrote :

This solves the immediate need to run non-autopilot tests. I could argue that it would be better to not touch phablet-test-run and instead put effort into make a python version that is better at supporting both generic and autopilot tests, but I feel that should really be a separate effort.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Sergio Schvezov (sergiusens) :
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 2013-10-24 17:45:53 +0000
3+++ phablet-test-run 2013-11-12 21:29:04 +0000
4@@ -20,6 +20,7 @@
5 RESULTDIR=""
6 ARTIFACTS=""
7
8+EXECUTE_COMMAND=0
9 USER=phablet
10 NOSHELL=0
11 RETVAL=0
12@@ -27,7 +28,7 @@
13
14 print_usage() {
15 cat << EOF
16-usage: $0 [-s SERIAL] [-s] [-n] [-v] [-p PACKAGENAME] [-c PACKAGE] [-o DIR] [-a ARTIFACT] testsuite
17+usage: $0 [-s SERIAL] [-s] [-n] [-x] [-v] [-p PACKAGENAME] [-c PACKAGE] [-o DIR] [-a ARTIFACT] testsuite
18
19 Run the specified testsuite on the device
20
21@@ -37,6 +38,7 @@
22 -n Stop the shell during the test run
23 -o DIR Test report and artifacts output dir
24 -a ARTIFACT Artifact to fetch after the test, may be used multiple times (requires -o)
25+ -x Execute command line, will not use autopilot by default
26 -v Run autopilot with -v option for more verbose output
27 EOF
28 }
29@@ -86,7 +88,21 @@
30 exec_with_adb_user initctl start unity8
31 }
32
33-run_test() {
34+get_returncode() {
35+ while read line; do
36+ set +e
37+ RETVAL=$(echo $line | grep -Po '(?<=ADB_RC=)\d+')
38+ if [ $? -eq 0 ] ; then
39+ set -e
40+ return $RETVAL
41+ fi
42+ echo $line
43+ set -e
44+ done
45+}
46+
47+
48+run_autopilot_test() {
49 exec_with_adb chmod 666 /dev/uinput
50 # adb shell always returns 0, so we have to do some hackery to get the
51 # actual RC from the test
52@@ -99,16 +115,24 @@
53 else
54 adb shell "$apbase $TESTSUITE\"; echo ADB_RC=\$?"
55 fi
56- } | while read line; do
57- set +e
58- RETVAL=$(echo $line | grep -Po '(?<=ADB_RC=)\d+')
59- if [ $? -eq 0 ] ; then
60- set -e
61- return $RETVAL
62+ } | get_returncode
63+}
64+
65+run_cli_command() {
66+ apbase="sudo -iu $USER bash -ic \"cd /home/phablet; $TESTSUITE"
67+ # adb shell always returns 0, so we have to do some hackery to get the
68+ # actual RC from the test
69+ {
70+ if [ "$RESULTDIR" ]; then
71+ result_output=/tmp/test_results.txt
72+ adb shell 'rm -rf $result_output'
73+ adb shell "$apbase | tee $result_output\"; echo ADB_RC=\$?"
74+ adb pull $result_output $RESULTDIR
75+ else
76+ adb shell "$apbase\"; echo ADB_RC=\$?"
77 fi
78- echo $line
79- set -e
80- done
81+ } | get_returncode
82+
83 }
84
85 fetch_artifacts() {
86@@ -116,7 +140,9 @@
87 mkdir -p $RESULTDIR
88 echo "***** Artifacts ($RESULTDIR) *****"
89 set +e
90- adb pull /tmp/test_results.xml $RESULTDIR
91+ if [ $EXECUTE_COMMAND -eq 0 ]; then
92+ adb pull /tmp/test_results.xml $RESULTDIR
93+ fi
94 for artifact in $ARTIFACTS; do
95 adb pull $artifact $RESULTDIR
96 done
97@@ -124,7 +150,7 @@
98 fi
99 }
100
101-while getopts a:c:hno:p:s:v opt; do
102+while getopts a:c:hnxo:p:s:v opt; do
103 case $opt in
104 a)
105 ARTIFACTS="$ARTIFACTS $OPTARG"
106@@ -148,6 +174,9 @@
107 s)
108 ANDROID_SERIAL=$OPTARG
109 ;;
110+ x)
111+ EXECUTE_COMMAND=1
112+ ;;
113 v)
114 VERBOSE="-v"
115 ;;
116@@ -156,7 +185,11 @@
117
118 shift $((OPTIND - 1))
119
120-TESTSUITE=$1
121+TESTSUITE=$@
122+if test -z "$TESTSUITE"; then
123+ echo To run a test please specify a test suite
124+ exit 0
125+fi
126
127 if test -z $ANDROID_SERIAL; then
128 ANDROID_SERIAL=$(adb devices -l | grep usb | cut -f 1 -d " " | head -n1)
129@@ -165,10 +198,6 @@
130
131 adb_root
132
133-if test -z $TESTSUITE; then
134- echo To run a test please specify a test suite
135- exit 0
136-fi
137
138 install_packages
139
140@@ -177,7 +206,12 @@
141 disable_shell
142 fi
143
144-run_test || RETVAL=1
145+if [ $EXECUTE_COMMAND -eq 1 ]; then
146+ echo "running $TESTSUITE"
147+ run_cli_command || RETVAL=1
148+else
149+ run_autopilot_test || RETVAL=1
150+fi
151
152 fetch_artifacts
153

Subscribers

People subscribed via source and target branches