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 t_DMA_COHERENT = literal_token('dma-coherent') 42 43 t_ignore = ' ' 44 45 def t_PHYS(self, t): 46 r'phys=(0x)?[a-f0-9]+' 47 t.value = [t.value[:4], int(t.value[5:], 16)] 48 return t 49 50 def t_NODES(self, t): 51 r'N[0-9]+=[1-9][0-9]*' 52 t.value = t.value.split('=', 1) 53 return t 54 55 p_lines = repeat_rule('line') 56 p_nodes = repeat_rule('node') 57 58 def p_line(self, p): 59 'line : addr_range NUMBER caller module pages phys ioremap vmalloc vmap user dma_coherent vpages vm_vm_area nodes NEWLINE' 60 p[0] = p[1:] 61 62 def p_addr_range(self, p): 63 'addr_range : HEX_LITERAL DASH HEX_LITERAL' 64 p[0] = [p[1], p[3]] 65 66 def p_module(self, p): 67 '''module : MODULE 68 | empty''' 69 p[0] = p[1] 70 71 def p_pages(self, p): 72 '''pages : PAGES EQUALS NUMBER 73 | empty''' 74 p[0] = [] if len(p) == 2 else [p[1], p[3]] 75 76 def p_phys(self, p): 77 '''phys : PHYS 78 | empty''' 79 p[0] = p[1] 80 81 def p_ioremap(self, p): 82 '''ioremap : IOREMAP 83 | empty''' 84 p[0] = p[1] 85 86 def p_vmalloc(self, p): 87 '''vmalloc : VMALLOC 88 | empty''' 89 p[0] = p[1] 90 91 def p_dma_coherent(self, p): 92 '''dma_coherent : DMA_COHERENT 93 | empty''' 94 p[0] = p[1] 95 96 def p_vmap(self, p): 97 '''vmap : VMAP 98 | empty''' 99 p[0] = p[1] 100 101 def p_user(self, p): 102 '''user : USER 103 | empty''' 104 p[0] = p[1] 105 106 def p_vpages(self, p): 107 '''vpages : VPAGES 108 | empty''' 109 p[0] = p[1] 110 111 def p_vm_vm_area(self, p): 112 '''vm_vm_area : UNPURGED VM_AREA 113 | VM_MAP_RAM 114 | empty''' 115 if len(p) == 2: 116 p[0] = [] 117 else: 118 p[0] = p[1:] 119 120 def p_node(self, p): 121 '''node : NODES 122 | empty''' 123 p[0] = [1] 124 125 def p_caller(self, p): 126 '''caller : CALLER 127 | HEX_LITERAL 128 | empty''' 129 p[0] = p[1] 130 131 def get_path(self): 132 return "/proc/vmallocinfo" 133