1# 2# Copyright (C) 2020 The Android Open Source Project 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# 16 17import struct 18from proc_tests import KernelProcFileTestBase 19 20 21class ProcUidCpuPowerTimeInStateTest( 22 KernelProcFileTestBase.KernelProcFileTestBase): 23 '''/proc/uid_cpupower/time_in_state 24 ''' 25 26 def parse_contents(self, contents): 27 size = struct.calcsize('I') 28 return [struct.unpack_from('I', contents.encode(), i)[0] for i in range(0, len(contents), size)] 29 30 def result_correct(self, result): 31 if not result: 32 return False 33 34 if (len(result) - 1) % (result[0] + 1) != 0: 35 return False 36 37 return True 38 39 def get_path(self): 40 return "/proc/uid_cpupower/time_in_state" 41 42 def file_optional(self, shell=None, dut=None): 43 # This file is optional until implemented in Android common kernel 44 return True 45 46class ProcUidCpuPowerConcurrentActiveTimeTest( 47 KernelProcFileTestBase.KernelProcFileTestBase): 48 '''/proc/uid_cpupower/concurrent_active_time 49 ''' 50 51 def parse_contents(self, contents): 52 size = struct.calcsize('I') 53 return [struct.unpack_from('I', contents.encode(), i)[0] for i in range(0, len(contents), size)] 54 55 def result_correct(self, result): 56 if not result: 57 return False 58 59 if (len(result) - 1) % (result[0] + 1) != 0: 60 return False 61 62 return True 63 64 def get_path(self): 65 return "/proc/uid_cpupower/concurrent_active_time" 66 67 def file_optional(self, shell=None, dut=None): 68 # This file is optional until implemented in Android common kernel 69 return True 70 71class ProcUidCpuPowerConcurrentPolicyTimeTest( 72 KernelProcFileTestBase.KernelProcFileTestBase): 73 '''/proc/uid_cpupower/concurrent_policy_time 74 ''' 75 76 def parse_contents(self, contents): 77 size = struct.calcsize('I') 78 return [struct.unpack_from('I', contents.encode(), i)[0] for i in range(0, len(contents), size)] 79 80 def result_correct(self, result): 81 if not result: 82 return False 83 84 policy_cnt = result[0] 85 result_len = len(result) 86 87 if policy_cnt + 1 > result_len: 88 return False 89 90 line_len = sum(result[1:policy_cnt+1]) + 1 91 92 if (result_len - policy_cnt - 1) % line_len != 0: 93 return False 94 95 return True 96 97 def get_path(self): 98 return "/proc/uid_cpupower/concurrent_policy_time" 99 100 def file_optional(self, shell=None, dut=None): 101 # This file is optional until implemented in Android common kernel 102 return True 103