1e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber# Script to gather perf and perf/watt data for several workloads
2e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber#
3e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber# Setup:
4e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber#
5e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber# - device connected to monsoon with USB passthrough enabled
6e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber# - network enabled (baseline will be measured and subtracted
7e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber#   from results) (network needed for chrome, youtube tests)
8e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber# - the device is rebooted after each test (can be inhibited
9e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber#   with "-r 0")
10e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber#
11e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber# Default behavior is to run each of the known workloads for
12e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber# 30 minutes gathering both performance and power data.
13e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber#
14e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber# The default time can be overridden with the -t option. To
15e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber# change individual test times, a config file can be specifed
16e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber# via -f with times for individual tests. Example file contents:
17050b28a593350047845a45a14cc5026221ac1620James Dong#
18050b28a593350047845a45a14cc5026221ac1620James Dong#	idleTime=60
19050b28a593350047845a45a14cc5026221ac1620James Dong#	recentflingTime=60
20050b28a593350047845a45a14cc5026221ac1620James Dong#	chromeTime=60
21e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber#	youtubeTime=0
226b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong#	sysappsTime=60
236b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong#	suntempleTime=5
24e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber#
25e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber# Output goes to the current directory.
266b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong#
27365a963142093a1cd8efdcea76b5f65096a5b115James Dong# Examples:
2846292fb347d72a314d985e34e5e3743d846cb9b6James Dong#
29e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber# - Run all tests for 15 minutes (default is 30): ./pwrtest.sh -t 15 -R MDA20
30e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber#
31e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber# - Use a config file for test times: ./pwrtest.sh -f ./myconfig -R MDA20
326b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong#
336b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong# - Use a init file to setup device tuneables after each restart (this is
346b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong#   a bash script which should include adb commands to set up device):
356b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong#     ./pwrtest.sh -F devtunables
366b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong#
376b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong
386b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames DongdefaultTime=30
396b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Donggarbageminutes=8
405ff1dd576bb93c45b44088a51544a18fc43ebf58Steve Block
416b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dongfunction Usage {
426b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	echo "Usage: $0 [OPTIONS]"
436b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	echo "-d device : device type (shamu, bullhead, ...)"
446b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	echo "-f configFile : config file to override individual test times"
456b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	echo "-g garbageMinutes : time to skip power measurement at beginning of test"
466b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	echo "                    default=$garbagetime minutes"
476b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	echo "-r restart : 0=no reboot between tests, 1=reboot (default)"
486b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	echo "-t defaultTimeMin : default time to run each test"
49e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber	echo "                    default=$defaultTime minutes"
50ab334fd351ae5a0e18903da123d63e565b536874Glenn Kasten	echo "-D cmddir : directory to find defs.sh"
51a0108697f86d8625eb7ad3f13e422427fe7573caJames Dong	echo "-F restartHookFile : file of commands to set device tunables after restart (optional)"
52a0108697f86d8625eb7ad3f13e422427fe7573caJames Dong	echo "-R release : release running on device (MDA20, 2054728, etc)"
536b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong}
5446292fb347d72a314d985e34e5e3743d846cb9b6James Dong
556b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dongrestart=1
566b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Donghz=5
57be6ec71af2d12e2a55f2f0b1b77d3fa5d593a1c7James Dongshadowgrid2TimeMax=25
58ab334fd351ae5a0e18903da123d63e565b536874Glenn Kasten
59ab334fd351ae5a0e18903da123d63e565b536874Glenn KastenCMDDIR=$(dirname $0 2>/dev/null)
60be6ec71af2d12e2a55f2f0b1b77d3fa5d593a1c7James DongCMDDIR=${CMDDIR:=.}
61e49f2b424318aa8e830e7a1338e5e32ab82992f9Eric Laurent
62e49f2b424318aa8e830e7a1338e5e32ab82992f9Eric LaurentMONSOON=monsoon.par
63e49f2b424318aa8e830e7a1338e5e32ab82992f9Eric Laurent
64e49f2b424318aa8e830e7a1338e5e32ab82992f9Eric Laurentwhile [ $# -gt 0 ]
65dd8104cc5367262f0e5f13df4e79f131e8d560bbGlenn Kastendo
66e49f2b424318aa8e830e7a1338e5e32ab82992f9Eric Laurent	case "$1" in
67e49f2b424318aa8e830e7a1338e5e32ab82992f9Eric Laurent	(-D) CMDDIR=$2; shift;;
68e49f2b424318aa8e830e7a1338e5e32ab82992f9Eric Laurent	(-r) restart=$2; shift;;
69e49f2b424318aa8e830e7a1338e5e32ab82992f9Eric Laurent	(-t) defaultTime=$2; shift;;
70e49f2b424318aa8e830e7a1338e5e32ab82992f9Eric Laurent	(-F) restartfile=$2; shift;;
71e49f2b424318aa8e830e7a1338e5e32ab82992f9Eric Laurent	(-g) garbageminutes=$2; shift;;
72e49f2b424318aa8e830e7a1338e5e32ab82992f9Eric Laurent	(-f)
73e49f2b424318aa8e830e7a1338e5e32ab82992f9Eric Laurent		configFile=$2;
74e49f2b424318aa8e830e7a1338e5e32ab82992f9Eric Laurent		echo "Reading configs from $configFile..."
75e49f2b424318aa8e830e7a1338e5e32ab82992f9Eric Laurent		. ./$configFile
76e49f2b424318aa8e830e7a1338e5e32ab82992f9Eric Laurent		shift;;
77e49f2b424318aa8e830e7a1338e5e32ab82992f9Eric Laurent	(-R) echo $2 > ./build; shift;;
78e49f2b424318aa8e830e7a1338e5e32ab82992f9Eric Laurent	(--) ;;
79e49f2b424318aa8e830e7a1338e5e32ab82992f9Eric Laurent	(--help)
80e49f2b424318aa8e830e7a1338e5e32ab82992f9Eric Laurent		Usage
81e49f2b424318aa8e830e7a1338e5e32ab82992f9Eric Laurent		exit 0;;
82e49f2b424318aa8e830e7a1338e5e32ab82992f9Eric Laurent	(*)
83e49f2b424318aa8e830e7a1338e5e32ab82992f9Eric Laurent		echo "Unknown option: $1"
84e49f2b424318aa8e830e7a1338e5e32ab82992f9Eric Laurent		Usage
85e49f2b424318aa8e830e7a1338e5e32ab82992f9Eric Laurent		exit 1;;
86e49f2b424318aa8e830e7a1338e5e32ab82992f9Eric Laurent	esac
87e49f2b424318aa8e830e7a1338e5e32ab82992f9Eric Laurent	shift
88e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huberdone
89e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber
90e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber. $CMDDIR/defs.sh --
91e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber
92b44c9d2bdc0d5b9cb03254022a58e017b516e9e6James Dongdevdir="/data/local/tmp"
93e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Hubersuntempledir=${CMDDIR}/suntemple
94e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber
95e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Hubercase $DEVICE in
96e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber(shamu|hammerhead)
97e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber	HWUITEST=hwuitest
98e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber	onSwipe="700 1847 700 400 50"
99e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber	;;
100e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber(*)
101e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber	HWUITEST=hwuitest64
102e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber	onSwipe="500 1200 500 550 150"
103e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber	;;
1046b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dongesac
105e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber
106e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huberscripts="defs.sh systemapps.sh recentfling.sh youtube.sh chromefling.sh $HWUITEST"
107e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber
108e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huberif ! $MONSOON >/dev/null 2>&1; then
1096e20bdf799a6f4efa6c42121a958634ea32ed5ccJames Dong	echo $MONSOON must be in your PATH >&2
1106e20bdf799a6f4efa6c42121a958634ea32ed5ccJames Dong	exit 1
1116e20bdf799a6f4efa6c42121a958634ea32ed5ccJames Dongfi
1126e20bdf799a6f4efa6c42121a958634ea32ed5ccJames Dong
113d3d4e5069e1af0437c4f5a7b4ba344bda5b937afJames Dongfunction usbpassthru {
114d3d4e5069e1af0437c4f5a7b4ba344bda5b937afJames Dong	if [ "$1" = off ]; then
115d707fcb3e29707ca4a5935c294ef0b38eb5aba5fJames Dong		state=off
116f60cafe0e6aad8f9ce54660fa88b651ae4e749e6James Dong	else
117f60cafe0e6aad8f9ce54660fa88b651ae4e749e6James Dong		state=on
118f60cafe0e6aad8f9ce54660fa88b651ae4e749e6James Dong	fi
119f60cafe0e6aad8f9ce54660fa88b651ae4e749e6James Dong	echo Setting usb pass-thru to $state
120f60cafe0e6aad8f9ce54660fa88b651ae4e749e6James Dong	monsoon.par --usbpassthrough=$state
121e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber}
122e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber
123e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huberfunction pwrcollect {
124eaae38445a340c4857c1c5569475879a728e63b7James Dong	collectmin=$1
125eaae38445a340c4857c1c5569475879a728e63b7James Dong	collectmin=${collectmin:=60}
126eaae38445a340c4857c1c5569475879a728e63b7James Dong	# samples = hz * 60 * minutes
127e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber	((samples=5*60*collectmin))
128e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber	monsoon.par --timestamp --samples $samples --hz 5
129eaae38445a340c4857c1c5569475879a728e63b7James Dong}
130e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber
131e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huberfunction copy_files {
132e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber	adb shell mkdir -p $devdir
1336b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	for file in $scripts
1343856b090cd04ba5dd4a59a12430ed724d5995909Steve Block	do
1356b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong		adb push $CMDDIR/$file $devdir
1366b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	done
1376b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong}
1386b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong
1396b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dongfunction install_suntemple {
1406b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	echo Checking for suntemple installation...
1416b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	#stdest=/storage/sdcard0/obb/com.BrueComputing.SunTemple
1426b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	stdest=/storage/emulated/0/obb/com.BrueComputing.SunTemple
1436b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	dircontents=$(adb ls $stdest 2>/dev/null)
1443856b090cd04ba5dd4a59a12430ed724d5995909Steve Block	if [ "$dircontents" = "" ]; then
1456b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong		echo Installing suntemple...
1466b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong		adb install $suntempledir/*.apk
1476b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong		adb shell mkdir -p $stdest
1486b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong		adb push $suntempledir/main*obb $stdest
1496b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	else
150b44c9d2bdc0d5b9cb03254022a58e017b516e9e6James Dong		echo dircontents=$dircontents
1516b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong		echo Suntemple already installed.
152e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber	fi
153e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber}
154e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber
155e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huberfunction run_test {
1566e20bdf799a6f4efa6c42121a958634ea32ed5ccJames Dong	testName=$1
1576e20bdf799a6f4efa6c42121a958634ea32ed5ccJames Dong	collectMinutes=$2
1586e20bdf799a6f4efa6c42121a958634ea32ed5ccJames Dong	collectOutput=${testName}-power-raw.out
1596e20bdf799a6f4efa6c42121a958634ea32ed5ccJames Dong	powerOutput=${testName}-power.out
160e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber	echo -----------------------------------------------------
1616b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	echo TEST: $testName
1626b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	echo enabled Cores $(adb shell "cat /sys/devices/system/cpu/online")
1636b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	date
164365a963142093a1cd8efdcea76b5f65096a5b115James Dong	echo -----------------------------------------------------
165e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber	usbpassthru off
166e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber	pwrcollect $collectMinutes > $collectOutput 2>/dev/null
167e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber	# take off the first 2min of samples
168e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber	totalSamples=$(cat $collectOutput | wc -l)
1696b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	# we throw away the first "garbageminutes" of the data
1706e20bdf799a6f4efa6c42121a958634ea32ed5ccJames Dong	# since it is volatile
1716e20bdf799a6f4efa6c42121a958634ea32ed5ccJames Dong	((garbage=hz*60*garbageminutes))
1726e20bdf799a6f4efa6c42121a958634ea32ed5ccJames Dong	((remaining=totalSamples-garbage))
1736e20bdf799a6f4efa6c42121a958634ea32ed5ccJames Dong	if [ $remaining -gt 0 ]; then
174e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber		tail -$remaining $collectOutput > $powerOutput
175e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber	else
1766b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong		cp $collectOutput $powerOutput
177e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber	fi
178e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber	echo power data for $testName copied to $collectOutput
179e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber	usbpassthru on
180e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber	sleep 10
181e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber	adb devices
182e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber	sleep 10
183f1ae1963f5028a670573b50a9c1cfb504fc426b4James Dong}
184f1ae1963f5028a670573b50a9c1cfb504fc426b4James Dong
185f1ae1963f5028a670573b50a9c1cfb504fc426b4James Dongfunction start_job {
186f1ae1963f5028a670573b50a9c1cfb504fc426b4James Dong	cmdline="$1"
187f1ae1963f5028a670573b50a9c1cfb504fc426b4James Dong	echo Running $cmdline
188f1ae1963f5028a670573b50a9c1cfb504fc426b4James Dong	(adb shell "cd $devdir && nohup $cmdline > test.out") &
189f1ae1963f5028a670573b50a9c1cfb504fc426b4James Dong	sleep 5
190f1ae1963f5028a670573b50a9c1cfb504fc426b4James Dong	kill %1 2>/dev/null
191f1ae1963f5028a670573b50a9c1cfb504fc426b4James Dong}
192f1ae1963f5028a670573b50a9c1cfb504fc426b4James Dong
193f1ae1963f5028a670573b50a9c1cfb504fc426b4James Dongfunction cleanup_job {
194f1ae1963f5028a670573b50a9c1cfb504fc426b4James Dong	testName=$1
195f1ae1963f5028a670573b50a9c1cfb504fc426b4James Dong	processName=$2
196f1ae1963f5028a670573b50a9c1cfb504fc426b4James Dong	processName=${processName:=" sh "}
197f1ae1963f5028a670573b50a9c1cfb504fc426b4James Dong	set -- $(adb shell ps | tr "\r" " " | grep "$processName")
198f1ae1963f5028a670573b50a9c1cfb504fc426b4James Dong	echo killing PID=$2...
199f1ae1963f5028a670573b50a9c1cfb504fc426b4James Dong	adb shell kill $2
200f1ae1963f5028a670573b50a9c1cfb504fc426b4James Dong	sleep 1
201f1ae1963f5028a670573b50a9c1cfb504fc426b4James Dong	echo copying test output to $testName...
202f1ae1963f5028a670573b50a9c1cfb504fc426b4James Dong	adb pull $devdir/test.out
203f1ae1963f5028a670573b50a9c1cfb504fc426b4James Dong	mv test.out ${testName}.out
204f1ae1963f5028a670573b50a9c1cfb504fc426b4James Dong	if [ $restart -gt 0 ]; then
205f1ae1963f5028a670573b50a9c1cfb504fc426b4James Dong		restart_device
206f1ae1963f5028a670573b50a9c1cfb504fc426b4James Dong	else
207f1ae1963f5028a670573b50a9c1cfb504fc426b4James Dong		doKeyevent HOME
208f1ae1963f5028a670573b50a9c1cfb504fc426b4James Dong	fi
209f1ae1963f5028a670573b50a9c1cfb504fc426b4James Dong}
210f1ae1963f5028a670573b50a9c1cfb504fc426b4James Dong
211f1ae1963f5028a670573b50a9c1cfb504fc426b4James Dongfunction airplane_mode {
212f1ae1963f5028a670573b50a9c1cfb504fc426b4James Dong	if [ "$1" = "on" ]; then
213f1ae1963f5028a670573b50a9c1cfb504fc426b4James Dong		mode=true
214f1ae1963f5028a670573b50a9c1cfb504fc426b4James Dong		setting=1
215e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber	else
216e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber		mode=false
2176b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong		setting=0
2186b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	fi
2196e20bdf799a6f4efa6c42121a958634ea32ed5ccJames Dong	adb shell settings put global airplane_mode_on $setting
2206e20bdf799a6f4efa6c42121a958634ea32ed5ccJames Dong	adb shell am broadcast -a android.intent.action.AIRPLANE_MODE --ez state $mode
2216e20bdf799a6f4efa6c42121a958634ea32ed5ccJames Dong	echo Set airplane mode to $mode
2226e20bdf799a6f4efa6c42121a958634ea32ed5ccJames Dong}
2236e20bdf799a6f4efa6c42121a958634ea32ed5ccJames Dong
2246b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dongfunction restart_device {
2256b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	adb reboot
2266b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	echo Wait 60s for device to restart...
2276b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	sleep 60
2286b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	while ! adb root
2296b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	do
2306b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong		echo Waiting for device to come up...
2316b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong		sleep 10
2326b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	done
2336b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	echo Wait 30s to complete boot activities...
2346b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	sleep 30
2356b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	echo Restart complete.
2366b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	doTap 897 1075
2376b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	sleep 2
2386b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	doSwipe $onSwipe
2396b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	restartfile=${restartfile:="./restarthook"}
2406b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	if [ -f $restartfile ]; then
2416b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong		# hook to change tunables after a restart
2426b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong		. $restartfile
2436b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	fi
2446b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong}
2456b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong
2466b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dongusbpassthru on
2476b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dongadb devices 2>/dev/null
2486b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong
2496b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dongairplane_mode off
2506b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dongif [ $restart -gt 0 ]; then
2516b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	restart_device
2526b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dongfi
253542db5d438988360d491a5add1040a2df9aa90c9James Dong
2546b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dongecho Copying $scripts to device $devdir...
2556b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dongcopy_files
2566b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dongtests=""
2576b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong
2586b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong# measure background power
259542db5d438988360d491a5add1040a2df9aa90c9James DongidleTime=${idleTime:=$defaultTime}
2606b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dongif [ $idleTime -gt 0 ]; then
2616b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	echo Test 1 : measure idle power for $idleTime minutes
2626b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	run_test idle $idleTime
263542db5d438988360d491a5add1040a2df9aa90c9James Dong	airplane_mode on
2646b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	echo Restarting for power baseline in airplane mode...
2653856b090cd04ba5dd4a59a12430ed724d5995909Steve Block	restart_device
2666b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	run_test idle-airplane $idleTime
2676b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	airplane_mode off
2686b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	# the screen blanks after 30 minutes. The first 2 minutes of the test
2696b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	# have already been filtered off. For our power baseline, keep the first
2706b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	# 20 minutes of the results
2716b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	((twentyminutes=hz*20*60))
2726b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	powerOutput="idle-power.out"
27346292fb347d72a314d985e34e5e3743d846cb9b6James Dong	displayPowerOutput="idle-display-power.out"
2746b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	airplanePowerOutput="idle-airplane-power.out"
2756b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	airplaneDisplayPowerOutput="idle-airplane-display-power.out"
2763856b090cd04ba5dd4a59a12430ed724d5995909Steve Block	totalSamples=$(cat $powerOutput | wc -l)
2776b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	if [ $twentyminutes -lt $totalSamples ]; then
2786b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong		head -$twentyminutes $powerOutput > $displayPowerOutput
2795ff1dd576bb93c45b44088a51544a18fc43ebf58Steve Block		head -$twentyminutes $airplanePowerOutput > $airplaneDisplayPowerOutput
2806b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	else
2816b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong		cp $powerOutput $displayPowerOutput
28246292fb347d72a314d985e34e5e3743d846cb9b6James Dong		cp $airplanePowerOutput $airplaneDisplayPowerOutput
283a472613aec322e25891abf5c77bf3f7e3c244920James Dong	fi
284a472613aec322e25891abf5c77bf3f7e3c244920James Dong	tests="$tests idle"
285a472613aec322e25891abf5c77bf3f7e3c244920James Dongfi
2863856b090cd04ba5dd4a59a12430ed724d5995909Steve Block
287a472613aec322e25891abf5c77bf3f7e3c244920James DongrecentflingTime=${recentflingTime:=$defaultTime}
288a472613aec322e25891abf5c77bf3f7e3c244920James Dongif [ $recentflingTime -gt 0 ]; then
289a472613aec322e25891abf5c77bf3f7e3c244920James Dong	echo $(date) Test 2 : recents fling for $recentflingTime minutes
2906b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	airplane_mode on
2916b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	adb shell "cd $devdir && ./systemapps.sh -A -T -i 1"
2926b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	start_job "./recentfling.sh -N -i 1000 -d $DEVICE"
2936b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	run_test recentfling $recentflingTime
2946b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	cleanup_job recentfling
2956b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	airplane_mode off
2966b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	date
2976b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	tests="$tests recentfling"
298f60cafe0e6aad8f9ce54660fa88b651ae4e749e6James Dongfi
2996b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong
3006b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames DongsuntempleTime=${suntempleTime:=$defaultTime}
301e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huberif [ $suntempleTime -gt 0 ]; then
302a472613aec322e25891abf5c77bf3f7e3c244920James Dong	echo $(date) Test 2 : run Sun Temple $suntempleTime minutes
303a472613aec322e25891abf5c77bf3f7e3c244920James Dong	airplane_mode on
304a472613aec322e25891abf5c77bf3f7e3c244920James Dong	install_suntemple
305a472613aec322e25891abf5c77bf3f7e3c244920James Dong	adb shell "am start $suntempleActivity"
306a472613aec322e25891abf5c77bf3f7e3c244920James Dong	run_test suntemple $suntempleTime
307a472613aec322e25891abf5c77bf3f7e3c244920James Dong	adb pull /sdcard/SunTemple/SunTemple/Saved/Logs/SunTemple.log
308a472613aec322e25891abf5c77bf3f7e3c244920James Dong	cleanup_job suntemple BrueComp
3096b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	airplane_mode off
3106b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	mv SunTemple.log suntemple.out
3116b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	# grab the suntemple log
312b575ddce78d266fa218006f90306158dda5c8f56James Dong	date
313b575ddce78d266fa218006f90306158dda5c8f56James Dong	tests="$tests suntemple"
314b575ddce78d266fa218006f90306158dda5c8f56James Dongfi
315b575ddce78d266fa218006f90306158dda5c8f56James Dong
316b575ddce78d266fa218006f90306158dda5c8f56James DongchromeTime=${chromeTime:=$defaultTime}
317b575ddce78d266fa218006f90306158dda5c8f56James Dongif [ $chromeTime -gt 0 ]; then
318b575ddce78d266fa218006f90306158dda5c8f56James Dong	echo $(date) Test 3 : chrome fling for $chromeTime minutes
319b575ddce78d266fa218006f90306158dda5c8f56James Dong	start_job "./chromefling.sh -i 1000 -d $DEVICE"
320b575ddce78d266fa218006f90306158dda5c8f56James Dong	run_test chrome $chromeTime
321b575ddce78d266fa218006f90306158dda5c8f56James Dong	cleanup_job chrome
322b575ddce78d266fa218006f90306158dda5c8f56James Dong	date
323b575ddce78d266fa218006f90306158dda5c8f56James Dong	tests="$tests chrome"
324d707fcb3e29707ca4a5935c294ef0b38eb5aba5fJames Dongfi
325b575ddce78d266fa218006f90306158dda5c8f56James Dong
326b575ddce78d266fa218006f90306158dda5c8f56James Dongshadowgrid2Time=${shadowgrid2Time:=$defaultTime}
327b575ddce78d266fa218006f90306158dda5c8f56James Dongif [ $shadowgrid2Time -gt $shadowgrid2TimeMax ]; then
328b575ddce78d266fa218006f90306158dda5c8f56James Dong	# we cap shadowgrid2 time since the display goes
329b575ddce78d266fa218006f90306158dda5c8f56James Dong	# off after 30 minutes
330b575ddce78d266fa218006f90306158dda5c8f56James Dong	$shadowgrid2Time=$shadowgrid2TimeMax
331b575ddce78d266fa218006f90306158dda5c8f56James Dongfi
332b575ddce78d266fa218006f90306158dda5c8f56James Dongif [ $shadowgrid2Time -gt 0 ]; then
333b575ddce78d266fa218006f90306158dda5c8f56James Dong	airplane_mode on
3346b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	echo $(date) Test 4 : shadowgrid2 for $shadowgrid2Time minutes
3353c3763d2ee1cd1fba7fe522fbaf0faca315d8c2aJames Dong	start_job "./$HWUITEST shadowgrid2 100000"
336b575ddce78d266fa218006f90306158dda5c8f56James Dong	run_test shadowgrid2 $shadowgrid2Time
337b575ddce78d266fa218006f90306158dda5c8f56James Dong	cleanup_job shadowgrid2 $HWUITEST
338b575ddce78d266fa218006f90306158dda5c8f56James Dong	airplane_mode off
339b575ddce78d266fa218006f90306158dda5c8f56James Dong	date
3406b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	tests="$tests shadowgrid2"
341b575ddce78d266fa218006f90306158dda5c8f56James Dongfi
342b575ddce78d266fa218006f90306158dda5c8f56James Dong
343b575ddce78d266fa218006f90306158dda5c8f56James DongyoutubeTime=${youtubeTime:=$defaultTime}
344b575ddce78d266fa218006f90306158dda5c8f56James Dongif [ $youtubeTime -gt 0 ]; then
345b575ddce78d266fa218006f90306158dda5c8f56James Dong	echo $(date) Test 5 : youtube for $youtubeTime minutes
346b575ddce78d266fa218006f90306158dda5c8f56James Dong	start_job "./youtube.sh -i 1000 -d $DEVICE"
347b575ddce78d266fa218006f90306158dda5c8f56James Dong	run_test youtube $youtubeTime
348b575ddce78d266fa218006f90306158dda5c8f56James Dong	cleanup_job youtube
349b575ddce78d266fa218006f90306158dda5c8f56James Dong	date
350b575ddce78d266fa218006f90306158dda5c8f56James Dong	tests="$tests youtube"
351b575ddce78d266fa218006f90306158dda5c8f56James Dongfi
352e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huber
3536b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames DongsysappsTime=${sysappsTime:=$defaultTime}
3546b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dongif [ $sysappsTime -gt 0 ]; then
355542db5d438988360d491a5add1040a2df9aa90c9James Dong	echo $(date) Test 6 : app switching for $sysappsTime minutes
356b575ddce78d266fa218006f90306158dda5c8f56James Dong	start_job "./systemapps.sh -T -i 1000 -d $DEVICE"
3576b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	run_test sysapps $sysappsTime
3586b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	cleanup_job sysapps
3596b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong	date
360b575ddce78d266fa218006f90306158dda5c8f56James Dong	tests="$tests sysapps"
3616b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dongfi
3626b61f4355db1974cd0f0dfaa4effdd7117b9f09bJames Dong
363e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huberecho Ran tests: $tests
364e7c9cb48fec02697227bd847cd2e69432659adfdAndreas Huberecho $tests > tests
365d3d4e5069e1af0437c4f5a7b4ba344bda5b937afJames Dong
366d3d4e5069e1af0437c4f5a7b4ba344bda5b937afJames Dong