Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1262)

Side by Side Diff: tools/skpbench/_hardware_android.py

Issue 2481413003: skpbench: simplify adb and reduce number of invocations (Closed)
Patch Set: skpbench: simplify adb and reduce number of invocations Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/skpbench/_adb_path.py ('k') | tools/skpbench/_hardware_nexus_6p.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2016 Google Inc. 1 # Copyright 2016 Google Inc.
2 # 2 #
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 from __future__ import print_function 6 from __future__ import print_function
7 from _hardware import Hardware 7 from _hardware import Hardware
8 import sys 8 import sys
9 import time 9 import time
10 10
11 class HardwareAndroid(Hardware): 11 class HardwareAndroid(Hardware):
12 def __init__(self, adb): 12 def __init__(self, adb):
13 Hardware.__init__(self) 13 Hardware.__init__(self)
14 self.warmup_time = 5 14 self.warmup_time = 5
15 self._adb = adb 15 self._adb = adb
16 self._is_root = self._adb.attempt_root() 16
17 if self._is_root: 17 if self._adb.root():
18 self._adb.remount() 18 self._adb.remount()
19 self._initial_airplane_mode = None 19 self._initial_ASLR = \
20 self._initial_location_providers = None 20 self._adb.check('cat /proc/sys/kernel/randomize_va_space')
21 self._initial_ASLR = None
22 21
23 def __enter__(self): 22 def __enter__(self):
24 # turn on airplane mode. 23 self._adb.shell('\n'.join([
25 self._initial_airplane_mode = \ 24 # turn on airplane mode.
26 self._adb.check('settings get global airplane_mode_on') 25 '''
27 self._adb.shell('settings put global airplane_mode_on 1') 26 settings put global airplane_mode_on 1''',
28 27
29 # disable GPS. 28 # disable GPS.
30 self._initial_location_providers = \ 29 '''
31 self._adb.check('settings get secure location_providers_allowed') 30 for MODE in gps wifi network; do
32 self._initial_location_providers = \ 31 settings put secure location_providers_allowed -$MODE
33 self._initial_location_providers.replace(',', ' ') 32 done''']))
34 self._adb.shell('''\
35 for PROVIDER in %s; do
36 settings put secure location_providers_allowed -$PROVIDER
37 done''' % self._initial_location_providers)
38 33
39 if self._is_root: 34 if self._adb.is_root():
40 # disable bluetooth, wifi, and mobile data. 35 self._adb.shell('\n'.join([
41 # TODO: can we query these initial values? 36 # disable bluetooth, wifi, and mobile data.
42 self._adb.shell('''\ 37 '''
43 service call bluetooth_manager 8 && 38 service call bluetooth_manager 8
44 svc wifi disable && 39 svc wifi disable
45 svc data disable''') 40 svc data disable''',
46 41
47 # kill the gui. 42 # kill the gui.
48 self._adb.shell('''\ 43 '''
49 setprop ctl.stop media && 44 setprop ctl.stop media
50 setprop ctl.stop zygote && 45 setprop ctl.stop zygote
51 setprop ctl.stop surfaceflinger && 46 setprop ctl.stop surfaceflinger
52 setprop ctl.stop drm''') 47 setprop ctl.stop drm''',
53 48
54 # disable ASLR. 49 # disable ASLR
55 self._initial_ASLR = \ 50 '''
56 self._adb.check('cat /proc/sys/kernel/randomize_va_space') 51 echo 0 > /proc/sys/kernel/randomize_va_space''']))
57 self._adb.shell('echo 0 > /proc/sys/kernel/randomize_va_space')
58 else: 52 else:
59 print("WARNING: no adb root access; results may be unreliable.", 53 print("WARNING: no adb root access; results may be unreliable.",
60 file=sys.stderr) 54 file=sys.stderr)
61 55
62 return Hardware.__enter__(self) 56 return Hardware.__enter__(self)
63 57
64 def __exit__(self, exception_type, exception_value, traceback): 58 def __exit__(self, exception_type, exception_value, traceback):
65 Hardware.__exit__(self, exception_type, exception_value, traceback) 59 Hardware.__exit__(self, exception_type, exception_value, traceback)
66 60
67 if self._is_root: 61 if self._adb.is_root():
68 # restore ASLR. 62 self._adb.shell('\n'.join([
69 self._adb.shell('echo %s > /proc/sys/kernel/randomize_va_space' % 63 # restore ASLR.
70 self._initial_ASLR) 64 '''
65 echo %s > /proc/sys/kernel/randomize_va_space''' % self._initial_ASLR,
71 66
72 # revive the gui. 67 # revive the gui.
73 self._adb.shell('''\ 68 '''
74 setprop ctl.start drm && 69 setprop ctl.start drm
75 setprop ctl.start surfaceflinger && 70 setprop ctl.start surfaceflinger
76 setprop ctl.start zygote && 71 setprop ctl.start zygote
77 setprop ctl.start media''') 72 setprop ctl.start media''']))
78 else:
79 # restore GPS (doesn't seem to work if we killed the gui).
80 self._adb.shell('''\
81 for PROVIDER in %s; do
82 settings put secure location_providers_allowed +$PROVIDER
83 done''' % self._initial_location_providers)
84
85 # restore airplane mode (doesn't seem to work if we killed the gui).
86 self._adb.shell('settings put global airplane_mode_on %s' %
87 self._initial_airplane_mode)
88 73
89 def sanity_check(self): 74 def sanity_check(self):
90 Hardware.sanity_check(self) 75 Hardware.sanity_check(self)
91 76
92 def print_debug_diagnostics(self): 77 def print_debug_diagnostics(self):
93 # search for and print thermal trip points that may have been exceeded. 78 # search for and print thermal trip points that may have been exceeded.
94 self._adb.shell('''\ 79 self._adb.shell('''\
95 THERMALDIR=/sys/class/thermal 80 THERMALDIR=/sys/class/thermal
96 if [ ! -d $THERMALDIR ]; then 81 if [ ! -d $THERMALDIR ]; then
97 exit 82 exit
(...skipping 15 matching lines...) Expand all
113 let i=i+1 98 let i=i+1
114 done 99 done
115 echo "$ZONE ($(cat type)): temp=$TEMP > $TRIPPOINT=$(cat $TRIPPOINT)" 1>&2 100 echo "$ZONE ($(cat type)): temp=$TEMP > $TRIPPOINT=$(cat $TRIPPOINT)" 1>&2
116 fi 101 fi
117 done''') 102 done''')
118 103
119 Hardware.print_debug_diagnostics(self) 104 Hardware.print_debug_diagnostics(self)
120 105
121 def sleep(self, sleeptime): 106 def sleep(self, sleeptime):
122 Hardware.sleep(self, sleeptime) 107 Hardware.sleep(self, sleeptime)
OLDNEW
« no previous file with comments | « tools/skpbench/_adb_path.py ('k') | tools/skpbench/_hardware_nexus_6p.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698