• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
6from _hardware import HardwareException, Expectation
7from _hardware_android import HardwareAndroid
8
9CPU_CLOCK_RATE = 1836000
10GPU_EMC_PROFILE = '0c: core 921 MHz emc 1600 MHz a A d D *'
11GPU_EMC_PROFILE_ID = '0c'
12
13class HardwarePixelC(HardwareAndroid):
14  def __init__(self, adb):
15    HardwareAndroid.__init__(self, adb)
16
17  def __enter__(self):
18    HardwareAndroid.__enter__(self)
19    if not self._adb.is_root():
20      return self
21
22    self._adb.shell('\n'.join([
23      # turn on and lock the first 3 cores.
24      '''
25      for N in 0 1 2; do
26        echo 1 > /sys/devices/system/cpu/cpu$N/online
27        echo userspace > /sys/devices/system/cpu/cpu$N/cpufreq/scaling_governor
28        echo %i > /sys/devices/system/cpu/cpu$N/cpufreq/scaling_max_freq
29        echo %i > /sys/devices/system/cpu/cpu$N/cpufreq/scaling_min_freq
30        echo %i > /sys/devices/system/cpu/cpu$N/cpufreq/scaling_setspeed
31      done''' % tuple(CPU_CLOCK_RATE for _ in range(3)),
32
33      # turn off the fourth core.
34      '''
35      echo 0 > /sys/devices/system/cpu/cpu3/online''',
36
37      # lock gpu/emc clocks.
38      '''
39      chown root:root /sys/devices/57000000.gpu/pstate
40      echo %s > /sys/devices/57000000.gpu/pstate''' % GPU_EMC_PROFILE_ID]))
41
42    return self
43
44  def filter_line(self, line):
45    JUNK = ['NvRmPrivGetChipPlatform: Could not read platform information',
46            'Expected on kernels without fuse support, using silicon']
47    return False if line in JUNK else HardwareAndroid.filter_line(self, line)
48
49  def sanity_check(self):
50    HardwareAndroid.sanity_check(self)
51
52    if not self._adb.is_root():
53      return
54
55    # only issue one shell command in an attempt to minimize interference.
56    result = self._adb.check('''\
57      cat /sys/class/power_supply/bq27742-0/capacity \
58          /sys/devices/system/cpu/online \
59          /sys/class/thermal/thermal_zone7/temp \
60          /sys/class/thermal/thermal_zone0/temp \
61          /sys/class/thermal/thermal_zone1/temp \
62          /sys/class/thermal/thermal_zone7/cdev1/cur_state \
63          /sys/class/thermal/thermal_zone7/cdev0/cur_state
64      for N in 0 1 2; do
65        cat /sys/devices/system/cpu/cpu$N/cpufreq/scaling_cur_freq
66      done
67      cat /sys/devices/57000000.gpu/pstate | grep \*$''')
68
69    expectations = \
70      [Expectation(int, min_value=30, name='battery', sleeptime=30*60),
71       Expectation(str, exact_value='0-2', name='online cpus'),
72       Expectation(int, max_value=40000, name='skin temperature'),
73       Expectation(int, max_value=86000, name='cpu temperature'),
74       Expectation(int, max_value=87000, name='gpu temperature'),
75       Expectation(int, exact_value=0, name='cpu throttle'),
76       Expectation(int, exact_value=0, name='gpu throttle')] + \
77      [Expectation(int, exact_value=CPU_CLOCK_RATE,
78                   name='cpu_%i clock rate' % i, sleeptime=30)
79       for i in (0, 1, 2)] + \
80      [Expectation(str, exact_value=GPU_EMC_PROFILE, name='gpu/emc profile')]
81
82    Expectation.check_all(expectations, result.splitlines())
83