1#
2# Copyright (C) 2019 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
17from vts.testcases.kernel.api.proc import KernelProcFileTestBase
18from vts.testcases.kernel.api.proc.KernelProcFileTestBase import repeat_rule, literal_token
19
20
21class ProcUidConcurrentActiveTimeTest(KernelProcFileTestBase.KernelProcFileTestBase):
22    '''/proc/uid_concurrent_active_time provides the time each UID's processes spend
23    executing concurrently with processes on other CPUs.
24
25    This is an Android specific file.
26    '''
27
28    start = 'uid_active_time_table'
29
30    t_CPU = literal_token(r'cpus')
31
32    p_uid_active_times = repeat_rule('uid_active_time')
33    p_numbers = repeat_rule('NUMBER')
34
35    t_ignore = ' '
36
37    def p_uid_active_time_table(self, p):
38        'uid_active_time_table : cpus uid_active_times'
39        p[0] = p[1:]
40
41    def p_cpus(self, p):
42        'cpus : CPU COLON NUMBER NEWLINE'
43        p[0] = p[3]
44
45    def p_uid_active_time(self, p):
46        'uid_active_time : NUMBER COLON NUMBERs NEWLINE'
47        p[0] = [p[1], p[3]]
48
49    def get_path(self):
50        return "/proc/uid_concurrent_active_time"
51
52    def file_optional(self, shell=None, dut=None):
53        return True
54
55    def result_correct(self, result):
56        cpus, times = result
57        no_repeated_uids = len(set(x[0] for x in times)) == len(times)
58        row_lengths_match = all(len(time[1]) == int(cpus) for time in times)
59        return no_repeated_uids and row_lengths_match
60
61class ProcUidConcurrentPolicyTimeTest(KernelProcFileTestBase.KernelProcFileTestBase):
62    '''/proc/uid_concurrent_policy_time provides the time each UID's processes spend
63    executing concurrently with processes on the same cluster.
64
65    This is an Android specific file.
66    '''
67
68    start = 'uid_policy_time_table'
69
70    t_POLICY = literal_token(r'policy')
71
72    p_policy_infos = repeat_rule('policy_info')
73    p_uid_policy_times = repeat_rule('uid_policy_time')
74    p_numbers = repeat_rule('NUMBER')
75
76    t_ignore = ' '
77
78    def p_uid_policy_time_table(self, p):
79        'uid_policy_time_table : header_row uid_policy_times'
80        p[0] = p[1:]
81
82    def p_header_row(self, p):
83        'header_row : policy_infos NEWLINE'
84        p[0] = sum(int(x) for x in p[1])
85
86    def p_policy_info(self, p):
87        'policy_info : POLICY NUMBER COLON NUMBER'
88        p[0] = p[4]
89
90    def p_uid_policy_time(self, p):
91        'uid_policy_time : NUMBER COLON NUMBERs NEWLINE'
92        p[0] = [p[1], p[3]]
93
94    def get_path(self):
95        return "/proc/uid_concurrent_policy_time"
96
97    def file_optional(self, shell=None, dut=None):
98        return True
99
100    def result_correct(self, result):
101        cpus, times = result
102        no_repeated_uids = len(set(x[0] for x in times)) == len(times)
103        row_lengths_match = all(len(time[1]) == int(cpus) for time in times)
104        return no_repeated_uids and row_lengths_match
105