• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 ProcVmallocInfoTest(KernelProcFileTestBase.KernelProcFileTestBase):
22    '''/proc/vmallocinfo provides info on vmalloc'd ranges.'''
23
24    start = 'lines'
25
26    def t_CALLER(self, t):
27        '[^ ^\t^\n^-^=^+^/]+\+0x[a-f0-9]+/0x[a-f0-9]+'
28        t.value = t.value.split('+')
29        return t
30
31    t_PAGES = literal_token('pages')
32    t_IOREMAP = literal_token('ioremap')
33    t_MODULE = literal_token('\[[^\n^\0]*\]')
34    t_VMALLOC = literal_token('vmalloc')
35    t_VMAP = literal_token('vmap')
36    t_USER = literal_token('user')
37    t_VPAGES = literal_token('vpages')
38    t_VM_AREA = literal_token('vm_area')
39    t_UNPURGED = literal_token('unpurged')
40    t_VM_MAP_RAM = literal_token('vm_map_ram')
41
42    t_ignore = ' '
43
44    def t_PHYS(self, t):
45        r'phys=(0x)?[a-f0-9]+'
46        t.value = [t.value[:4], int(t.value[5:], 16)]
47        return t
48
49    def t_NODES(self, t):
50        r'N[0-9]+=[1-9][0-9]*'
51        t.value = t.value.split('=', 1)
52        return t
53
54    p_lines = repeat_rule('line')
55    p_nodes = repeat_rule('node')
56
57    def p_line(self, p):
58        'line : addr_range NUMBER caller module pages phys ioremap vmalloc vmap user vpages vm_vm_area nodes NEWLINE'
59        p[0] = p[1:]
60
61    def p_addr_range(self, p):
62        'addr_range : HEX_LITERAL DASH HEX_LITERAL'
63        p[0] = [p[1], p[3]]
64
65    def p_module(self, p):
66        '''module : MODULE
67                  | empty'''
68        p[0] = p[1]
69
70    def p_pages(self, p):
71        '''pages : PAGES EQUALS NUMBER
72                 | empty'''
73        p[0] = [] if len(p) == 2 else [p[1], p[3]]
74
75    def p_phys(self, p):
76        '''phys : PHYS
77                | empty'''
78        p[0] = p[1]
79
80    def p_ioremap(self, p):
81        '''ioremap : IOREMAP
82                   | empty'''
83        p[0] = p[1]
84
85    def p_vmalloc(self, p):
86        '''vmalloc : VMALLOC
87                   | empty'''
88        p[0] = p[1]
89
90    def p_vmap(self, p):
91        '''vmap : VMAP
92                | empty'''
93        p[0] = p[1]
94
95    def p_user(self, p):
96        '''user : USER
97                | empty'''
98        p[0] = p[1]
99
100    def p_vpages(self, p):
101        '''vpages : VPAGES
102                  | empty'''
103        p[0] = p[1]
104
105    def p_vm_vm_area(self, p):
106        '''vm_vm_area : UNPURGED VM_AREA
107                      | VM_MAP_RAM
108                      | empty'''
109        if len(p) == 2:
110            p[0] = []
111        else:
112            p[0] = p[1:]
113
114    def p_node(self, p):
115        '''node : NODES
116                | empty'''
117        p[0] = [1]
118
119    def p_caller(self, p):
120        '''caller : CALLER
121                  | HEX_LITERAL
122                  | empty'''
123        p[0] = p[1]
124
125    def get_path(self):
126        return "/proc/vmallocinfo"
127