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 ProcZoneInfoTest(KernelProcFileTestBase.KernelProcFileTestBase):
22    '''/proc/zoneinfo displays information about memory zones.'''
23
24    t_APAGES = literal_token(r'pages')
25    t_PAGESETS = literal_token(r'pagesets')
26    t_CPU = literal_token(r'cpu')
27    t_VM = literal_token(r'vm')
28    t_STATS = literal_token(r'stats')
29    t_THRESHOLD = literal_token(r'threshold')
30    t_NODE = literal_token(r'Node')
31    t_ZONE = literal_token(r'zone')
32    t_PROTECTION = literal_token(r'protection')
33    t_PERNODE = literal_token(r'per-node')
34    t_LPAREN = literal_token(r'\(')
35    t_RPAREN = literal_token(r'\)')
36
37    t_ignore = ' '
38
39    start = 'nodes'
40
41    p_nodes = repeat_rule('node')
42    p_lines = repeat_rule('line')
43    p_cpus = repeat_rule('cpu')
44    p_colonlines = repeat_rule('colonline')
45    p_numcommas = repeat_rule('numcomma')
46
47    def p_node(self, p):
48        '''node : heading pernode APAGES lines protection populated'''
49        p[0] = [p[1], p[2], p[4], p[5], p[6]]
50
51    def p_populated(self, p):
52        '''populated : PAGESETS NEWLINE cpus colonlines
53                | lines PAGESETS NEWLINE cpus colonlines
54                | empty'''
55        if len(p) == 2:
56            p[0] = []
57        elif len(p) == 6:
58            p[0] = [p[1], p[4], p[5]]
59        else:
60            p[0] = [p[3], p[4]]
61
62    def p_pernode(self, p):
63        '''pernode : PERNODE STATS NEWLINE lines
64                   | empty'''
65        p[0] = [] if len(p) == 2 else [p[1], p[4]]
66
67    def p_protection(self, p):
68        'protection : PROTECTION COLON LPAREN numcommas NUMBER RPAREN NEWLINE'
69        p[0] = p[4] + [p[5]]
70
71    def p_numcomma(self, p):
72        'numcomma : NUMBER COMMA'
73        p[0] = p[1]
74
75    def p_line(self, p):
76        '''line : STRING NUMBER NEWLINE
77                | NUMBER NEWLINE'''
78        if len(p) == 4:
79            p[0] = p[1:3]
80        else:
81            p[0] = p[1]
82
83    def p_cpu(self, p):
84        'cpu : CPU COLON NUMBER NEWLINE colonline colonline colonline \
85                VM STATS THRESHOLD COLON NUMBER NEWLINE'
86
87        p[0] = [p[3], p[5], p[6], p[7], [p[10], p[12]]]
88
89    def p_colonline(self, p):
90        'colonline : STRING COLON NUMBER NEWLINE'
91        p[0] = [p[1], p[3]]
92
93    def p_heading(self, p):
94        'heading : NODE NUMBER COMMA ZONE STRING NEWLINE'
95        p[0] = [p[2], p[5]]
96
97    def get_path(self):
98        return "/proc/zoneinfo"
99