~fginther/ubuntu-test-cases/add-test-suite-timeout

« back to all changes in this revision

Viewing changes to scripts/jenkins.sh

Convert tabs to spaces in scripts/* [r=Thomi Richards, Francis Ginther]

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
 
13
13
 
14
14
usage() {
15
 
        cat <<EOF
 
15
    cat <<EOF
16
16
usage: $0 -a APP [-s ANDROID_SERIAL] [-p FILE -p FILE ...] [-Q]
17
17
 
18
18
Provisions the given device with the latest build
19
19
 
20
20
OPTIONS:
21
 
  -h    Show this message
 
21
  -h    Show this message
22
22
  -s    Specify the serial of the device to install
23
23
  -a    The application under the "tests" directory to test
24
24
  -p    Extra file to pull from target (absolute path or relative to /home/phablet)
30
30
PIDS=""
31
31
 
32
32
cleanup() {
33
 
        set +e
34
 
        echo "killing child pids: $PIDS"
35
 
        for p in $PIDS ; do
36
 
                kill $p
37
 
        done
 
33
    set +e
 
34
    echo "killing child pids: $PIDS"
 
35
    for p in $PIDS ; do
 
36
        kill $p
 
37
    done
38
38
}
39
39
 
40
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
 
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
91
}
92
92
 
93
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
 
                SERVER=$(curl ${INSTALL_URL}/artifact/clientlogs/.ci-flash-server | tr -d '\r\n')
102
 
                UUID=$REQUIRED_UUID IMAGE_SERVER=$SERVER IMAGE_OPT=$ARGS \
103
 
                        ${BASEDIR}/scripts/provision.sh
104
 
        else
105
 
                echo "UUIDS match"
106
 
        fi
 
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
        SERVER=$(curl ${INSTALL_URL}/artifact/clientlogs/.ci-flash-server | tr -d '\r\n')
 
102
        UUID=$REQUIRED_UUID IMAGE_SERVER=$SERVER IMAGE_OPT=$ARGS \
 
103
            ${BASEDIR}/scripts/provision.sh
 
104
    else
 
105
        echo "UUIDS match"
 
106
    fi
107
107
}
108
108
 
109
109
main() {
110
 
        rm -rf $RESDIR
111
 
        mkdir $RESDIR
112
 
 
113
 
        assert_image
114
 
 
115
 
        # print the build date so the jenkins job can use it as the
116
 
        # build description
117
 
        adb pull /var/log/installer/media-info ${RESDIR}
118
 
        BUILDID=$(adb shell cat /home/phablet/.ci-version)
119
 
        echo "= TOUCH IMAGE VERSION:$BUILDID"
120
 
 
121
 
        adb shell "top -n1 -b" > ${RESDIR}/top.log
122
 
 
123
 
        set -x
124
 
        adb shell 'sudo rm -f /var/crash/*'
125
 
        if [ -z $QUICK ] ; then
126
 
                # get the phone in sane place
127
 
                adb reboot
128
 
                # sometimes reboot doesn't happen fast enough, so add a little
129
 
                # delay to help ensure its actually rebooted and we didn't just
130
 
                # connect back to the device before it rebooted
131
 
                adb wait-for-device
132
 
                sleep 5
133
 
                adb wait-for-device
134
 
                phablet-network --skip-setup -t 90s
135
 
                adb shell sudo powerd-cli active &
136
 
                PIDS="$PIDS $!"
137
 
                adb shell sudo powerd-cli display on &
138
 
                PIDS="$PIDS $!"
139
 
        else
140
 
                echo "SKIPPING phone reboot..."
141
 
        fi
142
 
 
143
 
        ${BASEDIR}/utils/host/adb-shell "sudo aa-clickhook -f --include=/usr/share/autopilot-touch/apparmor/click.rules"
144
 
 
145
 
        echo "launching test from the host...."
146
 
        test_from_host
147
 
        adb shell 'sudo rm -f /var/crash/*'
148
 
 
149
 
        if ! `grep "^errors: [!0]" < $UTAHFILE >/dev/null` ; then
150
 
                echo "errors found"
151
 
                EXITCODE=1
152
 
        fi
153
 
        if ! `grep "^failures: [!0]" < $UTAHFILE >/dev/null` ; then
154
 
                echo "failures found"
155
 
                EXITCODE=2
156
 
        fi
157
 
        echo "Results Summary"
158
 
        echo "---------------"
159
 
        egrep '^(errors|failures|passes|fetch_errors):' $UTAHFILE
160
 
        exit $EXITCODE
 
110
    rm -rf $RESDIR
 
111
    mkdir $RESDIR
 
112
 
 
113
    assert_image
 
114
 
 
115
    # print the build date so the jenkins job can use it as the
 
116
    # build description
 
117
    adb pull /var/log/installer/media-info ${RESDIR}
 
118
    BUILDID=$(adb shell cat /home/phablet/.ci-version)
 
119
    echo "= TOUCH IMAGE VERSION:$BUILDID"
 
120
 
 
121
    adb shell "top -n1 -b" > ${RESDIR}/top.log
 
122
 
 
123
    set -x
 
124
    adb shell 'sudo rm -f /var/crash/*'
 
125
    if [ -z $QUICK ] ; then
 
126
        # get the phone in sane place
 
127
        adb reboot
 
128
        # sometimes reboot doesn't happen fast enough, so add a little
 
129
        # delay to help ensure its actually rebooted and we didn't just
 
130
        # connect back to the device before it rebooted
 
131
        adb wait-for-device
 
132
        sleep 5
 
133
        adb wait-for-device
 
134
        phablet-network --skip-setup -t 90s
 
135
        adb shell sudo powerd-cli active &
 
136
        PIDS="$PIDS $!"
 
137
        adb shell sudo powerd-cli display on &
 
138
        PIDS="$PIDS $!"
 
139
    else
 
140
        echo "SKIPPING phone reboot..."
 
141
    fi
 
142
 
 
143
    ${BASEDIR}/utils/host/adb-shell "sudo aa-clickhook -f --include=/usr/share/autopilot-touch/apparmor/click.rules"
 
144
 
 
145
    echo "launching test from the host...."
 
146
    test_from_host
 
147
    adb shell 'sudo rm -f /var/crash/*'
 
148
 
 
149
    if ! `grep "^errors: [!0]" < $UTAHFILE >/dev/null` ; then
 
150
        echo "errors found"
 
151
        EXITCODE=1
 
152
    fi
 
153
    if ! `grep "^failures: [!0]" < $UTAHFILE >/dev/null` ; then
 
154
        echo "failures found"
 
155
        EXITCODE=2
 
156
    fi
 
157
    echo "Results Summary"
 
158
    echo "---------------"
 
159
    egrep '^(errors|failures|passes|fetch_errors):' $UTAHFILE
 
160
    exit $EXITCODE
161
161
}
162
162
 
163
163
while getopts p:s:a:Qh opt; do
172
172
    a)
173
173
        APP=$OPTARG
174
174
        ;;
175
 
        p)
176
 
                EXTRA_PULL_FILE=$OPTARG
177
 
 
178
 
                if [ ! -z $EXTRA_PULL_FILE ]; then
179
 
                        # relative paths are assumed to be relative to /home/phablet
180
 
                        E_P_START=`echo $EXTRA_PULL_FILE | cut -c1`
181
 
 
182
 
                        if [ $E_P_START = '/' ]; then
183
 
                                EXTRA_PULL="$EXTRA_PULL --pull $EXTRA_PULL_FILE"
184
 
                        else
185
 
                                EXTRA_PULL="$EXTRA_PULL --pull /home/phablet/$EXTRA_PULL_FILE"
186
 
                        fi
187
 
                fi
188
 
                ;;
 
175
    p)
 
176
        EXTRA_PULL_FILE=$OPTARG
 
177
 
 
178
        if [ ! -z $EXTRA_PULL_FILE ]; then
 
179
            # relative paths are assumed to be relative to /home/phablet
 
180
            E_P_START=`echo $EXTRA_PULL_FILE | cut -c1`
 
181
 
 
182
            if [ $E_P_START = '/' ]; then
 
183
                EXTRA_PULL="$EXTRA_PULL --pull $EXTRA_PULL_FILE"
 
184
            else
 
185
                EXTRA_PULL="$EXTRA_PULL --pull /home/phablet/$EXTRA_PULL_FILE"
 
186
            fi
 
187
        fi
 
188
        ;;
189
189
    Q)
190
190
        QUICK=1
191
191
        ;;
197
197
    lines=$(adb devices | wc -l)
198
198
    if [ $lines -gt 3 ] ; then
199
199
        echo "ERROR: More than one device attached, please use -s option"
200
 
        echo
 
200
    echo
201
201
        usage
202
202
        exit 1
203
203
    fi