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
17from vts.testcases.kernel.api.proc import KernelProcFileTestBase
18from vts.testcases.kernel.api.proc.KernelProcFileTestBase import repeat_rule, literal_token
19
20
21class ProcStatTest(KernelProcFileTestBase.KernelProcFileTestBase):
22    '''/proc/stat provides kernel and system statistics.'''
23
24    start = 'stat'
25
26    t_CPU = literal_token(r'cpu[0-9]*')
27    t_INTR = literal_token(r'intr')
28    t_CTXT = literal_token(r'ctxt')
29    t_BTIME = literal_token(r'btime')
30    t_PROCESSES = literal_token(r'processes')
31    t_PROCS_RUNNING = literal_token(r'procs_running')
32    t_PROCS_BLOCKED = literal_token(r'procs_blocked')
33    t_SOFTIRQ = literal_token(r'softirq')
34
35    p_cpus = repeat_rule('cpu')
36    p_numbers = repeat_rule('NUMBER')
37
38    t_ignore = ' '
39
40    def p_stat(self, p):
41        'stat : cpus intr ctxt btime processes procs_running procs_blocked softirq'
42        p[0] = p[1:]
43
44    def p_cpu(self, p):
45        'cpu : CPU NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NEWLINE'
46        p[0] = p[1:]
47
48    def p_intr(self, p):
49        'intr : INTR NUMBERs NEWLINE'
50        p[0] = p[1:]
51
52    def p_ctxt(self, p):
53        'ctxt : CTXT NUMBER NEWLINE'
54        p[0] = p[1:]
55
56    def p_btime(self, p):
57        'btime : BTIME NUMBER NEWLINE'
58        p[0] = p[1:]
59
60    def p_processes(self, p):
61        'processes : PROCESSES NUMBER NEWLINE'
62        p[0] = p[1:]
63
64    def p_procs_running(self, p):
65        'procs_running : PROCS_RUNNING NUMBER NEWLINE'
66        p[0] = p[1:]
67
68    def p_procs_blocked(self, p):
69        'procs_blocked : PROCS_BLOCKED NUMBER NEWLINE'
70        p[0] = p[1:]
71
72    def p_softirq(self, p):
73        'softirq : SOFTIRQ NUMBERs NEWLINE'
74        p[0] = p[1:]
75
76    def get_path(self):
77        return "/proc/stat"
78