| OLD | NEW | 
|---|
| (Empty) |  | 
|  | 1 # Copyright 2016 Google Inc. | 
|  | 2 # | 
|  | 3 # Use of this source code is governed by a BSD-style license that can be | 
|  | 4 # found in the LICENSE file. | 
|  | 5 | 
|  | 6 from _hardware import HardwareException, Expectation | 
|  | 7 from _hardware_android import HardwareAndroid | 
|  | 8 | 
|  | 9 CPU_CLOCK_RATE = 1836000 | 
|  | 10 GPU_EMC_PROFILE = '0c: core 921 MHz emc 1600 MHz a A d D *' | 
|  | 11 GPU_EMC_PROFILE_ID = '0c' | 
|  | 12 | 
|  | 13 class HardwarePixelC(HardwareAndroid): | 
|  | 14   def __init__(self, adb): | 
|  | 15     HardwareAndroid.__init__(self, adb) | 
|  | 16 | 
|  | 17   def __enter__(self): | 
|  | 18     self._lock_clocks() | 
|  | 19     return HardwareAndroid.__enter__(self) | 
|  | 20 | 
|  | 21   def __exit__(self, exception_type, exception_value, exception_traceback): | 
|  | 22     HardwareAndroid.__exit__(self, exception_type, | 
|  | 23                              exception_value, exception_traceback) | 
|  | 24     self._unlock_clocks() | 
|  | 25 | 
|  | 26   def _lock_clocks(self): | 
|  | 27     if not self._is_root: | 
|  | 28       return | 
|  | 29 | 
|  | 30     # lock cpu clocks. | 
|  | 31     self._adb.shell('''\ | 
|  | 32       for N in $(seq 0 3); do | 
|  | 33         echo userspace > /sys/devices/system/cpu/cpu$N/cpufreq/scaling_governor | 
|  | 34         echo %i > /sys/devices/system/cpu/cpu$N/cpufreq/scaling_setspeed | 
|  | 35       done''' % CPU_CLOCK_RATE) | 
|  | 36 | 
|  | 37     # lock gpu/emc clocks. | 
|  | 38     self._adb.shell('''\ | 
|  | 39       chown root:root /sys/devices/57000000.gpu/pstate | 
|  | 40       echo %s > /sys/devices/57000000.gpu/pstate''' % GPU_EMC_PROFILE_ID) | 
|  | 41 | 
|  | 42   def _unlock_clocks(self): | 
|  | 43     if not self._is_root: | 
|  | 44       return | 
|  | 45 | 
|  | 46     # unlock gpu/emc clocks. | 
|  | 47     self._adb.shell('''\ | 
|  | 48       echo auto > /sys/devices/57000000.gpu/pstate | 
|  | 49       chown system:system /sys/devices/57000000.gpu/pstate''') | 
|  | 50 | 
|  | 51     # unlock cpu clocks. | 
|  | 52     self._adb.shell('''\ | 
|  | 53       for N in $(seq 0 3); do | 
|  | 54         echo 0 > /sys/devices/system/cpu/cpu$N/cpufreq/scaling_setspeed | 
|  | 55         echo interactive > /sys/devices/system/cpu/cpu$N/cpufreq/scaling_governo
    r | 
|  | 56       done''') | 
|  | 57 | 
|  | 58   def sanity_check(self): | 
|  | 59     HardwareAndroid.sanity_check(self) | 
|  | 60 | 
|  | 61     if not self._is_root: | 
|  | 62       return | 
|  | 63 | 
|  | 64     # only issue one shell command in an attempt to minimize interference. | 
|  | 65     result = self._adb.check_lines('''\ | 
|  | 66       cat /sys/class/power_supply/bq27742-0/capacity \ | 
|  | 67           /sys/class/thermal/thermal_zone7/temp \ | 
|  | 68           /sys/class/thermal/thermal_zone0/temp \ | 
|  | 69           /sys/class/thermal/thermal_zone1/temp \ | 
|  | 70           /sys/class/thermal/thermal_zone7/cdev1/cur_state \ | 
|  | 71           /sys/class/thermal/thermal_zone7/cdev0/cur_state | 
|  | 72       for N in $(seq 0 3); do | 
|  | 73         cat /sys/devices/system/cpu/cpu$N/cpufreq/scaling_cur_freq | 
|  | 74       done | 
|  | 75       cat /sys/devices/57000000.gpu/pstate | grep \*$''') | 
|  | 76 | 
|  | 77     expectations = \ | 
|  | 78       [Expectation(int, min_value=30, name='battery', sleeptime=30*60), | 
|  | 79        Expectation(int, max_value=40000, name='skin temperature'), | 
|  | 80        Expectation(int, max_value=86000, name='cpu temperature'), | 
|  | 81        Expectation(int, max_value=87000, name='gpu temperature'), | 
|  | 82        Expectation(int, exact_value=0, name='cpu throttle'), | 
|  | 83        Expectation(int, exact_value=0, name='gpu throttle')] + \ | 
|  | 84       [Expectation(int, exact_value=CPU_CLOCK_RATE, | 
|  | 85                    name='cpu_%i clock rate' % i, sleeptime=30) | 
|  | 86        for i in range(4)] + \ | 
|  | 87       [Expectation(str, exact_value=GPU_EMC_PROFILE, name='gpu/emc profile')] | 
|  | 88 | 
|  | 89     Expectation.check_all(expectations, result) | 
|  | 90 | 
|  | 91   def sleep(self, sleeptime): | 
|  | 92     self._unlock_clocks() | 
|  | 93     HardwareAndroid.sleep(self, sleeptime) | 
|  | 94     self._lock_clocks() | 
| OLD | NEW | 
|---|