| 1 |
#!/bin/bash |
| 2 |
# Copyright 2014 Canonical Ltd. |
| 3 |
# |
| 4 |
# This program is free software; you can redistribute it and/or modify |
| 5 |
# it under the terms of the GNU Lesser General Public License as published by |
| 6 |
# the Free Software Foundation; version 2.1. |
| 7 |
# |
| 8 |
# This program is distributed in the hope that it will be useful, |
| 9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the |
| 11 |
# GNU Lesser General Public License for more details. |
| 12 |
# |
| 13 |
# You should have received a copy of the GNU Lesser General Public License |
| 14 |
# along with this program.If not, see <http://www.gnu.org/licenses/>. |
| 15 |
# |
| 16 |
# Author: Zoltán Balogh <[email protected]> |
| 17 |
|
| 18 |
SERIALNUMBER=086e443edf51b915 |
| 19 |
SILO="025" |
| 20 |
TEST_SILO=false |
| 21 |
DISTRO="ubuntu" |
| 22 |
SERIES="vivid" |
| 23 |
CHANNEL="ubuntu-touch/rc-proposed/${DISTRO}" |
| 24 |
PASSWORD="0000" |
| 25 |
BOOTTIME=300 |
| 26 |
COMISSION=false |
| 27 |
COUNT=10 |
| 28 |
SLEEP_TIME=10 |
| 29 |
FILTER=.* |
| 30 |
LTTNG_SESSION_NAME_REGEXP='(auto-.*-.*) created.' |
| 31 |
LTTNG_SESSION_NAME="" |
| 32 |
REMOTE_LTTNG_SESSION=true |
| 33 |
VERBOSE=false |
| 34 |
CLEAR_CACHE="" |
| 35 |
VERBOSE_PARAMETER="" |
| 36 |
WIRELESS_ADAPTER="$(nmcli -t -f device,type dev | egrep "wireless|wifi" | cut -d: -f1)" |
| 37 |
IP_ADDRESS="$(ifconfig | grep -A 1 ${WIRELESS_ADAPTER} | tail -1 | cut -d ':' -f 2 | cut -d ' ' -f 1)" |
| 38 |
|
| 39 |
declare -a APPLICATIONS=( |
| 40 |
"dialer-app" |
| 41 |
"messaging-app" |
| 42 |
"lomiri-system-settings" |
| 43 |
) |
| 44 |
|
| 45 |
function echo(){ |
| 46 |
if [[ $VERBOSE == true ]]; then |
| 47 |
builtin echo $@; |
| 48 |
fi |
| 49 |
} |
| 50 |
|
| 51 |
sleep_indicator () { |
| 52 |
if [ -z "$1" ]; then |
| 53 |
i=1 |
| 54 |
while [$(adb get-state-s ${SERIALNUMBER}) == "unknown" ] |
| 55 |
do |
| 56 |
echo -ne "Wait for adb: $i seconds\r" |
| 57 |
sleep 1 |
| 58 |
i=$[$i+1] |
| 59 |
done |
| 60 |
echo -ne '\n' |
| 61 |
until pids=$(adb -s ${SERIALNUMBER} shell pidof lomiri-system-compositor|egrep -v "^$|initctl:"); |
| 62 |
do |
| 63 |
echo -ne "Wait for compositor: $i seconds\r" |
| 64 |
sleep 1; |
| 65 |
i=$[$i+1] |
| 66 |
done; |
| 67 |
echo -ne '\n' |
| 68 |
return |
| 69 |
fi |
| 70 |
SLEEP=$1 |
| 71 |
if [[ $SLEEP == 120 ]]; then |
| 72 |
echo "Remember that the phone may ask for SIM pin code" |
| 73 |
fi |
| 74 |
for (( LOOPVAR=1; LOOPVAR<= ${SLEEP}; LOOPVAR++ )) |
| 75 |
do |
| 76 |
echo -ne "Wait: $SLEEP/$LOOPVAR seconds\r" |
| 77 |
sleep 1 |
| 78 |
done |
| 79 |
echo -ne '\n' |
| 80 |
return 0 |
| 81 |
} |
| 82 |
|
| 83 |
function wait_for_shell { |
| 84 |
# Waiting for device on ADB |
| 85 |
set -e |
| 86 |
adb -s ${SERIALNUMBER} wait-for-device |
| 87 |
# Start waiting for Lomiri" |
| 88 |
until PIDS=$(adb -s ${SERIALNUMBER} shell pidof lomiri 2>/dev/null|egrep -v "^$"); |
| 89 |
do |
| 90 |
sleep 0.1; |
| 91 |
done; |
| 92 |
echo "Lomiri is up with PID: ${PIDS}" |
| 93 |
set +e |
| 94 |
} |
| 95 |
|
| 96 |
function unlock_screen { |
| 97 |
adb -s ${SERIALNUMBER} shell powerd-cli display on |egrep -v "Display State requested, cookie is|Press ctrl-c to exit|not fully supported." & |
| 98 |
adb -s ${SERIALNUMBER} shell powerd-cli active |egrep -v "requested, cookie is|Press ctrl-c to exit|not fully supported." & |
| 99 |
#sleep_indicator 10 |
| 100 |
adb -s ${SERIALNUMBER} shell "gdbus call --session --dest com.lomiri.LomiriGreeter --object-path / --method com.lomiri.LomiriGreeter.HideGreeter|grep -v '\(\)'" |
| 101 |
adb -s ${SERIALNUMBER} shell "echo ${PASSWORD}|sudo -S dbus-send --system --print-reply \ |
| 102 |
--dest=org.freedesktop.Accounts \ |
| 103 |
/org/freedesktop/Accounts/User32011 \ |
| 104 |
org.freedesktop.DBus.Properties.Set \ |
| 105 |
string:com.lomiri.lomiri.AccountsService \ |
| 106 |
string:demo-edges variant:boolean:false 2>&1|grep -v password|egrep -v '\(\)|method return'" |
| 107 |
} |
| 108 |
|
| 109 |
function reset { |
| 110 |
adb -s ${SERIALNUMBER} shell "echo ${PASSWORD}|sudo -S reboot 2>&1|grep -v password" |
| 111 |
sleep_indicator 120 |
| 112 |
wait_for_shell |
| 113 |
sleep_indicator 10 |
| 114 |
network |
| 115 |
unlock_screen |
| 116 |
} |
| 117 |
|
| 118 |
function network { |
| 119 |
# check for available wi-fi or cellular network |
| 120 |
if adb -s ${SERIALNUMBER} shell "nmcli -t -f device,type dev"|grep -q wlan; then |
| 121 |
echo "Wi-Fi is enabled" |
| 122 |
else |
| 123 |
if adb -s ${SERIALNUMBER} shell "nmcli -t -f device,type con"|grep -q "ril_1:gsm"; then |
| 124 |
echo "Cellular connection is available" |
| 125 |
else |
| 126 |
echo "Enable Wi-Fi or cellular network" |
| 127 |
# Without any network connection the profiling tools can not be installed |
| 128 |
exit |
| 129 |
fi |
| 130 |
fi |
| 131 |
if phablet-network -s ${SERIALNUMBER} 2>&1|grep -q Error; then |
| 132 |
echo "Reset and try again." |
| 133 |
reset -f |
| 134 |
phablet-network -s ${SERIALNUMBER} 2>&1 |
| 135 |
fi |
| 136 |
} |
| 137 |
|
| 138 |
function device_provisioning { |
| 139 |
# flash the latest image |
| 140 |
echo -e "Flashing \e[31m${CHANNEL}\e[0m" |
| 141 |
lomiri-device-flash touch --serial=${SERIALNUMBER} --channel=${CHANNEL} --wipe --developer-mode --password=${PASSWORD} |
| 142 |
sleep_indicator ${BOOTTIME} |
| 143 |
echo -e "Disable the intro wizard" |
| 144 |
phablet-config -s ${SERIALNUMBER} welcome-wizard --disable |
| 145 |
sleep_indicator 10 |
| 146 |
echo -e "Disable the edge swiping lecture " |
| 147 |
phablet-config -s ${SERIALNUMBER} edges-intro --disable |
| 148 |
sleep_indicator 10 |
| 149 |
echo -e "Clone the network " |
| 150 |
network |
| 151 |
sleep_indicator 10 |
| 152 |
adb -s ${SERIALNUMBER} shell "echo ${PASSWORD}|sudo -S reboot 2>&1|grep -v password" |
| 153 |
sleep_indicator 120 |
| 154 |
network |
| 155 |
sleep_indicator 10 |
| 156 |
echo "Set up with the archive image" |
| 157 |
adb -s ${SERIALNUMBER} shell "echo ${PASSWORD}|sudo -S touch /userdata/.writable_image 2>&1|grep -v password > /dev/null" |
| 158 |
adb -s ${SERIALNUMBER} shell "echo ${PASSWORD}|sudo -S touch /userdata/.adb_onlock 2>&1|grep -v password > /dev/null" |
| 159 |
#phablet-config -s ${SERIALNUMBER} writable-image -r ${PASSWORD} 2>&1 > /dev/null |
| 160 |
echo "Sleep after phablet-config"; |
| 161 |
sleep_indicator 10 |
| 162 |
echo -e "Clone the network " |
| 163 |
network |
| 164 |
adb -s ${SERIALNUMBER} shell "echo ${PASSWORD}|sudo -S reboot 2>&1|grep -v password" |
| 165 |
sleep_indicator 120 |
| 166 |
network |
| 167 |
sleep_indicator 10 |
| 168 |
} |
| 169 |
|
| 170 |
function measure_app_startups { |
| 171 |
for APPLICATION in "${APPLICATIONS[@]}" |
| 172 |
do |
| 173 |
if [[ ${APPLICATION} =~ ${FILTER} ]]; then |
| 174 |
echo -e "\e[31m${APPLICATION}\e[0m" |
| 175 |
LTTNG_SESSION_NAME="" |
| 176 |
while read -r LINE |
| 177 |
do |
| 178 |
if [[ $LINE =~ $LTTNG_SESSION_NAME_REGEXP ]]; then |
| 179 |
LTTNG_SESSION_NAME=${BASH_REMATCH[1]} |
| 180 |
fi |
| 181 |
if [[ $LINE =~ "Falling back to local" ]]; then |
| 182 |
# Falling back to local |
| 183 |
REMOTE_LTTNG_SESSION=false |
| 184 |
fi |
| 185 |
if [[ $LINE =~ "Traces will be written in" ]]; then |
| 186 |
LTTNG_TRACE_FILE=${LINE/Traces will be written in /} |
| 187 |
LTTNG_TRACE_FILE="${LTTNG_TRACE_FILE/$'\r'/}" |
| 188 |
fi |
| 189 |
done < <(adb -s ${SERIALNUMBER} shell "/usr/bin/lomiri-appstart-profile -a ${APPLICATION} -u ${IP_ADDRESS} -c ${COUNT} -s ${SLEEP_TIME} ${CLEAR_CACHE--q}") |
| 190 |
[ -z "${LTTNG_SESSION_NAME}" ] && echo "The lttng session is not available" || lomiri-app-launch-profiler-lttng -i ~/lttng-traces/lomiri-phablet/${LTTNG_SESSION_NAME} ${VERBOSE_PARAMETER--v} |
| 191 |
if [[ $REMOTE_LTTNG_SESSION == false ]]; then |
| 192 |
LTTNG_TRACE_PATH=${LTTNG_TRACE_FILE/$LTTNG_SESSION_NAME/} |
| 193 |
adb -s ${SERIALNUMBER} shell "echo ${PASSWORD}|sudo -S chown phablet $LTTNG_TRACE_PATH -R 2>&1|grep -v password > /dev/null" |
| 194 |
adb -s ${SERIALNUMBER} pull ${LTTNG_TRACE_FILE} ${LTTNG_SESSION_NAME} > /dev/null 2>&1 |
| 195 |
lomiri-app-launch-profiler-lttng -i ${LTTNG_SESSION_NAME} ${VERBOSE_PARAMETER--v} |
| 196 |
if [ -z "${LTTNG_SESSION_NAME}" ];then |
| 197 |
rm -rf ${LTTNG_SESSION_NAME} |
| 198 |
fi |
| 199 |
fi |
| 200 |
fi |
| 201 |
done |
| 202 |
} |
| 203 |
|
| 204 |
while getopts ":cqhvn:s:w:p:f:a:o:" opt; do |
| 205 |
case $opt in |
| 206 |
c) |
| 207 |
COMISSION=true |
| 208 |
;; |
| 209 |
n) |
| 210 |
COUNT=$OPTARG |
| 211 |
;; |
| 212 |
s) |
| 213 |
SLEEP_TIME=$OPTARG |
| 214 |
;; |
| 215 |
p) |
| 216 |
TEST_SILO=true |
| 217 |
PPA=$OPTARG |
| 218 |
;; |
| 219 |
f) |
| 220 |
FILTER=$OPTARG |
| 221 |
;; |
| 222 |
a) |
| 223 |
IFS=',' read -r -a APPLICATIONS <<< "$OPTARG" |
| 224 |
;; |
| 225 |
w) |
| 226 |
PASSWORD=$OPTARG |
| 227 |
;; |
| 228 |
v) |
| 229 |
VERBOSE=true |
| 230 |
unset VERBOSE_PARAMETER |
| 231 |
;; |
| 232 |
q) |
| 233 |
unset CLEAR_CACHE |
| 234 |
;; |
| 235 |
|
| 236 |
h) |
| 237 |
VERBOSE=true |
| 238 |
echo "Usage: lomiri-appstart-test -c -p 025 -n 5 -s 10" |
| 239 |
echo -e "\t-c : Provision the device from the rc-proposed channel" |
| 240 |
echo -e "\t-n : Number of times the applications are started during the test. Default $COUNT" |
| 241 |
echo -e "\t-s : Sleep time between application starts. Default $SLEEP_TIME" |
| 242 |
echo -e "\t-p : Run tests against a silo Default is ${TEST_SILO} the default silo is: ${SILO}" |
| 243 |
echo -e "\t-w : Password of the phablet user on the device. Default ${PASSWORD}" |
| 244 |
echo -e "\t-f : Filter for the test suite. Default $FILTER" |
| 245 |
echo -e "\t-v : Turn lomiri-appstart-test to be verbose. Default $VERBOSE" |
| 246 |
echo -e "\t-q : Test the application startup with QML cache. Default ${CLEAR_CACHE-true} ${CLEAR_CACHE+false}" |
| 247 |
echo -e "\t-h : Show this help" |
| 248 |
exit |
| 249 |
;; |
| 250 |
:) |
| 251 |
echo "Option -$OPTARG requires an argument." >&2 |
| 252 |
exit |
| 253 |
esac |
| 254 |
done |
| 255 |
|
| 256 |
# Use the first available device for testing |
| 257 |
echo -e "Waiting for a device" |
| 258 |
adb wait-for-device |
| 259 |
SERIALNUMBER=`adb devices -l | grep -Ev "List of devices attached" | grep -Ev "emulator-" | sed "/^$/d"|sed "s/ .*//g"` |
| 260 |
adb -s ${SERIALNUMBER} wait-for-device |
| 261 |
echo "Serial number: ${SERIALNUMBER}" |
| 262 |
echo "Test with QML cache: ${CLEAR_CACHE-true}" ${CLEAR_CACHE+false} |
| 263 |
echo "Number of start: ${COUNT}" |
| 264 |
echo "Length of sleep between restarts: ${SLEEP_TIME}" |
| 265 |
echo "Filter: ${FILTER}" |
| 266 |
echo "Commission: ${COMISSION}" |
| 267 |
echo "Test silo: ${TEST_SILO}" |
| 268 |
if [[ ${TEST_SILO} == true ]]; then |
| 269 |
echo "Silo: ${SILO}" |
| 270 |
fi |
| 271 |
echo "Password of the phablet user:${PASSWORD}" |
| 272 |
echo "Applications to test:" |
| 273 |
for APPLICATION in "${APPLICATIONS[@]}" |
| 274 |
do |
| 275 |
echo -e "\t$APPLICATION" |
| 276 |
done |
| 277 |
|
| 278 |
# Flash the device with rc-proposed |
| 279 |
if [ ${COMISSION} == true ]; then |
| 280 |
device_provisioning |
| 281 |
unlock_screen |
| 282 |
else |
| 283 |
# Check if the device is in writable mode |
| 284 |
if adb shell "echo ${PASSWORD}|sudo -S bash -c '[[ -f /userdata/.writable_image ]] &&echo && echo writable'" 2>&1 |grep -v password | grep -q writable ; then |
| 285 |
# The device is already writable |
| 286 |
unlock_screen |
| 287 |
network |
| 288 |
else |
| 289 |
adb -s ${SERIALNUMBER} shell "echo ${PASSWORD}|sudo -S touch /userdata/.writable_image 2>&1|grep -v password > /dev/null" |
| 290 |
adb -s ${SERIALNUMBER} shell "echo ${PASSWORD}|sudo -S touch /userdata/.adb_onlock 2>&1|grep -v password > /dev/null" |
| 291 |
reset -f |
| 292 |
sleep_indicator 120 |
| 293 |
echo -e "Clone the network " |
| 294 |
network |
| 295 |
adb -s ${SERIALNUMBER} shell "echo ${PASSWORD}|sudo -S reboot 2>&1|grep -v password" |
| 296 |
sleep_indicator 120 |
| 297 |
fi |
| 298 |
fi |
| 299 |
|
| 300 |
# Install the lomiri-app-launch-profiler on the device if needed |
| 301 |
if adb shell "dpkg -l lomiri-app-launch-profiler" 2>&1 | grep -q "no packages found" ; then |
| 302 |
echo "Installing lomiri-app-launch-profiler on the device" |
| 303 |
adb -s ${SERIALNUMBER} shell "echo ${PASSWORD}|sudo -S apt-get update 2>&1|grep -v password > /dev/null" |
| 304 |
if adb -s ${SERIALNUMBER} shell "echo ${PASSWORD}|sudo -S apt-cache search lomiri-app-launch-profiler 2>/dev/null"|grep -q lomiri-app-launch-profiler; then |
| 305 |
adb -s ${SERIALNUMBER} shell "echo ${PASSWORD}|sudo -S apt-get update 2>&1|grep -v password > /dev/null" |
| 306 |
adb -s ${SERIALNUMBER} shell "echo ${PASSWORD}|sudo -S apt-get install --yes --force-yes lomiri-app-launch-profiler 2>&1 |grep -v password > /dev/null" |
| 307 |
else |
| 308 |
echo "lomiri-app-launch-profiler is not available from the archives." |
| 309 |
echo "Please install it manually and press enter." |
| 310 |
read |
| 311 |
fi |
| 312 |
else |
| 313 |
echo "The lomiri-app-launch-profiler is installed on the device" |
| 314 |
fi |
| 315 |
|
| 316 |
# Start the lttng-relayd if needed |
| 317 |
pgrep lttng-relayd > /dev/null |
| 318 |
if [ $? -eq 0 ]; then |
| 319 |
echo -e "The lttng-relayd is already running." |
| 320 |
LTTNG_RELAYD_STARTED=false |
| 321 |
else |
| 322 |
LTTNG_RELAYD_STARTED=true |
| 323 |
echo -e "Starting lttng-relayd" |
| 324 |
lttng-relayd & |
| 325 |
sleep_indicator 5 |
| 326 |
fi |
| 327 |
|
| 328 |
nc -z ${IP_ADDRESS} 5343 |
| 329 |
if [ $? -eq 0 ]; then |
| 330 |
echo "The lttng server ${URL} is listening on 5343" |
| 331 |
else |
| 332 |
echo "The lttng server is not accesible. Check lttng-relayd or firewall policies." |
| 333 |
fi |
| 334 |
|
| 335 |
# Configure the silo on the device if requested |
| 336 |
if [[ ${TEST_SILO} == true ]]; then |
| 337 |
echo "Testing with ${SILO}" |
| 338 |
if adb -s ${SERIALNUMBER} shell "echo ${PASSWORD}|sudo -S bash -c 'ls -l /etc/apt/sources.list.d/' 2>&1"|grep -q testing-ppa.list; then |
| 339 |
echo "Already set up" |
| 340 |
else |
| 341 |
echo -e "Set up with silo \e[31m${SILO}\e[0m" |
| 342 |
adb -s ${SERIALNUMBER} shell "echo ${PASSWORD}|sudo -S bash -c 'echo \"deb http://ppa.launchpad.net/ci-train-ppa-service/landing-${SILO}/${DISTRO} ${SERIES} main\" > /etc/apt/sources.list.d/silo-${SILO}.list' 2>&1|grep -v password > /dev/null " |
| 343 |
SILO=${SILO/\//-} |
| 344 |
adb -s ${SERIALNUMBER} shell "echo ${PASSWORD}|sudo -S bash -c 'echo -e \"Package: *\nPin: release o=LP-PPA-ci-train-ppa-service-landing-${SILO}\nPin-Priority: 1100\" > /etc/apt/preferences.d/silo.pref' 2>&1|grep -v password > /dev/null " |
| 345 |
adb -s ${SERIALNUMBER} shell "test -e /usr/sbin/policy-rc.d && cp /usr/sbin/policy-rc.d /tmp/policy-rc.d" |
| 346 |
adb -s ${SERIALNUMBER} shell "echo ${PASSWORD}|sudo -S bash -c 'echo \"exit 101\" > /usr/sbin/policy-rc.d' 2>&1|grep -v password > /dev/null" |
| 347 |
adb -s ${SERIALNUMBER} shell "echo ${PASSWORD}|sudo -S bash -c 'chmod +x /usr/sbin/policy-rc.d' 2>&1|grep -v password > /dev/null" |
| 348 |
adb -s ${SERIALNUMBER} shell "echo ${PASSWORD}|sudo -S apt-get update 2>&1|grep -v password > /dev/null" |
| 349 |
adb -s ${SERIALNUMBER} shell "echo ${PASSWORD}|sudo -S apt-get dist-upgrade --yes --force-yes 2>&1 |grep -v password > /dev/null" |
| 350 |
adb -s ${SERIALNUMBER} shell "echo ${PASSWORD}|sudo -S dpkg --configure -a 2>&1 |grep -v password > /dev/null" |
| 351 |
adb -s ${SERIALNUMBER} shell "echo ${PASSWORD}|sudo -S apt-get --force-yes -f install 2>&1 |grep -v password > /dev/null" |
| 352 |
adb -s ${SERIALNUMBER} shell "echo ${PASSWORD}|sudo -S reboot 2>&1|grep -v password > /dev/null" |
| 353 |
sleep_indicator 120 |
| 354 |
unlock_screen |
| 355 |
network |
| 356 |
sleep_indicator 5 |
| 357 |
fi |
| 358 |
fi |
| 359 |
|
| 360 |
# Measure the application startup time |
| 361 |
measure_app_startups |
| 362 |
|
| 363 |
if [[ ${TEST_SILO} == true ]]; then |
| 364 |
echo "Cleaning up silo ${SILO}" |
| 365 |
if adb -s ${SERIALNUMBER} shell "dpkg-query -W --showformat='${Status}\n' ppa-purge 2>&1"|grep -q installed; then |
| 366 |
adb -s ${SERIALNUMBER} shell "echo ${PASSWORD}|sudo -S apt-get --force-yes intsall ppa-purge 2>&1 |grep -v password > /dev/null" |
| 367 |
REMOVE_PPA_PURGE=true |
| 368 |
fi |
| 369 |
adb -s ${SERIALNUMBER} shell "echo ${PASSWORD}|sudo -S ppa-purge -y -i ppa:ci-train-ppa-service/landing-${SILO} 2>&1 |grep -v password > /dev/null" |
| 370 |
if [[ ${REMOVE_PPA_PURGE} == true ]]; then |
| 371 |
adb -s ${SERIALNUMBER} shell "echo ${PASSWORD}|sudo -S apt-get --force-yes purge ppa-purge 2>&1 |grep -v password > /dev/null" |
| 372 |
fi |
| 373 |
fi |
| 374 |
|
| 375 |
# Kill the lttng-relayd if it was started here |
| 376 |
if [[ ${LTTNG_RELAYD_STARTED} == true ]]; then |
| 377 |
kill -9 `pgrep lttng-relayd` |
| 378 |
fi |