~pwlars/ubuntu-test-cases/krillin-recovery

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
#!/bin/sh

set -e

BASEDIR=$(dirname $(readlink -f $0))/..
RESDIR=`pwd`/clientlogs

export PATH=${BASEDIR}/utils/host:${PATH}
export TARGET_PREFIX=adb-shell


usage() {
	cat <<EOF
usage: $0 -a APP [-s ANDROID_SERIAL] [-Q] [-o results_dir] [-S]

Runs a set of autopilot tests on the target

OPTIONS:
  -h	Show this message
  -s    Specify the serial of the device to test
  -a    The application to test (can be repeated)
  -o    Specify the directory to place results in.
        Default: $RESDIR
  -Q    "Quick" don't do a reboot of the device before/between testsuites.
  -S    Skip the system-settle tests that run before/after each testsuite.

EOF
}

system_settle() {
	[ -z $NOSETTLE ] || return 0

	label=$1
	odir=$2
	rc=0
	settle=${BASEDIR}/tests/systemsettle/systemsettle.sh
	{
		export UTAH_PROBE_DIR=${odir}  # needed for log file location
		timeout 120s $settle -c5 -d2 -p 97.5 -l $label || rc=1
		echo $rc > ${odir}/settle_${label}.rc
	} 2>&1 | tee ${odir}/settle_${label}.log

	if [ "$label" = "after" ] ; then
		${BASEDIR}/scripts/combine_results ${odir}
	fi
}

test_app() {
	app=$1

	odir=${RESDIR}/${app}
	[ -d $odir ] && rm -rf $odir
	mkdir -p $odir

	system_settle before $odir

	if adb-shell /home/phablet/bin/unlock_screen.sh ; then
		phablet-test-run \
			-o ${odir} \
			-a /var/crash -a /home/phablet/.cache/upstart \
			-v $app || true
	else
		echo Screen unlock failed, skipping $app
	fi
	system_settle after $odir
}

reboot_wait() {
	if [ -z $QUICK ] ; then
		${BASEDIR}/scripts/reboot-and-wait
		adb shell 'rm -rf /var/crash/* /home/phablet/.cache/upstart/*.log'
	else
		echo "SKIPPING phone reboot..."
	fi
}

main() {
	# print the build date so the jenkins job can use it as the
	# build description
	BUILDID=$(adb shell cat /home/phablet/.ci-version)
	echo "= TOUCH IMAGE VERSION:$BUILDID"

	[ -d $RESDIR ] || mkdir -p $RESDIR

	set -x

	for app in $APPS ; do
		set +x
		echo "========================================================"
		echo "= testing $app"
		echo "========================================================"
		set -x
		reboot_wait
		test_app $app
	done
}

while getopts s:a:o:QSh opt; do
	case $opt in
	h)
		usage
		exit 0
		;;
	s)
		export ANDROID_SERIAL=$OPTARG
		;;
	o)
		RESDIR=$OPTARG
		;;
	a)
		APPS="$APPS $OPTARG"
		;;
	Q)
		QUICK=1
		;;
	S)
		NOSETTLE=1
		;;
	esac
done

if [ -z $ANDROID_SERIAL ] ; then
	# ensure we only have one device attached
	lines=$(adb devices | wc -l)
	if [ $lines -gt 3 ] ; then
		echo "ERROR: More than one device attached, please use -s option"
		echo
		usage
		exit 1
	fi
fi
if [ -z "$APPS" ] ; then
	echo "ERROR: No app specified"
	usage
	exit 1
fi

main