~afrantzis/+junk/mir-medium-test-runner-for-jenkins-wip

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/bin/bash
set +ex

date --utc --iso-8601=seconds | xargs echo "[timestamp] Start time :"

if [ -z "$1" ] || [ -z "$2" ]
then
    echo "You have to pass a device serial and packagearchive link"
    echo "$0 04bf2c50e294d599 http://host/path/to/archive.zip"
    exit -1
fi

exec_with_adb() {
    adb -s $ANDROID_SERIAL shell "sudo $@"
}

exec_with_adb_user() {
    adb -s $ANDROID_SERIAL shell "$@"
}

ANDROID_SERIAL=$1
packagearchive=$2
zip_name=`basename $packagearchive`
mir_rc=0
reboot_wait=30
network_wait=60
max_retries=5
results_dir=./results
mir_dir=$results_dir/mir
crash_dir=$results_dir/crash
log_dir=$results_dir/log
benchmark_dir=$results_dir/benchmark_results
benchmark_results=/tmp/glmark2_fullscreen_default.results

HOME_DIR="/home/phablet"
setup_dir="$HOME_DIR/mir-testrunner"

### Device initiation ###
# First reboot
echo "Rebooting the phone will take approximately $reboot_wait seconds to settle"
adb -s $ANDROID_SERIAL reboot
adb -s $ANDROID_SERIAL wait-for-device
sleep $reboot_wait

phablet-config writable-image --remotepassword ubuntuci

echo "SETTING UP SUDO"
adb shell "echo ubuntuci |sudo -S bash -c 'echo phablet ALL=\(ALL\) NOPASSWD: ALL > /etc/sudoers.d/phablet && chmod 600 /etc/sudoers.d/phablet'"

phablet-config welcome-wizard --disable
# FIXME: Can't do this through phablet-config for now because it needs auth
# phablet-config edges-intro --disable
adb shell "sudo dbus-send --system --print-reply --dest=org.freedesktop.Accounts /org/freedesktop/Accounts/User32011 org.freedesktop.DBus.Properties.Set string:com.canonical.unity.AccountsService string:demo-edges variant:boolean:false"

### Cleanup ###
# Cleanup host
rm $zip_name
rm -rf $results_dir
rm -rf package_archive || true
mkdir -p $results_dir
mkdir -p $benchmark_dir
mkdir -p $mir_dir
mkdir -p $crash_dir
mkdir -p $log_dir

# Cleanup target
exec_with_adb "rm -r $setup_dir $HOME_DIR/output"
exec_with_adb "rm /var/crash/*"

date --utc --iso-8601=seconds | xargs echo "[timestamp] Start Setup target :"

### Setup target ###
# Setup scripts
exec_with_adb_user "mkdir -p $setup_dir"
adb -s $ANDROID_SERIAL push mir_install_packages.sh "$setup_dir"

# Setup network
echo "Pausing $network_wait seconds before starting network"
sleep $network_wait
exec_with_adb 'nmcli dev wifi connect ubuntu-qa-g-wpa-d password qalabwireless'

# Collect pre-setup info
adb -s $ANDROID_SERIAL pull /etc/media-info $log_dir

# Setup package archive
wget $packagearchive
unzip $zip_name -d package_archive
if [ -d package_archive/output ]; then
    ARCHIVE_DIR=package_archive/output
    chmod 755 $ARCHIVE_DIR
elif [ -d package_archive/archive/work/output ]; then
    ARCHIVE_DIR=package_archive/archive/work/output
    chmod 755 $ARCHIVE_DIR
else
    echo "E: Cannot find local package archive" >&2
    exit 1
fi
adb -s $ANDROID_SERIAL push $ARCHIVE_DIR $HOME_DIR/archive

date --utc --iso-8601=seconds | xargs echo "[timestamp] Start PPAs and local Archive :"

# Setup the PPAs and local Archive
ppa_repos="ppa_sources"
rm $ppa_repos || true
touch $ppa_repos
for h in $hooks; do
    echo "Processing $h"
    if echo $h | grep D09add_ppa; then
        ppa=`echo $h | sed 's/D09add_ppa~\(.*\)~\(.*\)/ppa:\1\/\2/'`
	echo ${ppa} >> ${ppa_repos}
    fi
done

local_archive="deb $local_archive_source/$local_archive_name $local_archive_pocket/ "
if echo $local_archive | grep "http"; then
    local_archive=`sh -c "echo $local_archive | sed \"s/naartjie/10.98.3.7/\""`
    echo ${local_archive} >> ${ppa_repos}
fi
echo "Host side PPA repo list:"
cat $ppa_repos
adb -s $ANDROID_SERIAL push ${ppa_repos} /tmp/${ppa_repos}

date --utc --iso-8601=seconds | xargs echo "[timestamp] Start Add the test packages :"

# Add the test packages (these are the extra packages specified in the job cfg)
exec_with_adb "apt-get -y --force-yes --no-install-recommends install $test_packages"


exec_with_adb "$setup_dir/mir_install_packages.sh"

### Pre-run ###
# Collect pre-run logs
exec_with_adb "top -n 1 -b | head -20 > /tmp/top-pre.log"
adb -s $ANDROID_SERIAL pull /tmp/top-pre.log $log_dir
exec_with_adb "dpkg -l > /tmp/dpkg-l.log"
adb -s $ANDROID_SERIAL pull /tmp/dpkg-l.log $log_dir

date --utc --iso-8601=seconds | xargs echo "[timestamp] Start Run Tests :"

### Run Tests ###
# Setup to run the tests
rm .setup_complete || true
adb -s $ANDROID_SERIAL pull /.setup_complete
if [[ ! -a .setup_complete ]]; then
    echo "SETUP FAILED - CAN'T CONTINUE"
    mir_rc=1
else
    # Connect to the unrestricted network for running tests
    exec_with_adb 'nmcli dev wifi connect ubuntu-qa-g-wpa-d password qalabwireless'

    # Execute all of the test suites
    echo "I: Ready to run tests"
    echo "Rebooting the phone will take approximately $reboot_wait seconds to settle"
    adb -s $ANDROID_SERIAL reboot
    adb -s $ANDROID_SERIAL wait-for-device
    phablet-network --skip-setup -t 90s
    sleep $reboot_wait
    echo "I: Turning on the display"
    exec_with_adb "powerd-cli display on bright &"

    echo "I: stopping unity8"
    exec_with_adb_user "/sbin/initctl stop unity8"
    echo "I: stopping lightdm"
    exec_with_adb "/sbin/initctl stop lightdm"
    
    adb -s $ANDROID_SERIAL wait-for-device

    set -x 
    for suite in $test_suites; do
        echo running suite $suite
        date --utc --iso-8601=seconds | xargs echo "[timestamp] Start :" $suite
        if grep -q mir_demo_client_ <<< $suite  ; then
            if ! phablet-test-run -x -s $ANDROID_SERIAL $extra -v  mir_demo_server --test-client /usr/bin/$suite ; then
                mir_rc=-1
            fi
        elif grep -q mir_privileged_tests <<< $suite ; then
            if ! phablet-test-run -x -s $ANDROID_SERIAL $extra -v $suite ; then
                mir_rc=-1
            fi
        else
            if ! phablet-test-run -x -s $ANDROID_SERIAL $extra -v umockdev-run -- $suite ; then
                mir_rc=-1
            fi
        fi

        date --utc --iso-8601=seconds | xargs echo "[timestamp] End :" $suite
    done

    adb -s $ANDROID_SERIAL wait-for-device
fi

### Post Run ###
# Collect post-run logs
exec_with_adb "top -n 1 -b | head -20 > /tmp/top-post.log"
adb -s $ANDROID_SERIAL pull /tmp/top-post.log $log_dir
exec_with_adb "dmesg > /tmp/dmesg.log"
adb -s $ANDROID_SERIAL pull /tmp/dmesg.log $log_dir

for suite in $test_suites; do
    adb pull /tmp/$suite-log $mir_dir || true
done

# Collect crash files
echo "I: Gathering crash files (if any)"
adb -s $ANDROID_SERIAL pull /var/crash $crash_dir
ls $crash_dir

# Collect benchmark results
adb -s $ANDROID_SERIAL pull $benchmark_results $benchmark_dir

date --utc --iso-8601=seconds | xargs echo "[timestamp] End time :"

echo "I: Testing complete with returncode $mir_rc"
exit $mir_rc