lin
2025-08-20 171e08343a9b6df6c31197f5b4800e8004800f5b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#
# Copyright (C) 2017 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
 
from vts.testcases.kernel.api.proc import KernelProcFileTestBase
from vts.testcases.kernel.api.proc.KernelProcFileTestBase import repeat_rule, literal_token
 
 
class ProcVmallocInfoTest(KernelProcFileTestBase.KernelProcFileTestBase):
    '''/proc/vmallocinfo provides info on vmalloc'd ranges.'''
 
    start = 'lines'
 
    def t_CALLER(self, t):
        '[^ ^\t^\n^-^=^+^/]+\+0x[a-f0-9]+/0x[a-f0-9]+'
        t.value = t.value.split('+')
        return t
 
    t_PAGES = literal_token('pages')
    t_IOREMAP = literal_token('ioremap')
    t_MODULE = literal_token('\[[^\n^\0]*\]')
    t_VMALLOC = literal_token('vmalloc')
    t_VMAP = literal_token('vmap')
    t_USER = literal_token('user')
    t_VPAGES = literal_token('vpages')
    t_VM_AREA = literal_token('vm_area')
    t_UNPURGED = literal_token('unpurged')
    t_VM_MAP_RAM = literal_token('vm_map_ram')
 
    t_ignore = ' '
 
    def t_PHYS(self, t):
        r'phys=(0x)?[a-f0-9]+'
        t.value = [t.value[:4], int(t.value[5:], 16)]
        return t
 
    def t_NODES(self, t):
        r'N[0-9]+=[1-9][0-9]*'
        t.value = t.value.split('=', 1)
        return t
 
    p_lines = repeat_rule('line')
    p_nodes = repeat_rule('node')
 
    def p_line(self, p):
        'line : addr_range NUMBER caller module pages phys ioremap vmalloc vmap user vpages vm_vm_area nodes NEWLINE'
        p[0] = p[1:]
 
    def p_addr_range(self, p):
        'addr_range : HEX_LITERAL DASH HEX_LITERAL'
        p[0] = [p[1], p[3]]
 
    def p_module(self, p):
        '''module : MODULE
                  | empty'''
        p[0] = p[1]
 
    def p_pages(self, p):
        '''pages : PAGES EQUALS NUMBER
                 | empty'''
        p[0] = [] if len(p) == 2 else [p[1], p[3]]
 
    def p_phys(self, p):
        '''phys : PHYS
                | empty'''
        p[0] = p[1]
 
    def p_ioremap(self, p):
        '''ioremap : IOREMAP
                   | empty'''
        p[0] = p[1]
 
    def p_vmalloc(self, p):
        '''vmalloc : VMALLOC
                   | empty'''
        p[0] = p[1]
 
    def p_vmap(self, p):
        '''vmap : VMAP
                | empty'''
        p[0] = p[1]
 
    def p_user(self, p):
        '''user : USER
                | empty'''
        p[0] = p[1]
 
    def p_vpages(self, p):
        '''vpages : VPAGES
                  | empty'''
        p[0] = p[1]
 
    def p_vm_vm_area(self, p):
        '''vm_vm_area : UNPURGED VM_AREA
                      | VM_MAP_RAM
                      | empty'''
        if len(p) == 2:
            p[0] = []
        else:
            p[0] = p[1:]
 
    def p_node(self, p):
        '''node : NODES
                | empty'''
        p[0] = [1]
 
    def p_caller(self, p):
        '''caller : CALLER
                  | HEX_LITERAL
                  | empty'''
        p[0] = p[1]
 
    def get_path(self):
        return "/proc/vmallocinfo"