1#
2# Copyright (C) 2017 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
18import logging
19from vts.runners.host import asserts
20from vts.testcases.kernel.api.proc import KernelProcFileTestBase
21
22from vts.utils.python.file import target_file_utils
23
24
25class ProcUidCpuPowerTimeInStateTest(KernelProcFileTestBase.KernelProcFileTestBase):
26    '''/proc/uid_cpupower/time_in_state
27    '''
28
29    def parse_contents(self, contents):
30        size = struct.calcsize('I')
31        return [struct.unpack_from('I', contents, i)[0] for i in range(0, len(contents), size)]
32
33    def result_correct(self, result):
34        if not result:
35            return False
36
37        if (len(result) - 1) % (result[0] + 1) != 0:
38            return False
39
40        return True
41
42    def get_path(self):
43        return "/proc/uid_cpupower/time_in_state"
44
45    def file_optional(self, shell=None, dut=None):
46        # This file is optional until implemented in Android common kernel
47        return True
48
49class ProcUidCpuPowerConcurrentActiveTimeTest(KernelProcFileTestBase.KernelProcFileTestBase):
50    '''/proc/uid_cpupower/concurrent_active_time
51    '''
52
53    def parse_contents(self, contents):
54        size = struct.calcsize('I')
55        return [struct.unpack_from('I', contents, i)[0] for i in range(0, len(contents), size)]
56
57    def result_correct(self, result):
58        if not result:
59            return False
60
61        if (len(result) - 1) % (result[0] + 1) != 0:
62            return False
63
64        return True
65
66    def get_path(self):
67        return "/proc/uid_cpupower/concurrent_active_time"
68
69    def file_optional(self, shell=None, dut=None):
70        # This file is optional until implemented in Android common kernel
71        return True
72
73class ProcUidCpuPowerConcurrentPolicyTimeTest(KernelProcFileTestBase.KernelProcFileTestBase):
74    '''/proc/uid_cpupower/concurrent_policy_time
75    '''
76
77    def parse_contents(self, contents):
78        size = struct.calcsize('I')
79        return [struct.unpack_from('I', contents, i)[0] for i in range(0, len(contents), size)]
80
81    def result_correct(self, result):
82        if not result:
83            return False
84
85        policy_cnt = result[0]
86        result_len = len(result)
87
88        if policy_cnt + 1 > result_len:
89            return False
90
91        line_len = sum(result[1:policy_cnt+1]) + 1
92
93        if (result_len - policy_cnt - 1) % line_len != 0:
94            return False
95
96        return True
97
98    def get_path(self):
99        return "/proc/uid_cpupower/concurrent_policy_time"
100
101    def file_optional(self, shell=None, dut=None):
102        # This file is optional until implemented in Android common kernel
103        return True
104