~vila/ubuntu-test-cases/retry-apt-get-update

« back to all changes in this revision

Viewing changes to scripts/jenkins.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/bash
 
2
 
 
3
## This is the script jenkins should run to execute various touch applications
 
4
 
 
5
set -e
 
6
 
 
7
BASEDIR=$(dirname $(readlink -f $0))/..
 
8
 
 
9
RESDIR="${RESDIR-`pwd`/clientlogs}"
 
10
UTAHFILE=${RESDIR}/utah.yaml
 
11
UTAH_PHABLET_CMD="${UTAH_PHABLET_CMD-/usr/share/utah/examples/run_utah_phablet.py}"
 
12
 
 
13
 
 
14
usage() {
 
15
        cat <<EOF
 
16
usage: $0 -a APP [-s ANDROID_SERIAL] [-p FILE -p FILE ...] [-Q]
 
17
 
 
18
Provisions the given device with the latest build
 
19
 
 
20
OPTIONS:
 
21
  -h    Show this message
 
22
  -s    Specify the serial of the device to install
 
23
  -a    The application under the "tests" directory to test
 
24
  -p    Extra file to pull from target (absolute path or relative to /home/phablet)
 
25
  -Q    "Quick" don't do a reboot of the device before running the test
 
26
 
 
27
EOF
 
28
}
 
29
 
 
30
PIDS=""
 
31
 
 
32
cleanup() {
 
33
        set +e
 
34
        echo "killing child pids: $PIDS"
 
35
        for p in $PIDS ; do
 
36
                kill $p
 
37
        done
 
38
}
 
39
 
 
40
test_from_host() {
 
41
        export PATH=${BASEDIR}/utils/host:${PATH}
 
42
 
 
43
        # allow for certain commands to run from host/target
 
44
        # see unity8-autopilot/ts_control for example
 
45
        export TARGET_PREFIX=adb-shell
 
46
 
 
47
        [ -z $ANDROID_SERIAL ] || ADBOPTS="-s $ANDROID_SERIAL"
 
48
 
 
49
        # If we are not in the utah group, then we don't have permissions
 
50
        # for /var/lib/utah, so run under sudo
 
51
        if ! groups |grep -q utah ; then
 
52
                SUDO="sudo"
 
53
                sudo TARGET_PREFIX="${TARGET_PREFIX}" PATH="${PATH}" \
 
54
                        ${UTAH_PHABLET_CMD} \
 
55
                        ${ADBOPTS} \
 
56
                        --from-host \
 
57
                        --whoopsie \
 
58
                        --results-dir "${RESDIR}" \
 
59
                        --skip-install --skip-network --skip-utah \
 
60
                        --pull /var/crash \
 
61
                        --pull /home/phablet/.cache/upstart \
 
62
                        --pull /tmp/xmlresults \
 
63
                        --pull /var/log/syslog \
 
64
                        --pull /var/log/kern.log \
 
65
                        --pull /var/log/upstart/whoopsie.log \
 
66
                        $EXTRA_PULL \
 
67
                        -l "${TESTSUITE_HOST}/master.run"
 
68
        else
 
69
                TARGET_PREFIX="${TARGET_PREFIX}" PATH="${PATH}" \
 
70
                        ${UTAH_PHABLET_CMD} \
 
71
                        ${ADBOPTS} \
 
72
                        --from-host \
 
73
                        --whoopsie \
 
74
                        --results-dir "${RESDIR}" \
 
75
                        --skip-install --skip-network --skip-utah \
 
76
                        --pull /var/crash \
 
77
                        --pull /home/phablet/.cache/upstart \
 
78
                        --pull /tmp/xmlresults \
 
79
                        --pull /var/log/syslog \
 
80
                        --pull /var/log/kern.log \
 
81
                        --pull /var/log/upstart/whoopsie.log \
 
82
                        $EXTRA_PULL \
 
83
                        -l "${TESTSUITE_HOST}/master.run"
 
84
        fi
 
85
 
 
86
        # make sure the user running this script can remove its artifacts.
 
87
        # only run this if we had to run under sudo
 
88
        if [ "${SUDO}" = "sudo" ] ; then
 
89
                sudo chown -R "${USER}" ${RESDIR}
 
90
        fi
 
91
}
 
92
 
 
93
assert_image() {
 
94
        [ -z $INSTALL_URL ] && return
 
95
        echo "Ensuring target has proper image..."
 
96
        REQUIRED_UUID=$(curl ${INSTALL_URL}/artifact/clientlogs/.ci-uuid)
 
97
        ACTUAL_UUID=$(adb shell "cat /home/phablet/.ci-uuid | tr -d '\r\n'")
 
98
        if [ "$REQUIRED_UUID" != "$ACTUAL_UUID" ] ; then
 
99
                echo "UUIDs $REQUIRED_UUID != $ACTUAL_UUID, reprovisioning device..."
 
100
                ARGS=$(curl ${INSTALL_URL}/artifact/clientlogs/.ci-utah-args | tr -d '\r\n')
 
101
                UUID=$REQUIRED_UUID IMAGE_OPT=$ARGS ${BASEDIR}/scripts/provision.sh
 
102
        else
 
103
                echo "UUIDS match"
 
104
        fi
 
105
}
 
106
 
 
107
main() {
 
108
        rm -rf $RESDIR
 
109
        mkdir $RESDIR
 
110
 
 
111
        assert_image
 
112
 
 
113
        # print the build date so the jenkins job can use it as the
 
114
        # build description
 
115
        adb pull /var/log/installer/media-info ${RESDIR}
 
116
        BUILDID=$(adb shell cat /home/phablet/.ci-version)
 
117
        echo "= TOUCH IMAGE VERSION:$BUILDID"
 
118
 
 
119
        adb shell "top -n1 -b" > ${RESDIR}/top.log
 
120
 
 
121
        set -x
 
122
        adb shell 'sudo rm -f /var/crash/*'
 
123
        if [ -z $QUICK ] ; then
 
124
                # get the phone in sane place
 
125
                adb reboot
 
126
                # sometimes reboot doesn't happen fast enough, so add a little
 
127
                # delay to help ensure its actually rebooted and we didn't just
 
128
                # connect back to the device before it rebooted
 
129
                adb wait-for-device
 
130
                sleep 5
 
131
                adb wait-for-device
 
132
                phablet-network --skip-setup -t 90s
 
133
                adb shell sudo powerd-cli active &
 
134
                PIDS="$PIDS $!"
 
135
                adb shell sudo powerd-cli display on &
 
136
                PIDS="$PIDS $!"
 
137
        else
 
138
                echo "SKIPPING phone reboot..."
 
139
        fi
 
140
 
 
141
        ${BASEDIR}/utils/host/adb-shell "sudo aa-clickhook -f --include=/usr/share/autopilot-touch/apparmor/click.rules"
 
142
 
 
143
        echo "launching test from the host...."
 
144
        test_from_host
 
145
        adb shell 'sudo rm -f /var/crash/*'
 
146
 
 
147
        if ! `grep "^errors: [!0]" < $UTAHFILE >/dev/null` ; then
 
148
                echo "errors found"
 
149
                EXITCODE=1
 
150
        fi
 
151
        if ! `grep "^failures: [!0]" < $UTAHFILE >/dev/null` ; then
 
152
                echo "failures found"
 
153
                EXITCODE=2
 
154
        fi
 
155
        echo "Results Summary"
 
156
        echo "---------------"
 
157
        egrep '^(errors|failures|passes|fetch_errors):' $UTAHFILE
 
158
        exit $EXITCODE
 
159
}
 
160
 
 
161
while getopts p:s:a:Qh opt; do
 
162
    case $opt in
 
163
    h)
 
164
        usage
 
165
        exit 0
 
166
        ;;
 
167
    s)
 
168
        export ANDROID_SERIAL=$OPTARG
 
169
        ;;
 
170
    a)
 
171
        APP=$OPTARG
 
172
        ;;
 
173
        p)
 
174
                EXTRA_PULL_FILE=$OPTARG
 
175
 
 
176
                if [ ! -z $EXTRA_PULL_FILE ]; then
 
177
                        # relative paths are assumed to be relative to /home/phablet
 
178
                        E_P_START=`echo $EXTRA_PULL_FILE | cut -c1`
 
179
 
 
180
                        if [ $E_P_START = '/' ]; then
 
181
                                EXTRA_PULL="$EXTRA_PULL --pull $EXTRA_PULL_FILE"
 
182
                        else
 
183
                                EXTRA_PULL="$EXTRA_PULL --pull /home/phablet/$EXTRA_PULL_FILE"
 
184
                        fi
 
185
                fi
 
186
                ;;
 
187
    Q)
 
188
        QUICK=1
 
189
        ;;
 
190
  esac
 
191
done
 
192
 
 
193
if [ -z $ANDROID_SERIAL ] ; then
 
194
    # ensure we only have one device attached
 
195
    lines=$(adb devices | wc -l)
 
196
    if [ $lines -gt 3 ] ; then
 
197
        echo "ERROR: More than one device attached, please use -s option"
 
198
        echo
 
199
        usage
 
200
        exit 1
 
201
    fi
 
202
fi
 
203
if [ -z $APP ] ; then
 
204
    echo "ERROR: No app specified"
 
205
    usage
 
206
    exit 1
 
207
fi
 
208
 
 
209
TESTSUITE_HOST=$(readlink -f ${BASEDIR}/tests/${APP})
 
210
TESTSUITE_TARGET_BASE=/tmp/tests
 
211
TESTSUITE_TARGET=${TESTSUITE_TARGET_BASE}/$(basename ${TESTSUITE_HOST})
 
212
 
 
213
trap cleanup TERM INT EXIT
 
214
main