~fginther/ubuntu-test-cases/document-rtm-mp-testing

« back to all changes in this revision

Viewing changes to scripts/run-autopilot-tests.sh

  • Committer: Leo Arias
  • Date: 2014-11-10 19:28:56 UTC
  • mfrom: (345 touch)
  • mto: This revision was merged to the branch mainline in revision 352.
  • Revision ID: leo.arias@canonical.com-20141110192856-rgpksx9n9j0b39yl
Merged with the touch branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
 
 
3
set -e
 
4
 
 
5
BASEDIR=$(dirname $(readlink -f $0))/..
 
6
RESDIR=`pwd`/clientlogs
 
7
 
 
8
export PATH=${BASEDIR}/utils/host:${PATH}
 
9
export TARGET_PREFIX=adb-shell
 
10
 
 
11
 
 
12
usage() {
 
13
        cat <<EOF
 
14
usage: $0 -a APP [-s ANDROID_SERIAL] [-Q] [-o results_dir] [-S]
 
15
 
 
16
Runs a set of autopilot tests on the target
 
17
 
 
18
OPTIONS:
 
19
  -h    Show this message
 
20
  -s    Specify the serial of the device to test
 
21
  -a    The application to test (can be repeated)
 
22
  -o    Specify the directory to place results in.
 
23
        Default: $RESDIR
 
24
  -Q    "Quick" don't do a reboot of the device before/between testsuites.
 
25
  -S    Skip the system-settle tests that run before/after each testsuite.
 
26
 
 
27
EOF
 
28
}
 
29
 
 
30
log_error() {
 
31
        echo ERROR: $* >> ${RESDIR}/runner-errors.txt
 
32
}
 
33
 
 
34
setup_test() {
 
35
        app=$1
 
36
        label=$2
 
37
        odir=$3
 
38
        {
 
39
                pkgs=$(${BASEDIR}/jenkins/testconfig.py packages -a $app)
 
40
                if [ "$label" = "setup" ] ; then
 
41
                        if [ -z "${SKIP_TESTCONFIG}" ]; then
 
42
                                adb-shell sudo apt-get install -yq --force-yes $pkgs
 
43
                        fi
 
44
                else
 
45
                        if [ -z "${SKIP_TESTCONFIG}" ]; then
 
46
                                #Always remove dbus-x11 because it causes
 
47
                                #problems when we leave it around
 
48
                                pkgs="$pkgs dbus-x11"
 
49
                                adb-shell sudo apt-get autoremove --purge -y $pkgs || /bin/true
 
50
                        fi
 
51
                fi
 
52
                echo $? > ${odir}/setup_${label}.rc
 
53
        } 2>&1 | tee ${odir}/setup_${label}.log
 
54
}
 
55
 
 
56
system_settle() {
 
57
        [ -z $NOSETTLE ] || return 0
 
58
 
 
59
        label=$1
 
60
        odir=$2
 
61
        rc=0
 
62
        timeout=120s
 
63
        if [ "$label" = "before" ] ; then
 
64
                timeout=300s
 
65
        fi
 
66
 
 
67
        settle=${BASEDIR}/tests/systemsettle/systemsettle.sh
 
68
        {
 
69
                export UTAH_PROBE_DIR=${odir}  # needed for log file location
 
70
                timeout $timeout $settle -c5 -d6 -p 97.5 -l $label || rc=1
 
71
                echo $rc > ${odir}/settle_${label}.rc
 
72
        } 2>&1 | tee ${odir}/settle_${label}.log
 
73
}
 
74
 
 
75
test_app() {
 
76
        app=$1
 
77
 
 
78
        odir=${RESDIR}/${app}
 
79
        [ -d $odir ] && rm -rf $odir
 
80
        mkdir -p $odir || return 1
 
81
 
 
82
        system_settle before $odir
 
83
        phablet-config autopilot --dbus-probe enable || \
 
84
                (log_error "'autopilot dbus-probe enable' failed"; return 1)
 
85
        adb-shell /home/phablet/bin/check-clickhook-rules || \
 
86
                (log_error "some click profiles missing autopilot rules")
 
87
 
 
88
        setup_test $app setup $odir
 
89
 
 
90
        NOSHELL=""
 
91
        [ "$app" = "unity8" ] && NOSHELL="-n"
 
92
        EXTRA=""
 
93
        # Use --timeout-profile=long only if we are using the emulator
 
94
        [ -z $USE_EMULATOR ] || EXTRA="-A '--timeout-profile=long'"
 
95
 
 
96
        phablet-test-run \
 
97
                $NOSHELL $EXTRA \
 
98
                -o ${odir} -f subunit \
 
99
                -a /var/crash -a /home/phablet/.cache/upstart \
 
100
                -a /var/log/syslog \
 
101
                -A --timeout-profile=long \
 
102
                -v $app || true
 
103
        adb shell rm -rf /tmp/ci-logs
 
104
        adb shell mkdir /tmp/ci-logs
 
105
        adb shell sudo install -o phablet \
 
106
                -m 666 /var/log/upstart/whoopsie.log /tmp/ci-logs
 
107
        adb-shell "sudo system-image-cli --info > /tmp/ci-logs/system-image-cli.log"
 
108
        adb-shell "dpkg -l > /tmp/ci-logs/dpkg-l.log"
 
109
        adb pull /tmp/ci-logs ${odir}
 
110
 
 
111
        system_settle after $odir
 
112
        setup_test $app teardown $odir
 
113
        if [ -f ${odir}/test_results.subunit ] ; then
 
114
                cat ${odir}/test_results.subunit | subunit2junitxml > ${odir}/test_results.xml
 
115
        fi
 
116
        ${BASEDIR}/scripts/combine_results ${odir}
 
117
}
 
118
 
 
119
reboot_wait() {
 
120
        if [ -z $QUICK ] ; then
 
121
                reboot-and-unlock.sh
 
122
                FILES="/var/crash/* /home/phablet/.cache/upstart/*.log*"
 
123
                if ! adb shell "sudo rm -rf $FILES" ; then
 
124
                        log_error "unable to remove crash and log files, retrying"
 
125
                        adb wait-for-device
 
126
                        adb shell "sudo rm -rf $FILES"
 
127
                fi
 
128
        else
 
129
                echo "SKIPPING phone reboot..."
 
130
        fi
 
131
}
 
132
 
 
133
if [ -z $USE_EMULATOR ] ; then
 
134
grab_powerd() {
 
135
        echo "grabbing powerd cli locks..."
 
136
        adb shell sudo powerd-cli active &
 
137
        PIDS="$!"
 
138
        adb shell sudo powerd-cli display on &
 
139
        PIDS="$PIDS $!"
 
140
}
 
141
 
 
142
release_powerd() {
 
143
        if [ -n "$PIDS" ] ; then
 
144
                echo "killing child pids: $PIDS"
 
145
                for p in $PIDS ; do
 
146
                        kill $p || true
 
147
                done
 
148
                PIDS=""
 
149
        fi
 
150
        adb shell sudo pkill powerd-cli
 
151
}
 
152
 
 
153
else
 
154
grab_powerd() {
 
155
        #emulator does not use powerd, so this is noop
 
156
        return 0
 
157
}
 
158
 
 
159
release_powerd() {
 
160
        #emulator does not use powerd, so this is noop
 
161
        return 0
 
162
}
 
163
fi
 
164
 
 
165
dashboard_update() {
 
166
        # only try and update the dashboard if we are configured to
 
167
        [ -z $DASHBOARD_KEY ] && return 0
 
168
        [ -z $DASHBOARD_BUILD ] && return 0
 
169
        [ -z $DASHBOARD_IMAGE ] && return 0
 
170
        ${BASEDIR}/scripts/dashboard.py $* \
 
171
                --image $DASHBOARD_IMAGE \
 
172
                --build $DASHBOARD_BUILD || true
 
173
}
 
174
 
 
175
dashboard_result_running() {
 
176
        dashboard_update result-running --test $1
 
177
}
 
178
 
 
179
dashboard_result_syncing() {
 
180
        xunit=${RESDIR}/${app}/test_results.xml
 
181
        [ -f $xunit ] || return 0
 
182
 
 
183
        # save a utah.yaml version of the results so the dashboard can process
 
184
        cat $xunit | ${BASEDIR}/scripts/junit2utah.py > ${RESDIR}/${app}/utah.yaml
 
185
        dashboard_update result-syncing --test $1 --results ${RESDIR}/${app}/utah.yaml
 
186
}
 
187
 
 
188
main() {
 
189
        [ -d $RESDIR ] || mkdir -p $RESDIR
 
190
 
 
191
        set -x
 
192
 
 
193
        for app in $APPS ; do
 
194
                set +x
 
195
                echo "========================================================"
 
196
                echo "= testing $app"
 
197
                echo "========================================================"
 
198
                set -x
 
199
                dashboard_result_running $app
 
200
                reboot_wait
 
201
 
 
202
                grab_powerd
 
203
 
 
204
                if ! test_app $app ; then
 
205
                        log_error "testing $app, retrying"
 
206
                        # we sometimes see sporatic adb failures that seem to
 
207
                        # related to MTP. This adds a retry for the test.
 
208
                        # test_app only fails on a device error (not a test
 
209
                        # case error)
 
210
                        adb wait-for-device
 
211
                        test_app $app
 
212
                fi
 
213
                dashboard_result_syncing $app
 
214
 
 
215
                release_powerd
 
216
        done
 
217
}
 
218
 
 
219
while getopts s:a:o:QSh opt; do
 
220
        case $opt in
 
221
        h)
 
222
                usage
 
223
                exit 0
 
224
                ;;
 
225
        s)
 
226
                export ANDROID_SERIAL=$OPTARG
 
227
                ;;
 
228
        o)
 
229
                RESDIR=$OPTARG
 
230
                ;;
 
231
        a)
 
232
                APPS="$APPS $OPTARG"
 
233
                ;;
 
234
        Q)
 
235
                QUICK=1
 
236
                ;;
 
237
        S)
 
238
                NOSETTLE=1
 
239
                ;;
 
240
        esac
 
241
done
 
242
 
 
243
if [ -z $ANDROID_SERIAL ] ; then
 
244
        # ensure we only have one device attached
 
245
        lines=$(adb devices | wc -l)
 
246
        if [ $lines -gt 3 ] ; then
 
247
                echo "ERROR: More than one device attached, please use -s option"
 
248
                echo
 
249
                usage
 
250
                exit 1
 
251
        fi
 
252
fi
 
253
if [ -z "$APPS" ] ; then
 
254
        echo "ERROR: No app specified"
 
255
        usage
 
256
        exit 1
 
257
fi
 
258
 
 
259
trap release_powerd TERM INT EXIT
 
260
if [ -n "$USE_EMULATOR" ] ; then
 
261
        echo "disabling system-settle testing for emulator"
 
262
        NOSETTLE=1
 
263
fi
 
264
main